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

Request processing refactor #543

Merged
merged 3 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
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