Do not log big data request (ex: file upload)
This commit is contained in:
parent
ae8bceacba
commit
4c04014e4d
@ -22,6 +22,7 @@ import okhttp3.Interceptor
|
|||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import okhttp3.logging.HttpLoggingInterceptor
|
import okhttp3.logging.HttpLoggingInterceptor
|
||||||
import okio.Buffer
|
import okio.Buffer
|
||||||
|
import timber.log.Timber
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.nio.charset.Charset
|
import java.nio.charset.Charset
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -58,6 +59,11 @@ internal class CurlLoggingInterceptor @Inject constructor(private val logger: Ht
|
|||||||
|
|
||||||
val requestBody = request.body()
|
val requestBody = request.body()
|
||||||
if (requestBody != null) {
|
if (requestBody != null) {
|
||||||
|
if (requestBody.contentLength() > 100_000) {
|
||||||
|
Timber.w("Unable to log curl command data, size is too big (${requestBody.contentLength()})")
|
||||||
|
// Ensure the curl command will failed
|
||||||
|
curlCmd += "DATA IS TOO BIG"
|
||||||
|
} else {
|
||||||
val buffer = Buffer()
|
val buffer = Buffer()
|
||||||
requestBody.writeTo(buffer)
|
requestBody.writeTo(buffer)
|
||||||
var charset: Charset? = UTF8
|
var charset: Charset? = UTF8
|
||||||
@ -68,6 +74,7 @@ internal class CurlLoggingInterceptor @Inject constructor(private val logger: Ht
|
|||||||
// try to keep to a single line and use a subshell to preserve any line breaks
|
// try to keep to a single line and use a subshell to preserve any line breaks
|
||||||
curlCmd += " --data $'" + buffer.readString(charset!!).replace("\n", "\\n") + "'"
|
curlCmd += " --data $'" + buffer.readString(charset!!).replace("\n", "\\n") + "'"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val headers = request.headers()
|
val headers = request.headers()
|
||||||
var i = 0
|
var i = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user