HttpClient: omit default port 80 when rebuilding HTTP URLs#1108
Open
HttpClient: omit default port 80 when rebuilding HTTP URLs#1108
Conversation
When the original URL had no explicit port, HttpClientJavaLib was re-assembling it as http://host:80/path, sending Host: host:80 in the request. Some servers (e.g. IIS) copy the request authority verbatim into the Location header of a redirect, producing broken redirects to https://host:80/... that fail TLS handshake. Aligns the http branch with the https branch (which already omitted the default 443) so the port is only appended when it differs from the scheme default.
Collaborator
Cherry pick to beta success |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
When the original URL had no explicit port,
HttpClientJavaLibwas re-assembling it ashttp://host:80/path, which made Apache HttpClient sendHost: host:80in the request. Some servers (e.g. IIS) copy the request authority verbatim into theLocationheader of a redirect, producing broken redirects likehttps://host:80/...that fail the TLS handshake on port 80.This change aligns the http branch with the https branch (which already omitted the default 443) so the port is only appended when it differs from the scheme default.
Background
Reproduced calling
http://sdx.genexus.com/agetqrcode.aspx?.... The server replies with301 Location: https://sdx.genexus.com:80/...because the incomingHostheader contained:80. Apache HttpClient follows the redirect and tries to negotiate TLS against port 80, which fails withSSLException: Unsupported or unrecognized SSL message. TheHttpClientthen leavesresponse = nulland downstream code (e.g.GXutil.ImageUrlToBytes) throws a cryptic NPE onIOUtils.toByteArray(null).A browser hitting the same URL works because it never adds the default port to the
Hostheader, so the server's redirect is well-formed.Diff
Test plan
http://sdx.genexus.com/agetqrcode.aspx?testfrom a proc usingHttpClientand verify the wire log showsHost: sdx.genexus.com(no:80)SSLException/ NPE on the redirecthttp://localhost:8080/...and confirm the port is still preservedIssue: 208470