-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Issue #7250 - Correct HostHeaderCustomizer
logic and add new RejectMissingAuthorityCustomizer
#7292
Conversation
+ Fixes HostHeaderCustomizer to only do Host header on non-HTTP/1.1 + Introduces RejectMissingAuthorityCustomizer + Adds modules + xml for both Signed-off-by: Joakim Erdfelt <[email protected]>
HostHeaderCustomizer
logic and add new RejectMissingAuthorityCustomizer
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.
just a couple of optimizations
String hostHeaderValue = request.getHeader("Host"); | ||
|
||
// No Host Header | ||
if (request.getHttpVersion().getVersion() != HttpVersion.HTTP_1_1.getVersion() && | ||
hostHeaderValue == null) | ||
{ | ||
if (request.getHttpURI().isAbsolute()) | ||
{ | ||
request.getHttpFields().put(HttpHeader.HOST, request.getHttpURI().getAuthority()); | ||
} | ||
else | ||
{ | ||
request.getHttpFields().put(HttpHeader.HOST, hostValue); | ||
} | ||
} |
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.
Since getHeader is a linear lookup, it is best to avoid doing it if possible, and then to use efficient non string lookup:
String hostHeaderValue = request.getHeader("Host"); | |
// No Host Header | |
if (request.getHttpVersion().getVersion() != HttpVersion.HTTP_1_1.getVersion() && | |
hostHeaderValue == null) | |
{ | |
if (request.getHttpURI().isAbsolute()) | |
{ | |
request.getHttpFields().put(HttpHeader.HOST, request.getHttpURI().getAuthority()); | |
} | |
else | |
{ | |
request.getHttpFields().put(HttpHeader.HOST, hostValue); | |
} | |
} | |
// If not 1.1 and no Host Header | |
if (request.getHttpVersion().getVersion() != HttpVersion.HTTP_1_1.getVersion() && | |
!request.getHttpFields().contains(HttpHeader.HOST)) | |
{ | |
if (request.getHttpURI().isAbsolute()) | |
{ | |
request.getHttpFields().put(HttpHeader.HOST, request.getHttpURI().getAuthority()); | |
} | |
else | |
{ | |
request.getHttpFields().put(HttpHeader.HOST, hostValue); | |
} | |
} |
if (host != null) | ||
{ | ||
if (!(host instanceof HostPortHttpField) && StringUtil.isNotBlank(host.getValue())) | ||
{ | ||
return true; | ||
} | ||
|
||
if (host instanceof HostPortHttpField) | ||
{ | ||
HostPortHttpField authority = (HostPortHttpField)host; | ||
metadata.getURI().setAuthority(authority.getHost(), authority.getPort()); | ||
if (StringUtil.isNotBlank(authority.getHost())) | ||
return true; | ||
} | ||
} | ||
} |
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 think this way reduces the number of tests in the hot path:
if (host != null) | |
{ | |
if (!(host instanceof HostPortHttpField) && StringUtil.isNotBlank(host.getValue())) | |
{ | |
return true; | |
} | |
if (host instanceof HostPortHttpField) | |
{ | |
HostPortHttpField authority = (HostPortHttpField)host; | |
metadata.getURI().setAuthority(authority.getHost(), authority.getPort()); | |
if (StringUtil.isNotBlank(authority.getHost())) | |
return true; | |
} | |
} | |
} | |
if (host != null) | |
if (host instanceof HostPortHttpField) | |
{ | |
HostPortHttpField authority = (HostPortHttpField)host; | |
metadata.getURI().setAuthority(authority.getHost(), authority.getPort()); | |
if (StringUtil.isNotBlank(authority.getHost())) | |
return true; | |
} | |
else if (host != null && StringUtil.isNotBlank(host.getValue())) | |
{ | |
return true; | |
} | |
} |
@gregw would this be good for |
@gregw bump do you want to see this for |
Note keen on any changes to behaviour in jetty-9. Does the sponsor still require this? |
Nope. |
This is a minimal version of the draft PR #7251
header on non-HTTP/1.1
Signed-off-by: Joakim Erdfelt [email protected]