Skip to content

Commit fd7893d

Browse files
authored
Release 3.1.2 (#231)
* 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)
1 parent 0bbba97 commit fd7893d

File tree

61 files changed

+440
-680
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+440
-680
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# Change Log
22

3+
## Version 3.1.2 *(2020-02-09)*
4+
5+
This is hot-fix release to fix multiple issues introduced in `3.1.0`.
6+
7+
### Summary of Changes
8+
* 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.
9+
10+
### Bugfixes
11+
12+
* 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.
13+
* Fixed an [issue](https://github.com/ChuckerTeam/chucker/pull/214) with invalid CURL command generation.
14+
* Fixed an [issue](https://github.com/ChuckerTeam/chucker/issues/217) with crashes if ProGuard/R8 minification is applied to Chucker.
15+
* Fixed an [issue](https://github.com/ChuckerTeam/chucker/pull/221) with crash when user taps Save in a transaction, which is still in progress.
16+
* 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.
17+
* Fixed an [issue](https://github.com/ChuckerTeam/chucker/pull/223) with possible NPEs.
18+
319
## Version 3.1.1 *(2020-01-25)*
420

521
This is hot-fix release to fix issue introduced in `3.1.0`.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ repositories {
4242

4343
```groovy
4444
dependencies {
45-
debugImplementation "com.github.ChuckerTeam.Chucker:library:3.1.1"
46-
releaseImplementation "com.github.ChuckerTeam.Chucker:library-no-op:3.1.1"
45+
debugImplementation "com.github.ChuckerTeam.Chucker:library:3.1.2"
46+
releaseImplementation "com.github.ChuckerTeam.Chucker:library-no-op:3.1.2"
4747
}
4848
```
4949

build.gradle

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
buildscript {
22
ext {
3+
kotlinVersion = '1.3.61'
34
androidGradleVersion = '3.5.3'
4-
androidMavenGradleVersion = '2.1'
5+
6+
// Google libraries
57
appCompatVersion = '1.1.0'
68
constraintLayoutVersion = '1.1.3'
9+
materialComponentsVersion = '1.1.0-rc02'
10+
roomVersion = '2.2.3'
11+
lifecycleVersion = '2.2.0'
12+
13+
// Publishing
14+
androidMavenGradleVersion = '2.1'
15+
16+
// Networking
17+
gsonVersion = '2.8.6'
18+
okhttp3Version = '3.12.6'
19+
retrofitVersion = '2.6.4'
20+
21+
// Debug and quality control
722
detektVersion = '1.4.0'
823
dokkaVersion = '0.10.0'
9-
gradleBintrayVersion = '1.8.4'
10-
gsonVersion = '2.8.6'
11-
junitGradlePluignVersion = '1.3.1.1'
12-
junitVersion = '5.4.2'
13-
kotlinVersion = '1.3.61'
1424
ktLintVersion = '9.1.1'
1525
leakcanaryVersion = '2.1'
16-
materialComponentsVersion = '1.1.0-rc02'
26+
27+
// Testing
28+
junitGradlePluignVersion = '1.3.1.1'
29+
junitVersion = '5.4.2'
1730
mockkVersion = '1.9.3'
18-
okhttp3Version = '3.12.6'
19-
retrofitVersion = '2.6.4'
20-
roomVersion = '2.2.3'
21-
viewModelVersion = '2.1.0'
2231
}
2332

2433
repositories {

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ org.gradle.jvmargs=-Xmx1536m
1616
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1717
org.gradle.parallel=true
1818

19-
VERSION_NAME=3.1.1
20-
# 3*100*100 + 1*100 + 1 => 30101
21-
VERSION_CODE=30101
19+
VERSION_NAME=3.1.2
20+
# 3*100*100 + 1*100 + 2 => 30102
21+
VERSION_CODE=30102
2222
GROUP=com.github.chuckerteam.chucker
2323

2424
POM_REPO_NAME=Chucker
Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!--
3-
~ Copyright (C) 2017 Jeff Gilfelt.
4-
~
5-
~ Licensed under the Apache License, Version 2.0 (the "License");
6-
~ you may not use this file except in compliance with the License.
7-
~ You may obtain a copy of the License at
8-
~
9-
~ http://www.apache.org/licenses/LICENSE-2.0
10-
~
11-
~ Unless required by applicable law or agreed to in writing, software
12-
~ distributed under the License is distributed on an "AS IS" BASIS,
13-
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
~ See the License for the specific language governing permissions and
15-
~ limitations under the License.
16-
-->
172
<manifest
183
package="com.chuckerteam.chucker">
194
</manifest>

library/build.gradle

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,22 @@ artifacts {
5959
dependencies {
6060
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
6161

62-
implementation "com.google.code.gson:gson:$gsonVersion"
63-
implementation "com.squareup.okhttp3:okhttp:$okhttp3Version"
6462
implementation "com.google.android.material:material:$materialComponentsVersion"
6563
implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion"
6664

65+
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
66+
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
67+
implementation "androidx.room:room-runtime:$roomVersion"
68+
kapt "androidx.room:room-compiler:$roomVersion"
69+
70+
implementation "com.google.code.gson:gson:$gsonVersion"
71+
implementation "com.squareup.okhttp3:okhttp:$okhttp3Version"
72+
6773
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
6874
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
6975
testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
7076
testImplementation "io.mockk:mockk:$mockkVersion"
71-
72-
implementation "androidx.lifecycle:lifecycle-extensions:$viewModelVersion"
73-
implementation "androidx.room:room-runtime:$roomVersion"
74-
kapt "androidx.room:room-compiler:$roomVersion"
77+
testImplementation "com.squareup.okhttp3:mockwebserver:$okhttp3Version"
7578
}
7679

7780
apply from: rootProject.file('gradle/gradle-mvn-push.gradle')

library/src/main/AndroidManifest.xml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!--
3-
~ Copyright (C) 2017 Jeff Gilfelt.
4-
~
5-
~ Licensed under the Apache License, Version 2.0 (the "License");
6-
~ you may not use this file except in compliance with the License.
7-
~ You may obtain a copy of the License at
8-
~
9-
~ http://www.apache.org/licenses/LICENSE-2.0
10-
~
11-
~ Unless required by applicable law or agreed to in writing, software
12-
~ distributed under the License is distributed on an "AS IS" BASIS,
13-
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
~ See the License for the specific language governing permissions and
15-
~ limitations under the License.
16-
-->
172
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
183
package="com.chuckerteam.chucker">
194
<application>

library/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package com.chuckerteam.chucker.api
33
import android.content.Context
44
import com.chuckerteam.chucker.internal.data.entity.HttpTransaction
55
import com.chuckerteam.chucker.internal.support.IOUtils
6-
import com.chuckerteam.chucker.internal.support.hasBody
6+
import com.chuckerteam.chucker.internal.support.contentLenght
7+
import com.chuckerteam.chucker.internal.support.contentType
8+
import com.chuckerteam.chucker.internal.support.isGzipped
79
import java.io.IOException
810
import java.nio.charset.Charset
911
import okhttp3.Headers
@@ -60,10 +62,10 @@ class ChuckerInterceptor @JvmOverloads constructor(
6062
throw e
6163
}
6264

63-
processResponse(response, transaction)
65+
val processedResponse = processResponse(response, transaction)
6466
collector.onResponseReceived(transaction)
6567

66-
return response
68+
return processedResponse
6769
}
6870

6971
/**
@@ -76,7 +78,7 @@ class ChuckerInterceptor @JvmOverloads constructor(
7678

7779
transaction.apply {
7880
setRequestHeaders(request.headers())
79-
populateUrl(request.url().toString())
81+
populateUrl(request.url())
8082

8183
isRequestBodyPlainText = encodingIsSupported
8284
requestDate = System.currentTimeMillis()
@@ -86,7 +88,7 @@ class ChuckerInterceptor @JvmOverloads constructor(
8688
}
8789

8890
if (requestBody != null && encodingIsSupported) {
89-
val source = io.getNativeSource(Buffer(), io.bodyIsGzipped(request.headers().get(CONTENT_ENCODING)))
91+
val source = io.getNativeSource(Buffer(), request.isGzipped)
9092
val buffer = source.buffer()
9193
requestBody.writeTo(buffer)
9294
var charset: Charset = UTF8
@@ -106,8 +108,7 @@ class ChuckerInterceptor @JvmOverloads constructor(
106108
/**
107109
* Processes a [Response] and populates corresponding fields of a [HttpTransaction].
108110
*/
109-
private fun processResponse(response: Response, transaction: HttpTransaction) {
110-
val responseBody = response.body()!!
111+
private fun processResponse(response: Response, transaction: HttpTransaction): Response {
111112
val responseEncodingIsSupported = io.bodyHasSupportedEncoding(response.headers().get(CONTENT_ENCODING))
112113

113114
transaction.apply {
@@ -122,35 +123,35 @@ class ChuckerInterceptor @JvmOverloads constructor(
122123
responseCode = response.code()
123124
responseMessage = response.message()
124125

125-
responseContentType = responseBody.contentType()?.toString()
126-
responseContentLength = responseBody.contentLength()
126+
responseContentType = response.contentType
127+
responseContentLength = response.contentLenght
127128

128129
tookMs = (response.receivedResponseAtMillis() - response.sentRequestAtMillis())
129130
}
130131

131-
if (response.hasBody() && responseEncodingIsSupported) {
132-
processResponseBody(response, responseBody, transaction)
132+
return if (responseEncodingIsSupported) {
133+
processResponseBody(response, transaction)
134+
} else {
135+
response
133136
}
134137
}
135138

136139
/**
137140
* Processes a [ResponseBody] and populates corresponding fields of a [HttpTransaction].
138141
*/
139-
private fun processResponseBody(response: Response, responseBody: ResponseBody, transaction: HttpTransaction) {
142+
private fun processResponseBody(response: Response, transaction: HttpTransaction): Response {
143+
val responseBody = response.body() ?: return response
144+
140145
val contentType = responseBody.contentType()
141-
val charset: Charset = contentType?.charset(UTF8) ?: UTF8
146+
val charset = contentType?.charset(UTF8) ?: UTF8
142147
val contentLength = responseBody.contentLength()
143148

144-
val source = responseBody.source()
145-
source.request(Long.MAX_VALUE) // Buffer the entire body.
146-
var buffer = source.buffer()
147-
148-
if (io.bodyIsGzipped(response.headers()[CONTENT_ENCODING])) {
149-
GzipSource(buffer.clone()).use { gzippedResponseBody ->
150-
buffer = Buffer()
151-
buffer.writeAll(gzippedResponseBody)
152-
}
149+
val responseSource = if (response.isGzipped) {
150+
GzipSource(responseBody.source())
151+
} else {
152+
responseBody.source()
153153
}
154+
val buffer = Buffer().apply { responseSource.use { writeAll(it) } }
154155

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

166167
if (isImageContentType && buffer.size() < MAX_BLOB_SIZE) {
167-
transaction.responseImageData = buffer.readByteArray()
168+
transaction.responseImageData = buffer.clone().readByteArray()
168169
}
169170
}
171+
172+
return response.newBuilder()
173+
.body(ResponseBody.create(contentType, contentLength, buffer))
174+
.build()
170175
}
171176

172177
/** Overrides all headers from [headersToRedact] with `**` */

library/src/main/java/com/chuckerteam/chucker/internal/data/entity/HttpTransaction.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package com.chuckerteam.chucker.internal.data.entity
44

55
import android.graphics.Bitmap
66
import android.graphics.BitmapFactory
7-
import android.net.Uri
87
import androidx.room.ColumnInfo
98
import androidx.room.Entity
109
import androidx.room.Ignore
@@ -13,8 +12,8 @@ import com.chuckerteam.chucker.internal.support.FormatUtils
1312
import com.chuckerteam.chucker.internal.support.JsonConverter
1413
import com.google.gson.reflect.TypeToken
1514
import java.util.Date
16-
import kotlin.collections.ArrayList
1715
import okhttp3.Headers
16+
import okhttp3.HttpUrl
1817

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

211-
fun populateUrl(url: String): HttpTransaction {
212-
this.url = url
213-
val uri = Uri.parse(url)
214-
host = uri.host
215-
path = ("${uri.path}${uri.query?.let { "?$it" } ?: ""}")
216-
scheme = uri.scheme
210+
fun populateUrl(url: HttpUrl): HttpTransaction {
211+
this.url = url.toString()
212+
host = url.host()
213+
path = ("/${url.pathSegments().joinToString("/")}${url.query()?.let { "?$it" } ?: ""}")
214+
scheme = url.scheme()
217215
return this
218216
}
219217
}

library/src/main/java/com/chuckerteam/chucker/internal/support/ClearDatabaseService.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ internal class ClearDatabaseService : IntentService(CLEAN_DATABASE_SERVICE_NAME)
1010
override fun onHandleIntent(intent: Intent?) {
1111
when (intent?.getSerializableExtra(EXTRA_ITEM_TO_CLEAR)) {
1212
is ClearAction.Transaction -> {
13+
RepositoryProvider.initialize(applicationContext)
1314
RepositoryProvider.transaction().deleteAllTransactions()
1415
NotificationHelper.clearBuffer()
1516
NotificationHelper(this).dismissTransactionsNotification()
1617
}
1718
is ClearAction.Error -> {
19+
RepositoryProvider.initialize(applicationContext)
1820
RepositoryProvider.throwable().deleteAllThrowables()
1921
NotificationHelper(this).dismissErrorsNotification()
2022
}

library/src/main/java/com/chuckerteam/chucker/internal/support/FormatUtils.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ internal object FormatUtils {
145145

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

151151
headers?.forEach { header ->
@@ -154,13 +154,13 @@ internal object FormatUtils {
154154
) {
155155
compressed = true
156156
}
157-
curlCmd += " -H \"$header.name: $header.value\""
157+
curlCmd += " -H \"${header.name}: ${header.value}\""
158158
}
159159

160160
val requestBody = transaction.requestBody
161161
if (!requestBody.isNullOrEmpty()) {
162162
// try to keep to a single line and use a subshell to preserve any line breaks
163-
curlCmd += " --data $'$requestBody.replace(\"\\n\", \"\\\\n\")'"
163+
curlCmd += " --data $'${requestBody.replace("\n", "\\n")}'"
164164
}
165165
curlCmd += (if (compressed) " --compressed " else " ") + transaction.url
166166
return curlCmd

library/src/main/java/com/chuckerteam/chucker/internal/support/IOUtils.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,4 @@ internal class IOUtils(private val context: Context) {
6666
contentEncoding.isNullOrEmpty() ||
6767
contentEncoding.equals("identity", ignoreCase = true) ||
6868
contentEncoding.equals("gzip", ignoreCase = true)
69-
70-
fun bodyIsGzipped(contentEncoding: String?) = CONTENT_ENCODING_GZIP.equals(contentEncoding, ignoreCase = true)
71-
72-
private companion object {
73-
const val CONTENT_ENCODING_GZIP = "gzip"
74-
}
7569
}

library/src/main/java/com/chuckerteam/chucker/internal/support/LiveDataUtils.kt

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)