-
-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add switching between encoded and decoded URL formats. (#233)
* Add switching between encoded and decoded URL formats. * Make URL encoding transaction specific. * Change test name for upcoming #244 PR. * Use LiveDataRecord for combineLatest tests. * Properly switch encoding and decoding URL. * Show encoding icon only when it is viable. * Add encoded URL samples to HttpBinClient. * Avoid using 'this' scoping mechanism for URL.
- Loading branch information
Showing
24 changed files
with
420 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
library/src/main/java/com/chuckerteam/chucker/internal/support/FormattedUrl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.chuckerteam.chucker.internal.support | ||
|
||
import okhttp3.HttpUrl | ||
|
||
internal class FormattedUrl private constructor( | ||
val scheme: String, | ||
val host: String, | ||
val path: String, | ||
val query: String | ||
) { | ||
val pathWithQuery: String | ||
get() = if (query.isBlank()) { | ||
path | ||
} else { | ||
"$path?$query" | ||
} | ||
|
||
val url get() = "$scheme://$host$pathWithQuery" | ||
|
||
companion object { | ||
fun fromHttpUrl(httpUrl: HttpUrl, encoded: Boolean): FormattedUrl { | ||
return if (encoded) { | ||
encodedUrl(httpUrl) | ||
} else { | ||
decodedUrl(httpUrl) | ||
} | ||
} | ||
|
||
private fun encodedUrl(httpUrl: HttpUrl): FormattedUrl { | ||
val path = httpUrl.encodedPathSegments().joinToString("/") | ||
return FormattedUrl( | ||
httpUrl.scheme(), | ||
httpUrl.host(), | ||
if (path.isNotBlank()) "/$path" else "", | ||
httpUrl.encodedQuery().orEmpty() | ||
) | ||
} | ||
|
||
private fun decodedUrl(httpUrl: HttpUrl): FormattedUrl { | ||
val path = httpUrl.pathSegments().joinToString("/") | ||
return FormattedUrl( | ||
httpUrl.scheme(), | ||
httpUrl.host(), | ||
if (path.isNotBlank()) "/$path" else "", | ||
httpUrl.query().orEmpty() | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.