diff --git a/containers/jetty-http/src/main/java/org/glassfish/jersey/jetty/JettyHttpContainer.java b/containers/jetty-http/src/main/java/org/glassfish/jersey/jetty/JettyHttpContainer.java index ccc2fe7a7a..78d16058c1 100644 --- a/containers/jetty-http/src/main/java/org/glassfish/jersey/jetty/JettyHttpContainer.java +++ b/containers/jetty-http/src/main/java/org/glassfish/jersey/jetty/JettyHttpContainer.java @@ -238,13 +238,9 @@ public String getAuthenticationScheme() { } - private URI getBaseUri(final Request request) { - try { - return new URI(request.getScheme(), null, request.getServerName(), - request.getServerPort(), getBasePath(request), null, null); - } catch (final URISyntaxException ex) { - throw new IllegalArgumentException(ex); - } + private URI getBaseUri(final Request request) throws URISyntaxException { + return new URI(request.getScheme(), null, request.getServerName(), + request.getServerPort(), getBasePath(request), null, null); } private String getBasePath(final Request request) { diff --git a/containers/jetty-http/src/test/java/org/glassfish/jersey/jetty/ExceptionTest.java b/containers/jetty-http/src/test/java/org/glassfish/jersey/jetty/ExceptionTest.java index ce299cdf81..c64aa9cb69 100644 --- a/containers/jetty-http/src/test/java/org/glassfish/jersey/jetty/ExceptionTest.java +++ b/containers/jetty-http/src/test/java/org/glassfish/jersey/jetty/ExceptionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -65,6 +65,19 @@ public void test400StatusCodeForIllegalSymbolsInURI() throws IOException { assertEquals(400, response.getStatusLine().getStatusCode()); } + @Test + public void test400StatusCodeForIllegalHeaderValue() throws IOException { + startServer(ExceptionResource.class); + URI testUri = getUri().build(); + BasicHttpRequest request = new BasicHttpRequest("GET", testUri.toString() + "/400"); + request.addHeader("X-Forwarded-Host", "_foo.com"); + CloseableHttpClient client = HttpClientBuilder.create().build(); + + CloseableHttpResponse response = client.execute(new HttpHost(testUri.getHost(), testUri.getPort()), request); + + assertEquals(400, response.getStatusLine().getStatusCode()); + } + @Test public void test400StatusCode() throws IOException { startServer(ExceptionResource.class);