Upgrade OkHttp to 4.12.

Addresses #13491
This commit is contained in:
Nicholas Tinsley
2024-06-17 17:51:19 -04:00
committed by Greyson Parrelli
parent 9824cc2cbe
commit 8ba57a2733
11 changed files with 68 additions and 62 deletions

View File

@@ -58,18 +58,21 @@ class InstrumentationApplicationDependencyProvider(val application: Application,
Get("/v1/websocket/?login=") {
MockResponse().success().withWebSocketUpgrade(mockIdentifiedWebSocket)
},
Get("/v1/websocket", { !it.path.contains("login") }) {
Get("/v1/websocket", {
val path = it.path
return@Get path == null || !path.contains("login")
}) {
MockResponse().success().withWebSocketUpgrade(object : WebSocketListener() {})
}
)
}
webServer.setDispatcher(object : Dispatcher() {
webServer.dispatcher = object : Dispatcher() {
override fun dispatch(request: RecordedRequest): MockResponse {
val handler = handlers.firstOrNull { it.requestPredicate(request) }
return handler?.responseFactory?.invoke(request) ?: MockResponse().setResponseCode(500)
}
})
}
serviceTrustStore = SignalServiceTrustStore(application)
uncensoredConfiguration = SignalServiceConfiguration(

View File

@@ -55,5 +55,5 @@ inline fun <reified T> RecordedRequest.parsedRequestBody(): T {
}
private fun defaultRequestPredicate(verb: String, path: String, predicate: RequestPredicate = { true }): RequestPredicate = { request ->
request.method == verb && request.path.startsWith("/$path") && predicate(request)
request.method == verb && request.path?.startsWith("/$path") == true && predicate(request)
}

View File

@@ -67,10 +67,10 @@ class ApkUpdateJob private constructor(parameters: Parameters) : BaseJob(paramet
val request = Request.Builder().url(BuildConfig.APK_UPDATE_MANIFEST_URL).build()
val rawUpdateDescriptor: String = client.newCall(request).execute().use { response ->
if (!response.isSuccessful || response.body() == null) {
if (!response.isSuccessful || response.body == null) {
throw IOException("Failed to read update descriptor")
}
response.body()!!.string()
response.body!!.string()
}
val updateDescriptor: UpdateDescriptor = JsonUtils.fromJson(rawUpdateDescriptor, UpdateDescriptor::class.java)

View File

@@ -400,7 +400,7 @@ class AttachmentDownloadJob private constructor(
) {
try {
S3.getObject(attachment.fileName!!).use { response ->
val body = response.body()
val body = response.body
if (body != null) {
if (body.contentLength() > RemoteConfig.maxAttachmentReceiveSizeBytes) {
throw MmsException("Attachment too large, failing download")

View File

@@ -42,7 +42,7 @@ class FetchRemoteMegaphoneImageJob(parameters: Parameters, private val uuid: Str
override fun onRun() {
try {
S3.getObject(imageUrl).use { response ->
val body: ResponseBody? = response.body()
val body: ResponseBody? = response.body
if (body != null) {
val uri = BlobProvider.getInstance()
.forData(body.byteStream(), body.contentLength())

View File

@@ -53,10 +53,10 @@ object S3 {
fun getString(endpoint: String): String {
getObject(endpoint).use { response ->
if (!response.isSuccessful) {
throw NonSuccessfulResponseCodeException(response.code())
throw NonSuccessfulResponseCodeException(response.code)
}
return response.body()?.string()?.trim() ?: throw IOException()
return response.body?.string()?.trim() ?: throw IOException()
}
}
@@ -110,13 +110,13 @@ object S3 {
getObject(endpoint).use { response ->
if (!response.isSuccessful) {
return ServiceResponse.forApplicationError(
DefaultErrorMapper.getDefault().parseError(response.code()),
response.code(),
DefaultErrorMapper.getDefault().parseError(response.code),
response.code,
""
)
}
val source = response.body()?.source()
val source = response.body?.source()
val outputStream = ByteArrayOutputStream()
@@ -166,7 +166,7 @@ object S3 {
}
getObject(objectPathOnNetwork).use { response ->
val source = response.body()?.source()
val source = response.body?.source()
val outputStream: OutputStream = if (doNotEncrypt) {
FileOutputStream(objectFileOnDisk)

View File

@@ -1,6 +1,6 @@
package org.thoughtcrime.securesms.util
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import org.thoughtcrime.securesms.stickers.StickerUrl
import java.net.URI
import java.net.URISyntaxException
@@ -43,7 +43,7 @@ object LinkUtil {
return false
}
return HttpUrl.parse(linkUrl)?.scheme() == "https"
return linkUrl.toHttpUrlOrNull()?.scheme == "https"
}
/**