-
Notifications
You must be signed in to change notification settings - Fork 16
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
ApacheHttpClientBlockingChannel uses URL to build request #2437
ApacheHttpClientBlockingChannel uses URL to build request #2437
Conversation
Generate changelog in
|
try { | ||
return URIAuthority.create(url.getAuthority()); | ||
} catch (URISyntaxException e) { | ||
throw new SafeIllegalArgumentException("Invalid URI authority", e, UnsafeArg.of("url", url)); | ||
} |
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.
I wonder if it's worth rolling the dice with something along these lines to avoid string tokenizing/manipulation overhead? We have most of the data parsed out via URL already, I believe it's just ipv6 brackets that URL doesn't handle well.
String host = url.getHost();
if (host != null && host.startsWith("[") && host.endsWith("]")) {
host = host.substring(1, host.length() - 1);
}
return new URIAuthority(url.getUserInfo(), host, url.getPort());
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.
Alternatively, it may be safer if we check host != null && host.startsWith("[")
and in that case, we use the parsing URIAuthority.create
path, otherwise (in the common case) use new URIAuthority(url.getUserInfo(), host, url.getPort());
@VisibleForTesting | ||
static URIAuthority parseAuthority(URL url) { | ||
try { | ||
return URIAuthority.create(url.getAuthority()); |
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.
+1 I've verified that url.getAuthority()
is equivalent to URI.getRawAuthority()
, which is used internally within apache httpclient.
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.
Specifically we're computing the authority similar to what is done in:
"https://www.example.com:443, www.example.com, 443,", | ||
"https://www.example.com/path/to/foo/bar, www.example.com, -1,", | ||
"https://www.example.com/path/to/foo/bar?baz=quux&hello=world#hash-octothorpe, www.example.com, -1,", | ||
"https://[email protected]:8443/path/to/foo/bar?baz=quux&hello=world#hash-octothorpe ," |
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.
Let's add a couple test cases for encoding edge cases:
- A URL which includes percent-escaped values in the users password:
https://user:slash%[email protected]
- A URL which includes bracket-formatted ipv6 address:
https://user@[::1]/path
(perhaps with and without a port)
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.
Thanks, added some more test coverage.
b83036c
to
76686b4
Compare
c637a13
to
a03da51
Compare
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.
thanks!
Released 4.6.0 |
Before this PR
Noticed new URI(String) and some of its side effects in JFRs from services making high volumes of Dialogue requests.
Splitting out of PR #2432
After this PR
==COMMIT_MSG==
Parsing String to URI can be expensive in terms of CPU and allocations for high throughput services.
==COMMIT_MSG==
Possible downsides?