-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relax the validation of
Location
header when redirecting (#5477)
Reported by @ohadgur at https://discord.com/channels/1087271586832318494/1209914423494311948 Motivation: If a client is configured to follow redirects with `followRedirects()`, the client will validate the value of `Location` header before sending a follow-up request to the given redirect location. `RedirectingClient` validates and resolves the target location using `URI.resolve()` which rejects poorly encoded `Location` header values such as: - `Location: /foo bar` (space should be percent-encoded) - `Location: /?${}` (`$`, `{` and `}` should be percent-encoded.) Such strict validation might not be suitable in real world scenarios and we could normalize them just like a client validates and normalizes the initial request target. Modifications: - `RedirectingClient` now uses `RequestTarget.forClient()` to parse and normalize the target location so it is more tolerant to poorly encoded `Location` header values. - `RedirectingClient` now implements its own relative path resolution logic. See `RedirectingClient.resolveLocation()` and `resolveRelativeLocation() for the detail. - Added `host` and `port` properties to `RequestTarget`. - Added `host` property to `ClientRequestContext`. - Moved `DefaultRequestTarget.findAuthority()` to `ArmeriaHttpUtil` to reuse it in `RedirectingClient`. - Miscellaneous: - Fixed a potential bug where `RoutingContext.newPath()` creates a new `RequestTarget` whose `path` is `null` - Fixed a bug where `ClientRequestContext.uri()` returns a double-encoded URI (Special thanks to @ohadgur for reporting this bug and suggesting a fix.) - Improved `RequestTarget.forClient()` to remove the port number in an absolute request target when possible, so that `http://a:80` is normalized into `http://a`. Result: - (Bug fix) An Armeria client is now more tolerant to poorly encoded `Location` header values when following redirects. - (New feature) You can now get the host and port part separately from a `RequestTarget` using `RequestTarget.host()` and `RequestTarget.port()`. - (New feature) You can now get the host part from authority of the request URI using `ClientRequestContext.host()`. - (Improvement) `RequestTarget.forClient()` now removes a redundant port number from the specified URI for simpler request target comparison. For example, `https://foo` and `https://foo:443` are considered equal. --------- Co-authored-by: minux <songmw725@gmail.com>
- Loading branch information
Showing
14 changed files
with
516 additions
and
116 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
Oops, something went wrong.