Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly handle unexhausted network responses #288

Merged
merged 3 commits into from
Mar 27, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle IO issues while reading from file.
  • Loading branch information
MiSikora committed Mar 26, 2020
commit 4c420b1162adca56391044522faf254b7c02a341
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class ChuckerInterceptor internal constructor(
override fun onSuccess(file: File) {
val buffer = readResponseBuffer(file, response.isGzipped)
file.delete()
processResponseBody(response, buffer, transaction)
if (buffer != null) processResponseBody(response, buffer, transaction)
collector.onResponseReceived(transaction)
}

Expand All @@ -253,15 +253,17 @@ class ChuckerInterceptor internal constructor(
collector.onResponseReceived(transaction)
}

private fun readResponseBuffer(responseBody: File, isGzipped: Boolean): Buffer {
private fun readResponseBuffer(responseBody: File, isGzipped: Boolean): Buffer? {
val bufferedSource = Okio.buffer(Okio.source(responseBody))
val source = if (isGzipped) {
GzipSource(bufferedSource)
} else {
bufferedSource
}
return Buffer().apply {
writeAll(source)
return try {
Buffer().apply { writeAll(source) }
} catch (_: IOException) {
null
}
}
}
Expand Down