Merge branch 'jetty-11.0.x' into jetty-12.0.x

This commit is contained in:
Joakim Erdfelt 2022-09-13 10:11:40 -05:00
commit 141c58208d
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
6 changed files with 103 additions and 5 deletions

View File

@ -1291,6 +1291,12 @@ public class HttpConnection extends AbstractConnection implements Runnable, Writ
_uri.authority(hostPort.getHost(), port);
}
// Set path (if not already set)
if (_uri.getPath() == null)
{
_uri.path("/");
}
_request = new MetaData.Request(_method, _uri.asImmutable(), _version, _headerBuilder, _contentLength);
Runnable handle = _httpChannel.onRequest(_request);

View File

@ -16,6 +16,7 @@ package org.eclipse.jetty.server;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.jetty.http.HttpCookie;
import org.eclipse.jetty.http.HttpHeader;
@ -31,6 +32,7 @@ import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -88,6 +90,42 @@ public class RequestTest
assertThat(response.getContent(), containsString("pathInContext=/foo%2Fbar"));
}
@Test
public void testConnectRequestURLSameAsHost() throws Exception
{
String request = """
CONNECT myhost:9999 HTTP/1.1\r
Host: myhost:9999\r
Connection: close\r
\r
""";
HttpTester.Response response = HttpTester.parseResponse(connector.getResponse(request));
assertEquals(HttpStatus.OK_200, response.getStatus());
String responseBody = response.getContent();
assertThat(responseBody, containsString("httpURI=http://myhost:9999"));
assertThat(responseBody, containsString("httpURI.path=null"));
assertThat(responseBody, containsString("servername=myhost"));
}
@Test
public void testConnectRequestURLDifferentThanHost() throws Exception
{
// per spec, "Host" is ignored if request-target is authority-form
String request = """
CONNECT myhost:9999 HTTP/1.1\r
Host: otherhost:8888\r
Connection: close\r
\r
""";
HttpTester.Response response = HttpTester.parseResponse(connector.getResponse(request));
assertEquals(HttpStatus.OK_200, response.getStatus());
String responseBody = response.getContent();
assertThat(responseBody, containsString("httpURI=http://myhost:9999"));
assertThat(responseBody, containsString("httpURI.path=null"));
assertThat(responseBody, containsString("servername=myhost"));
}
/**
* Test that multiple requests on the same connection with different cookies
* do not bleed cookies.

View File

@ -1172,7 +1172,9 @@ public class Request implements HttpServletRequest
{
final StringBuffer url = new StringBuffer(128);
URIUtil.appendSchemeHostPort(url, getScheme(), getServerName(), getServerPort());
url.append(getRequestURI());
String path = getRequestURI();
if (path != null)
url.append(path);
return url;
}

View File

@ -58,6 +58,7 @@ import org.eclipse.jetty.http.HttpCookie;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.HttpTester;
import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.http.MetaData;
@ -781,6 +782,57 @@ public class RequestTest
assertEquals(" x=z; ", results.get(i));
}
@Test
public void testConnectRequestURLSameAsHost() throws Exception
{
final AtomicReference<String> resultRequestURL = new AtomicReference<>();
final AtomicReference<String> resultRequestURI = new AtomicReference<>();
_handler._checker = (request, response) ->
{
resultRequestURL.set(request.getRequestURL().toString());
resultRequestURI.set(request.getRequestURI());
return true;
};
String rawResponse = _connector.getResponse(
"""
CONNECT myhost:9999 HTTP/1.1\r
Host: myhost:9999\r
Connection: close\r
\r
""");
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
assertThat(response.getStatus(), is(HttpStatus.OK_200));
assertThat("request.getRequestURL", resultRequestURL.get(), is("http://myhost:9999/"));
assertThat("request.getRequestURI", resultRequestURI.get(), is("/"));
}
@Test
public void testConnectRequestURLDifferentThanHost() throws Exception
{
final AtomicReference<String> resultRequestURL = new AtomicReference<>();
final AtomicReference<String> resultRequestURI = new AtomicReference<>();
_handler._checker = (request, response) ->
{
resultRequestURL.set(request.getRequestURL().toString());
resultRequestURI.set(request.getRequestURI());
return true;
};
// per spec, "Host" is ignored if request-target is authority-form
String rawResponse = _connector.getResponse(
"""
CONNECT myhost:9999 HTTP/1.1\r
Host: otherhost:8888\r
Connection: close\r
\r
""");
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
assertThat(response.getStatus(), is(HttpStatus.OK_200));
assertThat("request.getRequestURL", resultRequestURL.get(), is("http://myhost:9999/"));
assertThat("request.getRequestURI", resultRequestURI.get(), is("/"));
}
@Test
public void testHostPort() throws Exception
{

View File

@ -12,7 +12,7 @@
<description>Generates a (maven based) P2 Updatesite</description>
<packaging>pom</packaging>
<properties>
<tycho-version>2.7.4</tycho-version>
<tycho-version>2.7.5</tycho-version>
</properties>
<build>
<plugins>

View File

@ -46,7 +46,7 @@
<guava.version>31.1-jre</guava.version>
<guice.version>5.1.0</guice.version>
<hamcrest.version>2.2</hamcrest.version>
<hawtio.version>2.15.0</hawtio.version>
<hawtio.version>2.15.1</hawtio.version>
<hazelcast.version>4.2.5</hazelcast.version>
<infinispan.protostream.version>4.4.4.Final</infinispan.protostream.version>
<infinispan.version>11.0.15.Final</infinispan.version>
@ -134,8 +134,8 @@
<maven.surefire.plugin.version>3.0.0-M7</maven.surefire.plugin.version>
<maven.source.plugin.version>3.2.1</maven.source.plugin.version>
<maven.war.plugin.version>3.3.2</maven.war.plugin.version>
<spotbugs.maven.plugin.version>4.7.1.1</spotbugs.maven.plugin.version>
<versions.maven.plugin.version>2.11.0</versions.maven.plugin.version>
<spotbugs.maven.plugin.version>4.7.2.0</spotbugs.maven.plugin.version>
<versions.maven.plugin.version>2.12.0</versions.maven.plugin.version>
<!-- testing -->
<invoker.mergeUserSettings>false</invoker.mergeUserSettings>