Skip to content

Commit

Permalink
Fix null host when checking virtual host #10922
Browse files Browse the repository at this point in the history
Use the `Request.getServerName` static and check for null host.
  • Loading branch information
gregw committed Nov 27, 2023
1 parent 7dcab84 commit a35b0a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ public boolean checkVirtualHost(Request request)
if (_vhosts.isEmpty())
return true;

String host = normalizeHostname(request.getHttpURI().getHost());
String host = Request.getServerName(request);
String connectorName = request.getConnectionMetaData().getConnector().getName();

for (VHost vhost : _vhosts)
Expand All @@ -733,21 +733,17 @@ public boolean checkVirtualHost(Request request)
continue;

if (contextVhost == null)
{
return true;
}
}

if (contextVhost != null)
if (contextVhost != null && host != null)
{
if (vhost._wild)
{
// wildcard only at the beginning, and only for one additional subdomain level
int index = host.indexOf(".");
if (index >= 0 && host.substring(index).equalsIgnoreCase(contextVhost))
{
return true;
}
}
else if (host.equalsIgnoreCase(contextVhost))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@ public String getName()
HttpFields fields = HttpFields.build().asImmutable();

MockHttpStream stream = new MockHttpStream(channel);
channel.onRequest(new MetaData.Request("GET", HttpURI.from("/ctx/"), HttpVersion.HTTP_1_0, fields, 0)).run();
assertThat(stream.isComplete(), is(true));
assertThat(stream.getResponse().getStatus(), equalTo(404));

stream = new MockHttpStream(channel);
channel.onRequest(new MetaData.Request("GET", HttpURI.from("http://localhost/ctx/"), HttpVersion.HTTP_1_1, fields, 0)).run();
assertThat(stream.isComplete(), is(true));
assertThat(stream.getResponse().getStatus(), equalTo(404));
Expand Down

0 comments on commit a35b0a2

Please sign in to comment.