KTOR-7190: Add support for encoded non-text queries #4110
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Subsystem
The changes only affect URLBuilder internals and some other internal APIs. No public API was affected.
Motivation
It fixes https://youtrack.jetbrains.com/issue/KTOR-7190/URLBuilder.encodedParameters-cant-handle-encoded-non-text-query-data.
Solution
Former solution assumed that any query parameter is able to be decoded as an UTF-8 string. And any encoded query parameter was decoded during the building an URL and after that encoded back to create a textual representation of an URL. Unfortunately it crashes an app if it tries to add something like bittorrent info_hash parameter (also see #1351 (comment)) because there are a lot of byte sequences which can't be decoded as an UTF-8 string.
My solution reverses the data flow. I added one special ParametersBuilder for undecodable query parameters where they are stored in encoded form. And URLBuilder.encodedParameters became just a wrapper which stores decodable parameters in URLBuilder.parameters and undecodable ones in the private URLBuilder.rawEncodedParameters.