Merge remote-tracking branch 'origin/jetty-12.0.x' into fix/12.0.x/hostheadercustomizer

This commit is contained in:
Joakim Erdfelt 2023-05-01 11:21:24 -05:00
commit d10d54042a
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
16 changed files with 70 additions and 89 deletions

View File

@ -43,7 +43,6 @@ import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.component.LifeCycle;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -69,7 +68,6 @@ public class BadURITest
}
@Test
@Disabled("TODO: need to fix ErrorHandler")
public void testBadURI() throws Exception
{
CountDownLatch handlerLatch = new CountDownLatch(1);

View File

@ -52,7 +52,6 @@ import org.eclipse.jetty.util.Utf8StringBuilder;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
@ -94,9 +93,7 @@ public class HTTP2CServerTest extends AbstractServerTest
}
}
// TODO: this test fails on IO.toString(), for some reason the second request does not close the connection.
@Test
@Disabled
public void testHTTP11Simple() throws Exception
{
try (Socket client = new Socket("localhost", connector.getLocalPort()))

View File

@ -78,7 +78,6 @@ import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@ -736,7 +735,6 @@ public class HttpClientTransportOverHTTP2Test extends AbstractTest
});
}
@Disabled
@Test
@Tag("external")
public void testExternalServer() throws Exception
@ -750,9 +748,7 @@ public class HttpClientTransportOverHTTP2Test extends AbstractTest
clientConnector.setExecutor(executor);
httpClient.start();
// ContentResponse response = httpClient.GET("https://http2.akamai.com/");
ContentResponse response = httpClient.GET("https://webtide.com/");
assertEquals(HttpStatus.OK_200, response.getStatus());
httpClient.stop();

View File

