Skip to content

Commit

Permalink
Update #8014
Browse files Browse the repository at this point in the history
Parse CONNECT URIs as Authority
  • Loading branch information
gregw committed May 24, 2022
1 parent 9b4f40d commit 78298f5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
5 changes: 2 additions & 3 deletions jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java
Expand Up @@ -119,7 +119,7 @@ static Immutable from(String uri)
static Immutable from(String method, String uri)
{
if (HttpMethod.CONNECT.is(method))
return new Immutable(uri);
return HttpURI.build().uri(method, uri).asImmutable();
if (uri.startsWith("/"))
return HttpURI.build().pathQuery(uri).asImmutable();
return HttpURI.from(uri);
Expand Down Expand Up @@ -947,8 +947,7 @@ public Mutable uri(String method, String uri)
if (HttpMethod.CONNECT.is(method))
{
clear();
_uri = uri;
_path = uri;
parse(State.HOST, uri);
}
else if (uri.startsWith("/"))
{
Expand Down
26 changes: 26 additions & 0 deletions jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java
Expand Up @@ -177,6 +177,32 @@ public void testParseRequestTarget()
assertThat(uri.getPath(), is("/bar"));
}

@Test
public void testCONNECT()
{
HttpURI uri;

uri = HttpURI.from("CONNECT", "host:80");
assertThat(uri.getHost(), is("host"));
assertThat(uri.getPort(), is(80));
assertThat(uri.getPath(), nullValue());

uri = HttpURI.from("CONNECT", "host");
assertThat(uri.getHost(), is("host"));
assertThat(uri.getPort(), is(-1));
assertThat(uri.getPath(), nullValue());

uri = HttpURI.from("CONNECT", "192.168.0.1:8080");
assertThat(uri.getHost(), is("192.168.0.1"));
assertThat(uri.getPort(), is(8080));
assertThat(uri.getPath(), nullValue());

uri = HttpURI.from("CONNECT", "[::1]:8080");
assertThat(uri.getHost(), is("[::1]"));
assertThat(uri.getPort(), is(8080));
assertThat(uri.getPath(), nullValue());
}

@Test
public void testAt()
{
Expand Down
Expand Up @@ -33,8 +33,6 @@
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpHeaderValue;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint;
Expand Down Expand Up @@ -193,12 +191,7 @@ public void handle(String target, Request jettyRequest, HttpServletRequest reque
String tunnelProtocol = jettyRequest.getMetaData().getProtocol();
if (HttpMethod.CONNECT.is(request.getMethod()) && tunnelProtocol == null)
{
String serverAddress = target;
if (HttpVersion.HTTP_2.is(request.getProtocol()))
{
HttpURI httpURI = jettyRequest.getHttpURI();
serverAddress = httpURI.getHost() + ":" + httpURI.getPort();
}
String serverAddress = jettyRequest.getHttpURI().getAuthority();
if (LOG.isDebugEnabled())
LOG.debug("CONNECT request for {}", serverAddress);
handleConnect(jettyRequest, request, response, serverAddress);
Expand Down
Expand Up @@ -1750,6 +1750,7 @@ public void setMetaData(MetaData.Request request)
if (field instanceof HostPortHttpField)
{
HostPortHttpField authority = (HostPortHttpField)field;

builder.host(authority.getHost()).port(authority.getPort());
}
else
Expand Down

0 comments on commit 78298f5

Please sign in to comment.