This repository was archived by the owner on Sep 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Unify query and url-encoded-form implementation #694
Merged
crazytonyli
merged 13 commits into
trunk
from
http-request-builder-unify-query-and-form
Jan 23, 2024
Merged
Unify query and url-encoded-form implementation #694
crazytonyli
merged 13 commits into
trunk
from
http-request-builder-unify-query-and-form
Jan 23, 2024
Conversation
This file contains hidden or 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
The implementation is the same as the existing query encoding behaviour.
2 tasks
jkmassel
approved these changes
Jan 23, 2024
Contributor
jkmassel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Little things, the rest we discussed on Zoom
| static let nestedParameters: [String: Any] = | ||
| [ | ||
| "number": 1, | ||
| "nsnumbe-true": NSNumber(value: true), |
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: typo?
| @@ -1,5 +1,9 @@ | |||
| import Foundation | |||
|
|
|||
| /// A builder type that adding HTTP request data onto an URL. | |||
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: typo?
Contributor
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙈 Fixed in 59bd717.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Description
There are two changes in this PR.
URL encoding in query and form
We used to have different implementation around encoding name-value pair into URL query and web form in POST request body:
URLComponent's query encoding implementation is used in building URL query, and our own customized implementation (which aligns with Alamofire's implementation for backwards compatibility) is used to build web form.Now, the same implementation, which is our customized one, is used to build both query and web form. Backwards compatibility is the only reason for this change.
HTTPRequestBuilder now does not modify the original URL
Say we have
HTTPRequestBuilderinstance created using an URL "https://wp.org/api?locale=en". When adding a query.query(name: "locale", value: "zh"), the new query replaces the one in the original url. This behaviour is changed in this PR. The added query will be appended onto the original URL, which means the original url content will always be in the final result. To be honest, I don't like this new behavior, but that's what Alamofire does and we'll need to do it for backwards compatibility.Testing Details
See added unit tests.
CHANGELOG.mdif necessary.