Skip to content

Commit

Permalink
Change the precedence between :authority and Host headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek committed Oct 30, 2023
1 parent 96d59d5 commit f90cda3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ public void extract(AddressPortSink sink, REQUEST request) {
}
}

// try Host
for (String host : getter.getHttpRequestHeader(request, "host")) {
// try :authority (HTTP 2.0 pseudo-header)
for (String host : getter.getHttpRequestHeader(request, ":authority")) {
if (extractHost(sink, host, 0, host.length())) {
return;
}
}

// try :authority (HTTP 2.0 pseudo-header)
for (String host : getter.getHttpRequestHeader(request, ":authority")) {
// try Host
for (String host : getter.getHttpRequestHeader(request, "host")) {
if (extractHost(sink, host, 0, host.length())) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ void shouldParseForwardedHost(

@ParameterizedTest
@ArgumentsSource(HostArgs.class)
void shouldParseHost(
void shouldParsePseudoAuthority(
List<String> headers, @Nullable String expectedAddress, @Nullable Integer expectedPort) {
doReturn(emptyList()).when(getter).getHttpRequestHeader(REQUEST, "forwarded");
doReturn(emptyList()).when(getter).getHttpRequestHeader(REQUEST, "x-forwarded-host");
doReturn(headers).when(getter).getHttpRequestHeader(REQUEST, "host");
doReturn(headers).when(getter).getHttpRequestHeader(REQUEST, ":authority");

AddressAndPort sink = new AddressAndPort();
underTest.extract(sink, REQUEST);
Expand All @@ -111,12 +111,12 @@ void shouldParseHost(

@ParameterizedTest
@ArgumentsSource(HostArgs.class)
void shouldParsePseudoAuthority(
void shouldParseHost(
List<String> headers, @Nullable String expectedAddress, @Nullable Integer expectedPort) {
doReturn(emptyList()).when(getter).getHttpRequestHeader(REQUEST, "forwarded");
doReturn(emptyList()).when(getter).getHttpRequestHeader(REQUEST, "x-forwarded-host");
doReturn(emptyList()).when(getter).getHttpRequestHeader(REQUEST, "host");
doReturn(headers).when(getter).getHttpRequestHeader(REQUEST, ":authority");
doReturn(emptyList()).when(getter).getHttpRequestHeader(REQUEST, ":authority");
doReturn(headers).when(getter).getHttpRequestHeader(REQUEST, "host");

AddressAndPort sink = new AddressAndPort();
underTest.extract(sink, REQUEST);
Expand Down

0 comments on commit f90cda3

Please sign in to comment.