mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-27 02:07:42 +00:00
Merge pull request #1568 from bemusementpark/fix-body
Fix leak in Response#body
This commit is contained in:
commit
64c72248e8
@ -115,18 +115,26 @@ object HTTP {
|
|||||||
}
|
}
|
||||||
Verb.DELETE -> request.delete()
|
Verb.DELETE -> request.delete()
|
||||||
}
|
}
|
||||||
lateinit var response: Response
|
return try {
|
||||||
try {
|
when {
|
||||||
val connection: OkHttpClient = if (timeout != HTTP.timeout) { // Custom timeout
|
// Custom timeout
|
||||||
if (useSeedNodeConnection) {
|
timeout != HTTP.timeout -> {
|
||||||
throw IllegalStateException("Setting a custom timeout is only allowed for requests to snodes.")
|
if (useSeedNodeConnection) {
|
||||||
|
throw IllegalStateException("Setting a custom timeout is only allowed for requests to snodes.")
|
||||||
|
}
|
||||||
|
getDefaultConnection(timeout)
|
||||||
|
}
|
||||||
|
useSeedNodeConnection -> seedNodeConnection
|
||||||
|
else -> defaultConnection
|
||||||
|
}.newCall(request.build()).execute().use { response ->
|
||||||
|
when (val statusCode = response.code) {
|
||||||
|
200 -> response.body!!.bytes()
|
||||||
|
else -> {
|
||||||
|
Log.d("Loki", "${verb.rawValue} request to $url failed with status code: $statusCode.")
|
||||||
|
throw HTTPRequestFailedException(statusCode, null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
getDefaultConnection(timeout)
|
|
||||||
} else {
|
|
||||||
if (useSeedNodeConnection) seedNodeConnection else defaultConnection
|
|
||||||
}
|
}
|
||||||
|
|
||||||
response = connection.newCall(request.build()).execute()
|
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
Log.d("Loki", "${verb.rawValue} request to $url failed due to error: ${exception.localizedMessage}.")
|
Log.d("Loki", "${verb.rawValue} request to $url failed due to error: ${exception.localizedMessage}.")
|
||||||
|
|
||||||
@ -135,14 +143,5 @@ object HTTP {
|
|||||||
// Override the actual error so that we can correctly catch failed requests in OnionRequestAPI
|
// Override the actual error so that we can correctly catch failed requests in OnionRequestAPI
|
||||||
throw HTTPRequestFailedException(0, null, "HTTP request failed due to: ${exception.message}")
|
throw HTTPRequestFailedException(0, null, "HTTP request failed due to: ${exception.message}")
|
||||||
}
|
}
|
||||||
return when (val statusCode = response.code) {
|
|
||||||
200 -> {
|
|
||||||
response.body!!.bytes()
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
Log.d("Loki", "${verb.rawValue} request to $url failed with status code: $statusCode.")
|
|
||||||
throw HTTPRequestFailedException(statusCode, null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user