Skip to content

Commit

Permalink
fix giokit http interceptor null point exceptioon (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacm authored May 8, 2024
1 parent 4c36817 commit 6cd097f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,31 @@ class GioHttpCaptureInterceptor @JvmOverloads constructor() : Interceptor {
log("--> END ${request.method()} (encoded body omitted)")
} else if (bodyHasSnappyEncoding(request.headers())) {
val buffer = Buffer()
requestBody!!.writeTo(buffer)
requestBody?.writeTo(buffer)

log("")
val byteArray = buffer.readByteArray()
val compressedOut = XORUtils.encrypt(byteArray, (gioHttp.httpTime and 0xFF).toInt())
gioHttp.requestBody = String(Snappy.uncompress(compressedOut, 0, compressedOut.size))
log(gioHttp.requestBody)
log("--> END ${request.method()} (${requestBody.contentLength()}-byte body)")
log("--> END ${request.method()} (${requestBody?.contentLength() ?: 0}-byte body)")
} else {
val buffer = Buffer()
requestBody!!.writeTo(buffer)
requestBody?.writeTo(buffer)

val contentType = requestBody.contentType()
val contentType = requestBody?.contentType()
val charset: Charset =
contentType?.charset(StandardCharsets.UTF_8) ?: StandardCharsets.UTF_8

log("")
if (buffer.isProbablyUtf8()) {
gioHttp.requestBody = buffer.readString(charset)
log(gioHttp.requestBody)
log("--> END ${request.method()} (${requestBody.contentLength()}-byte body)")
log("--> END ${request.method()} (${requestBody?.contentLength() ?: 0}-byte body)")
} else {
gioHttp.requestBody = buffer.readString(charset)
//gioHttp.requestBody = "encoded body omitted (e.g. protobuf)"
log("--> END ${request.method()} (binary ${requestBody.contentLength()}-byte body omitted. e.g. protobuf)")
log("--> END ${request.method()} (binary ${requestBody?.contentLength() ?: 0}-byte body omitted. e.g. protobuf)")
}
}

Expand All @@ -113,8 +113,8 @@ class GioHttpCaptureInterceptor @JvmOverloads constructor() : Interceptor {
val tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs)
gioHttp.httpCost = tookMs

val responseBody = response.body()!!
val contentLength = responseBody.contentLength()
val responseBody = response.body()
val contentLength = responseBody?.contentLength() ?: 0
val bodySize = if (contentLength != -1L) "$contentLength-byte" else "unknown-length"
gioHttp.responseCode = response.code()
gioHttp.responseSize = contentLength
Expand All @@ -137,7 +137,7 @@ class GioHttpCaptureInterceptor @JvmOverloads constructor() : Interceptor {
if (bodyHasUnknownEncoding(response.headers())) {
gioHttp.responseBody = "encoded body omitted"
log("<-- END HTTP (encoded body omitted)")
} else {
} else if (responseBody != null) {
val source = responseBody.source()
source.request(Long.MAX_VALUE) // Buffer the entire body.
var buffer = source.buffer()
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ powermock = "2.0.9"
# !!! SDK VERSION !!!
growingio = "4.1.0"
growingioPlugin = "4.1.0"
giokit = "2.1.1"
giokitCode = "21"
giokit = "2.1.2"
giokitCode = "22"

[plugins]
android-application = { id = "com.android.application", version.ref = "pluginGradle" }
Expand Down

0 comments on commit 6cd097f

Please sign in to comment.