@ -81,7 +81,6 @@ import org.eclipse.jetty.util.FuturePromise;
import org.eclipse.jetty.util.NanoTime;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.awaitility.Awaitility.await;
@ -334,13 +333,7 @@ public class StreamResetTest extends AbstractTest
assertTrue(dataLatch.await(5, TimeUnit.SECONDS));
}
// TODO: This test writes after a failure and highlights some problem in the implementation
// of the handling of errors. For example, the request._error field is set by the failure,
// but checked during the succeed of the callback (so cannot turn a failure into a success)
// and also highlights that the implementation should be more precise at severing the link
// between channel and request, possibly where the request only has one field, the channel.
@Test
@Disabled
public void testAsyncWriteAfterStreamReceivingReset() throws Exception
{
CountDownLatch commitLatch = new CountDownLatch(1);

View File

@ -31,15 +31,20 @@ import org.eclipse.jetty.http3.client.HTTP3Client;
import org.eclipse.jetty.http3.client.transport.HttpClientTransportOverHTTP3;
import org.eclipse.jetty.http3.frames.HeadersFrame;
import org.eclipse.jetty.util.HostPort;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Disabled
@Tag("external")
public class ExternalServerTest
{
private static final Logger LOG = LoggerFactory.getLogger(ExternalServerTest.class);
@Test
@Tag("external")
public void testExternalServerWithHttpClient() throws Exception
@ -52,8 +57,7 @@ public class ExternalServerTest
{
URI uri = URI.create("https://maven-central-eu.storage-download.googleapis.com/maven2/org/apache/maven/maven-parent/38/maven-parent-38.pom");
ContentResponse response = httpClient.newRequest(uri).send();
System.err.println("response = " + response);
System.err.println(response.getContentAsString());
assertThat(response.getContentAsString(), containsString("<artifactId>maven-parent</artifactId>"));
}
finally
{
@ -69,11 +73,7 @@ public class ExternalServerTest
client.start();
try
{
HostPort hostPort = new HostPort("google.com:443");
// HostPort hostPort = new HostPort("nghttp2.org:4433");
// HostPort hostPort = new HostPort("quic.tech:8443");
// HostPort hostPort = new HostPort("h2o.examp1e.net:443");
// HostPort hostPort = new HostPort("test.privateoctopus.com:4433");
HostPort hostPort = new HostPort("maven-central-eu.storage-download.googleapis.com:443");
Session.Client session = client.connect(new InetSocketAddress(hostPort.getHost(), hostPort.getPort()), new Session.Client.Listener() {})
.get(5, TimeUnit.SECONDS);
@ -85,7 +85,8 @@ public class ExternalServerTest
@Override
public void onResponse(Stream.Client stream, HeadersFrame frame)
{
System.err.println("RESPONSE HEADER = " + frame);
if (LOG.isDebugEnabled())
LOG.debug("RESPONSE HEADER = {}", frame);
if (frame.isLast())
{
requestLatch.countDown();
@ -98,7 +99,8 @@ public class ExternalServerTest
public void onDataAvailable(Stream.Client stream)
{
Stream.Data data = stream.readData();
System.err.println("RESPONSE DATA = " + data);
if (LOG.isDebugEnabled())
LOG.debug("RESPONSE DATA = {}", data);
if (data != null)
{
data.release();
@ -114,7 +116,8 @@ public class ExternalServerTest
@Override
public void onTrailer(Stream.Client stream, HeadersFrame frame)
{
System.err.println("RESPONSE TRAILER = " + frame);
if (LOG.isDebugEnabled())
LOG.debug("RESPONSE TRAILER = {}", frame);
requestLatch.countDown();
}
});

View File

@ -153,6 +153,7 @@ public class ErrorHandlerTest
assertThat("Response status code", response.getStatus(), is(404));
assertThat("Response Content-Length", response.getField(HttpHeader.CONTENT_LENGTH).getIntValue(), greaterThan(0));
assertThat("Response Content-Type", response.get(HttpHeader.CONTENT_TYPE), containsString("text/html;charset=ISO-8859-1"));
assertThat(response.get(HttpHeader.DATE), notNullValue());
assertThat(response.getContent(), containsString("content=\"text/html;charset=ISO-8859-1\""));
assertContent(response);

View File

@ -24,12 +24,10 @@ import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.Content;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.IO;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@Disabled // TODO
public class HalfCloseTest
{
@Test

View File

@ -227,7 +227,12 @@ public class ServletApiResponse implements HttpServletResponse
}
}
}
default -> _response.getState().sendError(sc, msg);
default ->
{
if (isCommitted())
throw new IllegalStateException("Committed");
_response.getState().sendError(sc, msg);
}
}
}

View File

@ -379,7 +379,6 @@ public class ServletContextResponse extends ContextResponse
case CACHE_CONTROL:
case LAST_MODIFIED:
case EXPIRES:
case DATE:
case VARY:
i.remove();
continue;

View File

@ -59,6 +59,7 @@ 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.hamcrest.Matchers.notNullValue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -156,6 +157,7 @@ public class ErrorPageTest
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
assertThat(response.getStatus(), is(595));
assertThat(response.get(HttpHeader.DATE), notNullValue());
String actualContentType = response.get(HttpHeader.CONTENT_TYPE);
// should not expect to see charset line from servlet
assertThat(actualContentType, not(containsString("charset=US-ASCII")));

View File

@ -16,7 +16,6 @@ package org.eclipse.jetty.ee10.websocket.jakarta.client;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
@ -169,10 +168,12 @@ public class JakartaWebSocketClientContainer extends JakartaWebSocketContainer i
return error;
}
private Session connect(ConfiguredEndpoint configuredEndpoint, URI destURI) throws IOException
private Session connect(ConfiguredEndpoint configuredEndpoint, URI destURI) throws IOException, DeploymentException
{
Objects.requireNonNull(configuredEndpoint, "WebSocket configured endpoint cannot be null");
Objects.requireNonNull(destURI, "Destination URI cannot be null");
if (configuredEndpoint == null)
throw new DeploymentException("WebSocket configured endpoint cannot be null");
if (destURI == null)
throw new DeploymentException("Destination URI cannot be null");
JakartaClientUpgradeRequest upgradeRequest = new JakartaClientUpgradeRequest(this, getWebSocketCoreClient(), destURI, configuredEndpoint);
@ -202,8 +203,8 @@ public class JakartaWebSocketClientContainer extends JakartaWebSocketContainer i
catch (ExecutionException e)
{
var cause = e.getCause();
if (cause instanceof RuntimeException)
throw (RuntimeException)cause;
if (cause instanceof DeploymentException)
throw (DeploymentException)cause;
if (cause instanceof IOException)
throw (IOException)cause;
throw new IOException(cause);
@ -286,7 +287,6 @@ public class JakartaWebSocketClientContainer extends JakartaWebSocketContainer i
ClientEndpoint anno = endpoint.getClass().getAnnotation(ClientEndpoint.class);
if (anno == null)
throw new DeploymentException("Could not get ClientEndpoint annotation for " + endpoint.getClass().getName());
return new AnnotatedClientEndpointConfig(anno, components);
}

View File

@ -18,29 +18,17 @@ import java.util.List;
import jakarta.websocket.ClientEndpoint;
import jakarta.websocket.ClientEndpointConfig;
import jakarta.websocket.DeploymentException;
import org.eclipse.jetty.ee10.websocket.jakarta.common.ClientEndpointConfigWrapper;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.exception.InvalidWebSocketException;
public class AnnotatedClientEndpointConfig extends ClientEndpointConfigWrapper
{
public AnnotatedClientEndpointConfig(ClientEndpoint anno, WebSocketComponents components)
public AnnotatedClientEndpointConfig(ClientEndpoint anno, WebSocketComponents components) throws DeploymentException
{
Configurator configurator;
try
{
configurator = components.getObjectFactory().createInstance(anno.configurator());
}
catch (Exception e)
{
StringBuilder err = new StringBuilder();
err.append("Unable to instantiate ClientEndpoint.configurator() of ");
err.append(anno.configurator().getName());
err.append(" defined as annotation in ");
err.append(anno.getClass().getName());
throw new InvalidWebSocketException(err.toString(), e);
}
Configurator configurator = components.getObjectFactory().createInstance(anno.configurator());
ClientEndpointConfig build = Builder.create()
.encoders(List.of(anno.encoders()))
.decoders(List.of(anno.decoders()))
@ -48,7 +36,13 @@ public class AnnotatedClientEndpointConfig extends ClientEndpointConfigWrapper
.extensions(Collections.emptyList())
.configurator(configurator)
.build();
init(build);
}
catch (Throwable t)
{
String err = "Unable to instantiate ClientEndpoint.configurator() of " + anno.configurator().getName() +
" defined as annotation in " + anno.getClass().getName();
throw new DeploymentException(err, t);
}
}
}

View File

@ -1217,7 +1217,6 @@ public class Response implements HttpServletResponse
case LAST_MODIFIED:
case EXPIRES:
case ETAG:
case DATE:
case VARY:
i.remove();
continue;

View File

@ -2052,6 +2052,7 @@ public class ResponseTest
response.setContentType("some/type");
response.setContentLength(3);
response.setHeader(HttpHeader.EXPIRES, "never");
response.setHeader(HttpHeader.DATE, "2000-01-01");
response.setHeader("SomeHeader", "SomeValue");
@ -2068,6 +2069,7 @@ public class ResponseTest
// check arbitrary header still set
assertThat(response.getHeader("SomeHeader"), is("SomeValue"));
assertThat(response.getHeader("Date"), is("2000-01-01"));
// check cookies are still there
Enumeration<String> set = response.getHttpFields().getValues("Set-Cookie");

View File

@ -16,7 +16,6 @@ package org.eclipse.jetty.ee9.websocket.jakarta.client;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
@ -169,10 +168,12 @@ public class JakartaWebSocketClientContainer extends JakartaWebSocketContainer i
return error;
}
private Session connect(ConfiguredEndpoint configuredEndpoint, URI destURI) throws IOException
private Session connect(ConfiguredEndpoint configuredEndpoint, URI destURI) throws IOException, DeploymentException
{
Objects.requireNonNull(configuredEndpoint, "WebSocket configured endpoint cannot be null");
Objects.requireNonNull(destURI, "Destination URI cannot be null");
if (configuredEndpoint == null)
throw new DeploymentException("WebSocket configured endpoint cannot be null");
if (destURI == null)
throw new DeploymentException("Destination URI cannot be null");
JakartaClientUpgradeRequest upgradeRequest = new JakartaClientUpgradeRequest(this, getWebSocketCoreClient(), destURI, configuredEndpoint);
@ -202,8 +203,8 @@ public class JakartaWebSocketClientContainer extends JakartaWebSocketContainer i
catch (ExecutionException e)
{
var cause = e.getCause();
if (cause instanceof RuntimeException)
throw (RuntimeException)cause;
if (cause instanceof DeploymentException)
throw (DeploymentException)cause;
if (cause instanceof IOException)
throw (IOException)cause;
throw new IOException(cause);
@ -286,7 +287,6 @@ public class JakartaWebSocketClientContainer extends JakartaWebSocketContainer i
ClientEndpoint anno = endpoint.getClass().getAnnotation(ClientEndpoint.class);
if (anno == null)
throw new DeploymentException("Could not get ClientEndpoint annotation for " + endpoint.getClass().getName());
return new AnnotatedClientEndpointConfig(anno, components);
}

View File

@ -18,29 +18,17 @@ import java.util.List;
import jakarta.websocket.ClientEndpoint;
import jakarta.websocket.ClientEndpointConfig;
import jakarta.websocket.DeploymentException;
import org.eclipse.jetty.ee9.websocket.jakarta.common.ClientEndpointConfigWrapper;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.exception.InvalidWebSocketException;
public class AnnotatedClientEndpointConfig extends ClientEndpointConfigWrapper
{
public AnnotatedClientEndpointConfig(ClientEndpoint anno, WebSocketComponents components)
public AnnotatedClientEndpointConfig(ClientEndpoint anno, WebSocketComponents components) throws DeploymentException
{
Configurator configurator;
try
{
configurator = components.getObjectFactory().createInstance(anno.configurator());
}
catch (Exception e)
{
StringBuilder err = new StringBuilder();
err.append("Unable to instantiate ClientEndpoint.configurator() of ");
err.append(anno.configurator().getName());
err.append(" defined as annotation in ");
err.append(anno.getClass().getName());
throw new InvalidWebSocketException(err.toString(), e);
}
Configurator configurator = components.getObjectFactory().createInstance(anno.configurator());
ClientEndpointConfig build = Builder.create()
.encoders(List.of(anno.encoders()))
.decoders(List.of(anno.decoders()))
@ -48,7 +36,13 @@ public class AnnotatedClientEndpointConfig extends ClientEndpointConfigWrapper
.extensions(Collections.emptyList())
.configurator(configurator)
.build();
init(build);
}
catch (Throwable t)
{
String err = "Unable to instantiate ClientEndpoint.configurator() of " + anno.configurator().getName() +
" defined as annotation in " + anno.getClass().getName();
throw new DeploymentException(err, t);
}
}
}