Skip to content

Commit

Permalink
Request processing celanup (#543)
Browse files Browse the repository at this point in the history
* Inline variable

* Simplify processing request body

* Remove return type from request processor
  • Loading branch information
MiSikora committed Feb 9, 2021
1 parent 1448158 commit 689fc05
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public class ChuckerInterceptor private constructor(
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
val transaction = HttpTransaction()
val request = requestProcessor.process(chain.request(), transaction)
val request = chain.request()

requestProcessor.process(request, transaction)

val response = try {
chain.proceed(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ internal class RequestProcessor(
private val collector: ChuckerCollector,
private val maxContentLength: Long,
) {
fun process(request: Request, transaction: HttpTransaction): Request {
fun process(request: Request, transaction: HttpTransaction) {
processMetadata(request, transaction)
processBody(request, transaction)
collector.onRequestSent(transaction)
return request
}

private fun processMetadata(request: Request, transaction: HttpTransaction) {
Expand All @@ -36,17 +35,17 @@ internal class RequestProcessor(
private fun processBody(request: Request, transaction: HttpTransaction) {
val body = request.body ?: return

val isEncodingSupported = request.headers.hasSupportedContentEncoding
if (!isEncodingSupported) {
if (!request.headers.hasSupportedContentEncoding) {
return
}

val limitingSource = try {
val requestSource = try {
Buffer().apply { body.writeTo(this) }
} catch (e: IOException) {
Logger.error("Failed to read request payload", e)
return
}.uncompress(request.headers).let { LimitingSource(it, maxContentLength) }
}
val limitingSource = LimitingSource(requestSource.uncompress(request.headers), maxContentLength)

val contentBuffer = Buffer().apply { limitingSource.use { writeAll(it) } }
if (!contentBuffer.isProbablyPlainText) {
Expand Down

0 comments on commit 689fc05

Please sign in to comment.