Skip to content

Commit

Permalink
Release 3.1.2 (#231)
Browse files Browse the repository at this point in the history
* Remove scroll flags (#210)
* Fix/gradle properties (#211)
* Allow Gradle parallel build
* Fix version name
* Fix for curl command (#214)
* Fix R8 minification crash on TransactionViewModel creation. (#219)
* Big resources renaming (#216)
* Fix clear action crash when application is dead (#222)
* Fix for crash on Save transaction action (#221)
* Show warning is transaction is null, fix crash in Save action
* Uncomment sample transactions
* Replace multiple returning with multiple throw due to detekt issue
* Add message into IOException, update string for request being not ready
* Fix for NPE in NotificationHelper (#223)
* Add additional check fo transaction being not null before getting its notificationText
* Extract transaction item from transactionBuffer
* ViewModel refactoring (#220)
* Update ViewModel dependency, refactor TransactionViewModel
* Dependencies clean up
* Switch to ViewModel on the main screen
* Fix depleting bytes from the response. (#226)
* Use HttpUrl instead of Uri for parsing URL data.
* Do not read image sources directly from the response.
* Simplify gzip logic.
* Move gzip checks from IoUtils to OkHttpUtils.
* Remove unused 'Response.hasBody()' extension.
* Update library/src/main/java/com/chuckerteam/chucker/internal/support/OkHttpUtils.kt
* Revert resource renaming (#227)
* Revert renaming
* Add changelogs for 3.1.2 (#230)
  • Loading branch information
vbuberen committed Feb 9, 2020
1 parent 0bbba97 commit fd7893d
Show file tree
Hide file tree
Showing 61 changed files with 440 additions and 680 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Change Log

## Version 3.1.2 *(2020-02-09)*

This is hot-fix release to fix multiple issues introduced in `3.1.0`.

### Summary of Changes
* All Chucker screens now have their own `ViewModel`. Due to this change user can now open the transaction in progress and the content will appear as soon as transaction finishes. No need for reopening transaction anymore.

### Bugfixes

* Fixed an [issue](https://github.com/ChuckerTeam/chucker/issues/225) introduced in 3.1.0 where image downloading fails if OkHttp was used for image loading in libraries like Glide, Picasso or Coil.
* Fixed an [issue](https://github.com/ChuckerTeam/chucker/pull/214) with invalid CURL command generation.
* Fixed an [issue](https://github.com/ChuckerTeam/chucker/issues/217) with crashes if ProGuard/R8 minification is applied to Chucker.
* Fixed an [issue](https://github.com/ChuckerTeam/chucker/pull/221) with crash when user taps Save in a transaction, which is still in progress.
* Fixed an [issue](https://github.com/ChuckerTeam/chucker/pull/222) with crash when user taps Clear from notification shade while the original app is already dead.
* Fixed an [issue](https://github.com/ChuckerTeam/chucker/pull/223) with possible NPEs.

## Version 3.1.1 *(2020-01-25)*

This is hot-fix release to fix issue introduced in `3.1.0`.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ repositories {

```groovy
dependencies {
debugImplementation "com.github.ChuckerTeam.Chucker:library:3.1.1"
releaseImplementation "com.github.ChuckerTeam.Chucker:library-no-op:3.1.1"
debugImplementation "com.github.ChuckerTeam.Chucker:library:3.1.2"
releaseImplementation "com.github.ChuckerTeam.Chucker:library-no-op:3.1.2"
}
```

Expand Down
31 changes: 20 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
buildscript {
ext {
kotlinVersion = '1.3.61'
androidGradleVersion = '3.5.3'
androidMavenGradleVersion = '2.1'

// Google libraries
appCompatVersion = '1.1.0'
constraintLayoutVersion = '1.1.3'
materialComponentsVersion = '1.1.0-rc02'
roomVersion = '2.2.3'
lifecycleVersion = '2.2.0'

// Publishing
androidMavenGradleVersion = '2.1'

// Networking
gsonVersion = '2.8.6'
okhttp3Version = '3.12.6'
retrofitVersion = '2.6.4'

// Debug and quality control
detektVersion = '1.4.0'
dokkaVersion = '0.10.0'
gradleBintrayVersion = '1.8.4'
gsonVersion = '2.8.6'
junitGradlePluignVersion = '1.3.1.1'
junitVersion = '5.4.2'
kotlinVersion = '1.3.61'
ktLintVersion = '9.1.1'
leakcanaryVersion = '2.1'
materialComponentsVersion = '1.1.0-rc02'

// Testing
junitGradlePluignVersion = '1.3.1.1'
junitVersion = '5.4.2'
mockkVersion = '1.9.3'
okhttp3Version = '3.12.6'
retrofitVersion = '2.6.4'
roomVersion = '2.2.3'
viewModelVersion = '2.1.0'
}

repositories {
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ org.gradle.jvmargs=-Xmx1536m
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true

VERSION_NAME=3.1.1
# 3*100*100 + 1*100 + 1 => 30101
VERSION_CODE=30101
VERSION_NAME=3.1.2
# 3*100*100 + 1*100 + 2 => 30102
VERSION_CODE=30102
GROUP=com.github.chuckerteam.chucker

POM_REPO_NAME=Chucker
Expand Down
15 changes: 0 additions & 15 deletions library-no-op/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2017 Jeff Gilfelt.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<manifest
package="com.chuckerteam.chucker">
</manifest>
15 changes: 9 additions & 6 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,22 @@ artifacts {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"

implementation "com.google.code.gson:gson:$gsonVersion"
implementation "com.squareup.okhttp3:okhttp:$okhttp3Version"
implementation "com.google.android.material:material:$materialComponentsVersion"
implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion"

implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
implementation "androidx.room:room-runtime:$roomVersion"
kapt "androidx.room:room-compiler:$roomVersion"

implementation "com.google.code.gson:gson:$gsonVersion"
implementation "com.squareup.okhttp3:okhttp:$okhttp3Version"

testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
testImplementation "io.mockk:mockk:$mockkVersion"

implementation "androidx.lifecycle:lifecycle-extensions:$viewModelVersion"
implementation "androidx.room:room-runtime:$roomVersion"
kapt "androidx.room:room-compiler:$roomVersion"
testImplementation "com.squareup.okhttp3:mockwebserver:$okhttp3Version"
}

apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
Expand Down
15 changes: 0 additions & 15 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2017 Jeff Gilfelt.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.chuckerteam.chucker">
<application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.chuckerteam.chucker.api
import android.content.Context
import com.chuckerteam.chucker.internal.data.entity.HttpTransaction
import com.chuckerteam.chucker.internal.support.IOUtils
import com.chuckerteam.chucker.internal.support.hasBody
import com.chuckerteam.chucker.internal.support.contentLenght
import com.chuckerteam.chucker.internal.support.contentType
import com.chuckerteam.chucker.internal.support.isGzipped
import java.io.IOException
import java.nio.charset.Charset
import okhttp3.Headers
Expand Down Expand Up @@ -60,10 +62,10 @@ class ChuckerInterceptor @JvmOverloads constructor(
throw e
}

processResponse(response, transaction)
val processedResponse = processResponse(response, transaction)
collector.onResponseReceived(transaction)

return response
return processedResponse
}

/**
Expand All @@ -76,7 +78,7 @@ class ChuckerInterceptor @JvmOverloads constructor(

transaction.apply {
setRequestHeaders(request.headers())
populateUrl(request.url().toString())
populateUrl(request.url())

isRequestBodyPlainText = encodingIsSupported
requestDate = System.currentTimeMillis()
Expand All @@ -86,7 +88,7 @@ class ChuckerInterceptor @JvmOverloads constructor(
}

if (requestBody != null && encodingIsSupported) {
val source = io.getNativeSource(Buffer(), io.bodyIsGzipped(request.headers().get(CONTENT_ENCODING)))
val source = io.getNativeSource(Buffer(), request.isGzipped)
val buffer = source.buffer()
requestBody.writeTo(buffer)
var charset: Charset = UTF8
Expand All @@ -106,8 +108,7 @@ class ChuckerInterceptor @JvmOverloads constructor(
/**
* Processes a [Response] and populates corresponding fields of a [HttpTransaction].
*/
private fun processResponse(response: Response, transaction: HttpTransaction) {
val responseBody = response.body()!!
private fun processResponse(response: Response, transaction: HttpTransaction): Response {
val responseEncodingIsSupported = io.bodyHasSupportedEncoding(response.headers().get(CONTENT_ENCODING))

transaction.apply {
Expand All @@ -122,35 +123,35 @@ class ChuckerInterceptor @JvmOverloads constructor(
responseCode = response.code()
responseMessage = response.message()

responseContentType = responseBody.contentType()?.toString()
responseContentLength = responseBody.contentLength()
responseContentType = response.contentType
responseContentLength = response.contentLenght

tookMs = (response.receivedResponseAtMillis() - response.sentRequestAtMillis())
}

if (response.hasBody() && responseEncodingIsSupported) {
processResponseBody(response, responseBody, transaction)
return if (responseEncodingIsSupported) {
processResponseBody(response, transaction)
} else {
response
}
}

/**
* Processes a [ResponseBody] and populates corresponding fields of a [HttpTransaction].
*/
private fun processResponseBody(response: Response, responseBody: ResponseBody, transaction: HttpTransaction) {
private fun processResponseBody(response: Response, transaction: HttpTransaction): Response {
val responseBody = response.body() ?: return response

val contentType = responseBody.contentType()
val charset: Charset = contentType?.charset(UTF8) ?: UTF8
val charset = contentType?.charset(UTF8) ?: UTF8
val contentLength = responseBody.contentLength()

val source = responseBody.source()
source.request(Long.MAX_VALUE) // Buffer the entire body.
var buffer = source.buffer()

if (io.bodyIsGzipped(response.headers()[CONTENT_ENCODING])) {
GzipSource(buffer.clone()).use { gzippedResponseBody ->
buffer = Buffer()
buffer.writeAll(gzippedResponseBody)
}
val responseSource = if (response.isGzipped) {
GzipSource(responseBody.source())
} else {
responseBody.source()
}
val buffer = Buffer().apply { responseSource.use { writeAll(it) } }

if (io.isPlaintext(buffer)) {
transaction.isResponseBodyPlainText = true
Expand All @@ -164,9 +165,13 @@ class ChuckerInterceptor @JvmOverloads constructor(
(contentType?.toString()?.contains(CONTENT_TYPE_IMAGE, ignoreCase = true) == true)

if (isImageContentType && buffer.size() < MAX_BLOB_SIZE) {
transaction.responseImageData = buffer.readByteArray()
transaction.responseImageData = buffer.clone().readByteArray()
}
}

return response.newBuilder()
.body(ResponseBody.create(contentType, contentLength, buffer))
.build()
}

/** Overrides all headers from [headersToRedact] with `**` */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package com.chuckerteam.chucker.internal.data.entity

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.net.Uri
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Ignore
Expand All @@ -13,8 +12,8 @@ import com.chuckerteam.chucker.internal.support.FormatUtils
import com.chuckerteam.chucker.internal.support.JsonConverter
import com.google.gson.reflect.TypeToken
import java.util.Date
import kotlin.collections.ArrayList
import okhttp3.Headers
import okhttp3.HttpUrl

/**
* Represent a full HTTP transaction (with Request and Response). Instances of this classes
Expand Down Expand Up @@ -208,12 +207,11 @@ internal class HttpTransaction(
return responseBody?.let { formatBody(it, responseContentType) } ?: ""
}

fun populateUrl(url: String): HttpTransaction {
this.url = url
val uri = Uri.parse(url)
host = uri.host
path = ("${uri.path}${uri.query?.let { "?$it" } ?: ""}")
scheme = uri.scheme
fun populateUrl(url: HttpUrl): HttpTransaction {
this.url = url.toString()
host = url.host()
path = ("/${url.pathSegments().joinToString("/")}${url.query()?.let { "?$it" } ?: ""}")
scheme = url.scheme()
return this
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ internal class ClearDatabaseService : IntentService(CLEAN_DATABASE_SERVICE_NAME)
override fun onHandleIntent(intent: Intent?) {
when (intent?.getSerializableExtra(EXTRA_ITEM_TO_CLEAR)) {
is ClearAction.Transaction -> {
RepositoryProvider.initialize(applicationContext)
RepositoryProvider.transaction().deleteAllTransactions()
NotificationHelper.clearBuffer()
NotificationHelper(this).dismissTransactionsNotification()
}
is ClearAction.Error -> {
RepositoryProvider.initialize(applicationContext)
RepositoryProvider.throwable().deleteAllThrowables()
NotificationHelper(this).dismissErrorsNotification()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ internal object FormatUtils {

fun getShareCurlCommand(transaction: HttpTransaction): String {
var compressed = false
var curlCmd = "curl -X $transaction.method"
var curlCmd = "curl -X ${transaction.method}"
val headers = transaction.getParsedRequestHeaders()

headers?.forEach { header ->
Expand All @@ -154,13 +154,13 @@ internal object FormatUtils {
) {
compressed = true
}
curlCmd += " -H \"$header.name: $header.value\""
curlCmd += " -H \"${header.name}: ${header.value}\""
}

val requestBody = transaction.requestBody
if (!requestBody.isNullOrEmpty()) {
// try to keep to a single line and use a subshell to preserve any line breaks
curlCmd += " --data $'$requestBody.replace(\"\\n\", \"\\\\n\")'"
curlCmd += " --data $'${requestBody.replace("\n", "\\n")}'"
}
curlCmd += (if (compressed) " --compressed " else " ") + transaction.url
return curlCmd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,4 @@ internal class IOUtils(private val context: Context) {
contentEncoding.isNullOrEmpty() ||
contentEncoding.equals("identity", ignoreCase = true) ||
contentEncoding.equals("gzip", ignoreCase = true)

fun bodyIsGzipped(contentEncoding: String?) = CONTENT_ENCODING_GZIP.equals(contentEncoding, ignoreCase = true)

private companion object {
const val CONTENT_ENCODING_GZIP = "gzip"
}
}

This file was deleted.

Loading

0 comments on commit fd7893d

Please sign in to comment.