Skip to content

Commit

Permalink
Updates.
Browse files Browse the repository at this point in the history
* Introduced HttpScheme.isSecure(String), to avoid code duplication.
* Fixed handling of cookie "localhost" domain in HttpClient.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Feb 2, 2023
1 parent 9c8f14b commit 7a3d7e2
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,9 @@ public void putCookie(URI uri, HttpField field)
{
try
{
String value = field.getValue();
if (value != null)
{
HttpCookie cookie = cookieParser.parse(uri, field);
HttpCookie cookie = cookieParser.parse(uri, field);
if (cookie != null)
cookieStore.add(uri, cookie);
}
}
catch (IOException x)
{
Expand Down Expand Up @@ -1134,16 +1131,6 @@ public static int normalizePort(String scheme, int port)
return HttpScheme.getDefaultPort(scheme);
}

public boolean isDefaultPort(String scheme, int port)
{
return HttpScheme.getDefaultPort(scheme) == port;
}

public static boolean isSchemeSecure(String scheme)
{
return HttpScheme.HTTPS.is(scheme) || HttpScheme.WSS.is(scheme);
}

public ClientConnectionFactory newSslClientConnectionFactory(SslContextFactory.Client sslContextFactory, ClientConnectionFactory connectionFactory)
{
if (sslContextFactory == null)
Expand All @@ -1168,7 +1155,9 @@ public HttpCookie parse(URI uri, HttpField field) throws IOException
header.put(field.getHeader().asString(), List.of(value));
put(uri, header);
Store store = (Store)getCookieStore();
return store.cookie;
HttpCookie cookie = store.cookie;
store.cookie = null;
return cookie;
}

private static class Store implements CookieStore
Expand All @@ -1178,6 +1167,9 @@ private static class Store implements CookieStore
@Override
public void add(URI uri, java.net.HttpCookie cookie)
{
String domain = cookie.getDomain();
if ("localhost.local".equals(domain))
cookie.setDomain("localhost");
this.cookie = HttpCookie.from(cookie);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.io.CyclicTimeouts;
import org.eclipse.jetty.util.Attachable;
Expand Down Expand Up @@ -155,13 +156,17 @@ protected void normalizeRequest(HttpRequest request)
}

ProxyConfiguration.Proxy proxy = destination.getProxy();
if (proxy instanceof HttpProxy && !HttpClient.isSchemeSecure(request.getScheme()))
if (proxy instanceof HttpProxy)
{
URI uri = request.getURI();
if (uri != null)
String scheme = request.getScheme();
if (!HttpScheme.isSecure(scheme))
{
path = uri.toString();
request.path(path);
URI uri = request.getURI();
if (uri != null)
{
path = uri.toString();
request.path(path);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.eclipse.jetty.client.Response;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.io.ClientConnectionFactory;
import org.eclipse.jetty.io.CyclicTimeouts;
import org.eclipse.jetty.util.BlockingArrayQueue;
Expand Down Expand Up @@ -84,7 +85,9 @@ public HttpDestination(HttpClient client, Origin origin, boolean intrinsicallySe
this.requestTimeouts = new RequestTimeouts(client.getScheduler());

String host = HostPort.normalizeHost(getHost());
if (!client.isDefaultPort(getScheme(), getPort()))
String scheme = getScheme();
int port = getPort();
if (port != HttpScheme.getDefaultPort(scheme))
host += ":" + getPort();
hostField = new HttpField(HttpHeader.HOST, host);

Expand Down Expand Up @@ -199,7 +202,8 @@ private ClientConnectionFactory newSslClientConnectionFactory(SslContextFactory.
@Override
public boolean isSecure()
{
return HttpClient.isSchemeSecure(getScheme());
String scheme = getScheme();
return HttpScheme.isSecure(scheme);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
import org.eclipse.jetty.alpn.client.ALPNClientConnectionFactory;
import org.eclipse.jetty.client.AbstractConnectorHttpClientTransport;
import org.eclipse.jetty.client.Destination;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.HttpClientTransport;
import org.eclipse.jetty.client.MultiplexConnectionPool;
import org.eclipse.jetty.client.Origin;
import org.eclipse.jetty.client.Request;
import org.eclipse.jetty.client.internal.HttpDestination;
import org.eclipse.jetty.client.internal.HttpRequest;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.io.ClientConnectionFactory;
import org.eclipse.jetty.io.ClientConnector;
Expand Down Expand Up @@ -132,7 +132,8 @@ private static ClientConnector findClientConnector(ClientConnectionFactory.Info[
@Override
public Origin newOrigin(Request request)
{
boolean secure = HttpClient.isSchemeSecure(request.getScheme());
String scheme = request.getScheme();
boolean secure = HttpScheme.isSecure(scheme);
String http1 = "http/1.1";
String http2 = secure ? "h2" : "h2c";
List<String> protocols = List.of();
Expand Down
Loading

0 comments on commit 7a3d7e2

Please sign in to comment.