-
-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore domains and paths from interceptor #1236
Comments
This sounds reasonable to add.
This feels like an overkill to me and not something we probably want to maintain/test, etc. |
Ignoring the path is more important for me than domian.
We would be receiving the Regex from App, hence we only call diff --git a/library/src/main/kotlin/com/chuckerteam/chucker/api/ChuckerInterceptor.kt b/library/src/main/kotlin/com/chuckerteam/chucker/api/ChuckerInterceptor.kt
index 10a6e9c..7e0f03f 100644
--- a/library/src/main/kotlin/com/chuckerteam/chucker/api/ChuckerInterceptor.kt
+++ b/library/src/main/kotlin/com/chuckerteam/chucker/api/ChuckerInterceptor.kt
@@ -56,6 +56,7 @@ public class ChuckerInterceptor private constructor(
)
private val skipPaths = builder.skipPaths.toSet()
+ private val skipPathsRegex = builder.skipPathsRegex.toSet()
init {
if (builder.createShortcut) {
@@ -72,8 +73,9 @@ public class ChuckerInterceptor private constructor(
override fun intercept(chain: Interceptor.Chain): Response {
val transaction = HttpTransaction()
val request = chain.request()
- val shouldProcessTheRequest = !skipPaths.any { it == request.url.encodedPath }
- if (shouldProcessTheRequest) {
+ val shouldSkipPath = skipPaths.contains(request.url.encodedPath) || skipPathsRegex.any { it.matches(request.url.encodedPath) }
+
+ if (!shouldSkipPath) {
requestProcessor.process(request, transaction)
}
val response =
@@ -84,7 +86,7 @@ public class ChuckerInterceptor private constructor(
collector.onResponseReceived(transaction)
throw e
}
- return if (shouldProcessTheRequest) {
+ return if (!shouldSkipPath) {
responseProcessor.process(response, transaction)
} else {
response
@@ -105,7 +107,8 @@ public class ChuckerInterceptor private constructor(
internal var headersToRedact = emptySet<String>()
internal var decoders = emptyList<BodyDecoder>()
internal var createShortcut = true
- internal var skipPaths = mutableSetOf<String>()
+ internal val skipPaths = mutableSetOf<String>()
+ internal val skipPathsRegex = mutableSetOf<Regex>()
/**
* Sets the [ChuckerCollector] to customize data retention.
@@ -195,6 +198,11 @@ public class ChuckerInterceptor private constructor(
}
}
+ public fun skipPaths(vararg skipPaths: Regex): Builder =
+ apply {
+ this@Builder.skipPathsRegex.addAll(skipPaths.toSet())
+ }
+
/**
* Creates a new [ChuckerInterceptor] instance with values defined in this builder.
*/ |
Can you give me some real world examples of paths you want to ignore with Regex just to understand your use case? |
Some of the domain for these paths are well known, sometimes they are dynamically named by cloud provider. ex: CloudFront Possible Paths for the images.
Ignore the below info, it is not relavant. |
Other than:
all the others can be easily achieved with What would be your |
To confirm this statement, do you mean existing Regex for |
I meant the already existing Anyway, I think it's reasonable to add |
skipPaths
Allow to selectively skip Chucker interception #266 allow chucker to skip regex of paths and domains.💡 Describe the solution you'd like
fun skipDomains(vararg pattern: kotlin.text.Regex)
to skip the domains user are not intereseted in tapping.fun skipPaths(vararg pattern: kotlin.text.Regex)
with Regex, this way user can skip parts of path that they are not interested.📊 Describe alternatives you've considered
📄 Additional context
Provide
fun skipDomains(vararg pattern: kotlin.text.Regex)
to skip the domains user are not intereseted in tapping.Below are possible domains, subdomains that user is not interested.
assets.example.com
dam.example.com
notinterested.example.com
analytics.example.com
thirdparty.com
overload
fun skipPaths(vararg pattern: kotlin.text.Regex)
with Regex, this way user can skip parts of path that they are not interested.v1/not/very/interesting/path
v2/not/very/interesting/path/maybe
not/very/interesting
/important/but/i/dont/care/
/dynamic/path/from/dam/assets/my-image.jpg
/dynamic/path/from/dam/assets/my-image.png
Initially I considered
String
over regex. But, regex gives more flexibility to the user to ignore more with less. ex:".*(jpg|jpeg|png|gif|webp)$".toRegex()
in one. If this was string.jpg
,.jpeg
,.png
,.gif
,.webp
would need 5 loops.* "not/very/important/in/here" // <-- Ingore* "not/very/important/in/here/not/important/at/all", // <-- Ignore* "not/very/important/in/here/but/important" // <-- DO NOT INGORE* "not/very/important/in/here/also/but/many-be/important/req" // <-- DO NOT INGORERegex("""^not/very/important/in/here(?!/but.*important).*""")
🙋 Do you want to develop this feature yourself?
The text was updated successfully, but these errors were encountered: