|
55 | 55 | import org.eclipse.jetty.http.BadMessageException;
|
56 | 56 | import org.eclipse.jetty.http.HttpCompliance;
|
57 | 57 | import org.eclipse.jetty.http.HttpComplianceSection;
|
| 58 | +import org.eclipse.jetty.http.HttpStatus; |
58 | 59 | import org.eclipse.jetty.http.HttpTester;
|
59 | 60 | import org.eclipse.jetty.http.MimeTypes;
|
60 | 61 | import org.eclipse.jetty.io.Connection;
|
|
83 | 84 | import static org.hamcrest.Matchers.containsString;
|
84 | 85 | import static org.hamcrest.Matchers.is;
|
85 | 86 | import static org.hamcrest.Matchers.not;
|
| 87 | +import static org.hamcrest.Matchers.nullValue; |
86 | 88 | import static org.hamcrest.Matchers.startsWith;
|
87 | 89 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
88 | 90 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
@@ -872,6 +874,52 @@ public boolean check(HttpServletRequest request, HttpServletResponse response)
|
872 | 874 | assertEquals(" x=z; ", results.get(i++));
|
873 | 875 | }
|
874 | 876 |
|
| 877 | + @Test |
| 878 | + public void testConnectRequestURLSameAsHost() throws Exception |
| 879 | + { |
| 880 | + final AtomicReference<String> resultRequestURL = new AtomicReference<>(); |
| 881 | + final AtomicReference<String> resultRequestURI = new AtomicReference<>(); |
| 882 | + _handler._checker = (request, response) -> |
| 883 | + { |
| 884 | + resultRequestURL.set(request.getRequestURL().toString()); |
| 885 | + resultRequestURI.set(request.getRequestURI()); |
| 886 | + return true; |
| 887 | + }; |
| 888 | + |
| 889 | + String rawResponse = _connector.getResponse( |
| 890 | + "CONNECT myhost:9999 HTTP/1.1\n" + |
| 891 | + "Host: myhost:9999\n" + |
| 892 | + "Connection: close\n" + |
| 893 | + "\n"); |
| 894 | + HttpTester.Response response = HttpTester.parseResponse(rawResponse); |
| 895 | + assertThat(response.getStatus(), is(HttpStatus.OK_200)); |
| 896 | + assertThat("request.getRequestURL", resultRequestURL.get(), is("http://myhost:9999")); |
| 897 | + assertThat("request.getRequestURI", resultRequestURI.get(), is(nullValue())); |
| 898 | + } |
| 899 | + |
| 900 | + @Test |
| 901 | + public void testConnectRequestURLDifferentThanHost() throws Exception |
| 902 | + { |
| 903 | + final AtomicReference<String> resultRequestURL = new AtomicReference<>(); |
| 904 | + final AtomicReference<String> resultRequestURI = new AtomicReference<>(); |
| 905 | + _handler._checker = (request, response) -> |
| 906 | + { |
| 907 | + resultRequestURL.set(request.getRequestURL().toString()); |
| 908 | + resultRequestURI.set(request.getRequestURI()); |
| 909 | + return true; |
| 910 | + }; |
| 911 | + |
| 912 | + String rawResponse = _connector.getResponse( |
| 913 | + "CONNECT myhost:9999 HTTP/1.1\n" + |
| 914 | + "Host: otherhost:8888\n" + // per spec, this is ignored if request-target is authority-form |
| 915 | + "Connection: close\n" + |
| 916 | + "\n"); |
| 917 | + HttpTester.Response response = HttpTester.parseResponse(rawResponse); |
| 918 | + assertThat(response.getStatus(), is(HttpStatus.OK_200)); |
| 919 | + assertThat("request.getRequestURL", resultRequestURL.get(), is("http://myhost:9999")); |
| 920 | + assertThat("request.getRequestURI", resultRequestURI.get(), is(nullValue())); |
| 921 | + } |
| 922 | + |
875 | 923 | @Test
|
876 | 924 | public void testHostPort() throws Exception
|
877 | 925 | {
|
|
0 commit comments