|
32 | 32 | import jakarta.servlet.http.HttpServletResponse;
|
33 | 33 | import org.eclipse.jetty.http.ComplianceViolation;
|
34 | 34 | import org.eclipse.jetty.http.HttpCompliance;
|
| 35 | +import org.eclipse.jetty.http.UriCompliance; |
35 | 36 | import org.eclipse.jetty.server.HttpConfiguration;
|
36 | 37 | import org.eclipse.jetty.server.HttpConnectionFactory;
|
37 | 38 | import org.eclipse.jetty.server.LocalConnector;
|
@@ -87,8 +88,8 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
|
87 | 88 | {
|
88 | 89 | resp.setContentType("text/plain");
|
89 | 90 | PrintWriter out = resp.getWriter();
|
90 |
| - List<String> headerNames = new ArrayList<>(); |
91 |
| - headerNames.addAll(Collections.list(req.getHeaderNames())); |
| 91 | + out.printf("%s %s%s%s\n", req.getMethod(), req.getContextPath(), req.getServletPath(), req.getPathInfo()); |
| 92 | + List<String> headerNames = new ArrayList<>(Collections.list(req.getHeaderNames())); |
92 | 93 | Collections.sort(headerNames);
|
93 | 94 | for (String name : headerNames)
|
94 | 95 | {
|
@@ -183,4 +184,25 @@ public void testFoldedHeader() throws Exception
|
183 | 184 | assertThat("Response headers", response, containsString("X-Http-Violation-0: Line Folding not supported"));
|
184 | 185 | assertThat("Response body", response, containsString("[Name] = [Some Value]"));
|
185 | 186 | }
|
| 187 | + |
| 188 | + @Test |
| 189 | + public void testAmbiguousSlash() throws Exception |
| 190 | + { |
| 191 | + String request = """ |
| 192 | + GET /dump/foo//bar HTTP/1.1\r |
| 193 | + Host: local\r |
| 194 | + Connection: close\r |
| 195 | + \r |
| 196 | + """; |
| 197 | + |
| 198 | + String response = connector.getResponse(request); |
| 199 | + assertThat(response, containsString("HTTP/1.1 400 Bad")); |
| 200 | + |
| 201 | + connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setUriCompliance(UriCompliance.RFC3986.with("test", UriCompliance.Violation.AMBIGUOUS_EMPTY_SEGMENT)); |
| 202 | + server.getContainedBeans(ServletHandler.class).stream().findFirst().get().setDecodeAmbiguousURIs(true); |
| 203 | + |
| 204 | + response = connector.getResponse(request); |
| 205 | + assertThat(response, containsString("HTTP/1.1 200 OK")); |
| 206 | + assertThat(response, containsString("GET /dump/foo//bar")); |
| 207 | + } |
186 | 208 | }
|
0 commit comments