Skip to content

Commit bb65db4

Browse files
jbescosjansupol
authored andcommitted
Exception in Jersey Jetty handler's Host header parsing bubbles up to the top #5189
Signed-off-by: Jorge Bescos Gascon <[email protected]>
1 parent 20f085e commit bb65db4

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

containers/jetty-http/src/main/java/org/glassfish/jersey/jetty/JettyHttpContainer.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,9 @@ public String getAuthenticationScheme() {
238238
}
239239

240240

241-
private URI getBaseUri(final Request request) {
242-
try {
243-
return new URI(request.getScheme(), null, request.getServerName(),
244-
request.getServerPort(), getBasePath(request), null, null);
245-
} catch (final URISyntaxException ex) {
246-
throw new IllegalArgumentException(ex);
247-
}
241+
private URI getBaseUri(final Request request) throws URISyntaxException {
242+
return new URI(request.getScheme(), null, request.getServerName(),
243+
request.getServerPort(), getBasePath(request), null, null);
248244
}
249245

250246
private String getBasePath(final Request request) {

containers/jetty-http/src/test/java/org/glassfish/jersey/jetty/ExceptionTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ public void test400StatusCodeForIllegalSymbolsInURI() throws IOException {
6565
assertEquals(400, response.getStatusLine().getStatusCode());
6666
}
6767

68+
@Test
69+
public void test400StatusCodeForIllegalHeaderValue() throws IOException {
70+
startServer(ExceptionResource.class);
71+
URI testUri = getUri().build();
72+
BasicHttpRequest request = new BasicHttpRequest("GET", testUri.toString() + "/400");
73+
request.addHeader("X-Forwarded-Host", "_foo.com");
74+
CloseableHttpClient client = HttpClientBuilder.create().build();
75+
76+
CloseableHttpResponse response = client.execute(new HttpHost(testUri.getHost(), testUri.getPort()), request);
77+
78+
assertEquals(400, response.getStatusLine().getStatusCode());
79+
}
80+
6881
@Test
6982
public void test400StatusCode() throws IOException {
7083
startServer(ExceptionResource.class);

0 commit comments

Comments
 (0)