File tree 4 files changed +24
-2
lines changed
main/kotlin/com/chuckerteam/chucker
test/kotlin/com/chuckerteam/chucker/api
4 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ Please add your entries according to this format.
11
11
* Kotlin to 2.0.20
12
12
* AGP to 8.5.2
13
13
* Fix Toolbar is not accessible on api level 35 [ #1280 ]
14
+ * Fixed the ` skipPaths ` method unexpectedly modified the passed arguments [ #1237 ]
14
15
15
16
### Added
16
17
* Added _ save as text_ and _ save as .har file_ options to save all transactions [ #1214 ]
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import com.chuckerteam.chucker.internal.support.CacheDirectoryProvider
7
7
import com.chuckerteam.chucker.internal.support.PlainTextDecoder
8
8
import com.chuckerteam.chucker.internal.support.RequestProcessor
9
9
import com.chuckerteam.chucker.internal.support.ResponseProcessor
10
+ import com.chuckerteam.chucker.internal.support.addNonBlankPathSegments
10
11
import okhttp3.HttpUrl
11
12
import okhttp3.Interceptor
12
13
import okhttp3.Response
@@ -199,6 +200,9 @@ public class ChuckerInterceptor private constructor(
199
200
/* *
200
201
* Sets a list of [String] to skip paths. When any of the [String] matches
201
202
* a request path, the request will be skipped.
203
+ *
204
+ * **Note:** An empty path will be treated as the '/'.
205
+ * '//' will also be treated as the '/' path.
202
206
*/
203
207
public fun skipPaths (vararg paths : String ): Builder =
204
208
apply {
@@ -207,7 +211,8 @@ public class ChuckerInterceptor private constructor(
207
211
HttpUrl .Builder ()
208
212
.scheme(" https" )
209
213
.host(" example.com" )
210
- .addPathSegment(candidatePath).build()
214
+ .addNonBlankPathSegments(candidatePath)
215
+ .build()
211
216
this @Builder.skipPaths.add(httpUrl.encodedPath)
212
217
}
213
218
}
Original file line number Diff line number Diff line change
1
+ package com.chuckerteam.chucker.internal.support
2
+
3
+ import okhttp3.HttpUrl
4
+
5
+ private const val PATH_SEGMENTS_DELIMITER = " /"
6
+
7
+ public fun HttpUrl.Builder.addNonBlankPathSegments (candidatePath : String ): HttpUrl .Builder =
8
+ apply {
9
+ candidatePath.split(PATH_SEGMENTS_DELIMITER ).filter { it.isNotBlank() }
10
+ .forEach { item -> addPathSegment(item) }
11
+ }
Original file line number Diff line number Diff line change 1
1
package com.chuckerteam.chucker.api
2
2
3
+ import com.chuckerteam.chucker.internal.support.addNonBlankPathSegments
3
4
import com.chuckerteam.chucker.util.ChuckerInterceptorDelegate
4
5
import com.chuckerteam.chucker.util.ClientFactory
5
6
import com.chuckerteam.chucker.util.NoLoggerRule
@@ -379,7 +380,11 @@ internal class ChuckerInterceptorSkipRequestTest {
379
380
responseBody : String ,
380
381
) {
381
382
val httpUrl =
382
- HttpUrl .Builder ().scheme(" https" ).host(" testexample.com" ).addPathSegment(path).build()
383
+ HttpUrl .Builder ()
384
+ .scheme(" https" )
385
+ .host(" testexample.com" )
386
+ .addNonBlankPathSegments(path)
387
+ .build()
383
388
384
389
val request = Request .Builder ().url(server.url(httpUrl.encodedPath)).build()
385
390
server.enqueue(MockResponse ().setBody(responseBody))
You can’t perform that action at this time.
0 commit comments