use of org.eclipse.jetty.server.LocalConnector.LocalEndPoint in project jetty.project by eclipse.
the class PartialRFC2616Test method test3_6_c.
@Test
public void test3_6_c() throws Exception {
String response;
int offset = 0;
LocalEndPoint endp = connector.executeRequest("POST /R1 HTTP/1.1\n" + "Host: localhost\n" + "Transfer-Encoding: chunked\n" + "Content-Type: text/plain\n" + "\n" + "3;\n" + "fgh\n" + "3;\n" + "Ijk\n" + "0;\n\n" + "POST /R2 HTTP/1.1\n" + "Host: localhost\n" + "Transfer-Encoding: chunked\n" + "Content-Type: text/plain\n" + "\n" + "4;\n" + "lmno\n" + "5;\n" + "Pqrst\n" + "0;\n\n" + "GET /R3 HTTP/1.1\n" + "Host: localhost\n" + "Connection: close\n" + "\n");
offset = 0;
response = endp.getResponse();
checkNotContained(response, "HTTP/1.1 100", "3.6.1 Chunking");
offset = checkContains(response, offset, "HTTP/1.1 200", "3.6.1 Chunking");
offset = checkContains(response, offset, "fghIjk", "3.6.1 Chunking");
offset = 0;
response = endp.getResponse();
checkNotContained(response, "HTTP/1.1 100", "3.6.1 Chunking");
offset = checkContains(response, offset, "HTTP/1.1 200", "3.6.1 Chunking");
offset = checkContains(response, offset, "lmnoPqrst", "3.6.1 Chunking");
offset = 0;
response = endp.getResponse();
checkNotContained(response, "HTTP/1.1 100", "3.6.1 Chunking");
offset = checkContains(response, offset, "/R3", "3.6.1 Chunking");
}
use of org.eclipse.jetty.server.LocalConnector.LocalEndPoint in project jetty.project by eclipse.
the class LocalConnectorTest method testExpectContinues.
@Test
public void testExpectContinues() throws Exception {
LocalEndPoint endp = _connector.executeRequest("GET /R1 HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: text/plain; charset=UTF-8\r\n" + "Expect: 100-Continue\r\n" + "Content-Length: 10\r\n" + "\r\n");
String response = endp.getResponse();
assertThat(response, containsString("HTTP/1.1 100 Continue"));
endp.addInput("01234567890\r\n");
response = endp.getResponse();
assertThat(response, containsString("HTTP/1.1 200 OK"));
assertThat(response, containsString("pathInfo=/R1"));
assertThat(response, containsString("0123456789"));
}
use of org.eclipse.jetty.server.LocalConnector.LocalEndPoint in project jetty.project by eclipse.
the class PartialRFC2616Test method test4_4_3.
@Test
public void test4_4_3() throws Exception {
// _content length is ignored, as chunking is used. If it is
// not ignored, the second request wont be seen.
int offset = 0;
String response;
LocalEndPoint endp = connector.executeRequest("GET /R1 HTTP/1.1\n" + "Host: localhost\n" + "Transfer-Encoding: chunked\n" + "Content-Type: text/plain\n" + "Content-Length: 100\n" + "\n" + "3;\n" + "123\n" + "3;\n" + "456\n" + "0;\n" + "\n" + "GET /R2 HTTP/1.1\n" + "Host: localhost\n" + "Connection: close\n" + "Content-Type: text/plain\n" + "Content-Length: 6\n" + "\n" + "abcdef");
offset = 0;
response = endp.getResponse();
offset = checkContains(response, offset, "HTTP/1.1 200 OK", "3. ignore c-l") + 1;
offset = checkContains(response, offset, "/R1", "3. ignore c-l") + 1;
offset = checkContains(response, offset, "123456", "3. ignore c-l") + 1;
offset = 0;
response = endp.getResponse();
offset = checkContains(response, offset, "HTTP/1.1 200 OK", "3. ignore c-l") + 1;
offset = checkContains(response, offset, "/R2", "3. _content-length") + 1;
offset = checkContains(response, offset, "abcdef", "3. _content-length") + 1;
}
use of org.eclipse.jetty.server.LocalConnector.LocalEndPoint in project jetty.project by eclipse.
the class PartialRFC2616Test method test4_4_2.
@Test
public void test4_4_2() throws Exception {
String response;
int offset = 0;
// If _content length not used, second request will not be read.
LocalEndPoint endp = connector.executeRequest("GET /R1 HTTP/1.1\n" + "Host: localhost\n" + "Transfer-Encoding: identity\n" + "Content-Type: text/plain\n" + "Content-Length: 5\n" + "\n" + "123\015\012" + "GET /R2 HTTP/1.1\n" + "Host: localhost\n" + "Transfer-Encoding: other\n" + "Connection: close\n" + "\n");
offset = 0;
response = endp.getResponse();
offset = checkContains(response, offset, "HTTP/1.1 200 OK", "2. identity") + 10;
offset = checkContains(response, offset, "/R1", "2. identity") + 3;
offset = 0;
response = endp.getResponse();
offset = checkContains(response, offset, "HTTP/1.1 200 OK", "2. identity") + 10;
offset = checkContains(response, offset, "/R2", "2. identity") + 3;
}
use of org.eclipse.jetty.server.LocalConnector.LocalEndPoint in project jetty.project by eclipse.
the class RequestTest method testCookies.
@Test
public void testCookies() throws Exception {
final ArrayList<Cookie> cookies = new ArrayList<>();
_handler._checker = new RequestTester() {
@Override
public boolean check(HttpServletRequest request, HttpServletResponse response) throws IOException {
javax.servlet.http.Cookie[] ca = request.getCookies();
if (ca != null)
cookies.addAll(Arrays.asList(ca));
response.getOutputStream().println("Hello World");
return true;
}
};
String response;
cookies.clear();
response = _connector.getResponse("GET / HTTP/1.1\n" + "Host: whatever\n" + "Connection: close\n" + "\n");
assertTrue(response.startsWith("HTTP/1.1 200 OK"));
assertEquals(0, cookies.size());
cookies.clear();
response = _connector.getResponse("GET / HTTP/1.1\n" + "Host: whatever\n" + "Cookie: name=quoted=\"\\\"value\\\"\"\n" + "Connection: close\n" + "\n");
assertTrue(response.startsWith("HTTP/1.1 200 OK"));
assertEquals(1, cookies.size());
assertEquals("name", cookies.get(0).getName());
assertEquals("quoted=\"value\"", cookies.get(0).getValue());
cookies.clear();
response = _connector.getResponse("GET / HTTP/1.1\n" + "Host: whatever\n" + "Cookie: name=value; other=\"quoted=;value\"\n" + "Connection: close\n" + "\n");
assertTrue(response.startsWith("HTTP/1.1 200 OK"));
assertEquals(2, cookies.size());
assertEquals("name", cookies.get(0).getName());
assertEquals("value", cookies.get(0).getValue());
assertEquals("other", cookies.get(1).getName());
assertEquals("quoted=;value", cookies.get(1).getValue());
cookies.clear();
LocalEndPoint endp = _connector.executeRequest("GET /other HTTP/1.1\n" + "Host: whatever\n" + "Other: header\n" + "Cookie: name=value; other=\"quoted=;value\"\n" + "\n" + "GET /other HTTP/1.1\n" + "Host: whatever\n" + "Other: header\n" + "Cookie: name=value; other=\"quoted=;value\"\n" + "Connection: close\n" + "\n");
response = endp.getResponse();
assertThat(response, Matchers.startsWith("HTTP/1.1 200 OK"));
response = endp.getResponse();
assertThat(response, Matchers.startsWith("HTTP/1.1 200 OK"));
assertEquals(4, cookies.size());
assertEquals("name", cookies.get(0).getName());
assertEquals("value", cookies.get(0).getValue());
assertEquals("other", cookies.get(1).getName());
assertEquals("quoted=;value", cookies.get(1).getValue());
assertSame(cookies.get(0), cookies.get(2));
assertSame(cookies.get(1), cookies.get(3));
cookies.clear();
endp = _connector.executeRequest("GET /other HTTP/1.1\n" + "Host: whatever\n" + "Other: header\n" + "Cookie: name=value; other=\"quoted=;value\"\n" + "\n" + "GET /other HTTP/1.1\n" + "Host: whatever\n" + "Other: header\n" + "Cookie: name=value; other=\"othervalue\"\n" + "Connection: close\n" + "\n");
response = endp.getResponse();
assertThat(response, Matchers.startsWith("HTTP/1.1 200 OK"));
response = endp.getResponse();
assertThat(response, Matchers.startsWith("HTTP/1.1 200 OK"));
assertEquals(4, cookies.size());
assertEquals("name", cookies.get(0).getName());
assertEquals("value", cookies.get(0).getValue());
assertEquals("other", cookies.get(1).getName());
assertEquals("quoted=;value", cookies.get(1).getValue());
assertNotSame(cookies.get(0), cookies.get(2));
assertNotSame(cookies.get(1), cookies.get(3));
cookies.clear();
//NOTE: the javax.servlet.http.Cookie class sets the system property org.glassfish.web.rfc2109_cookie_names_enforced
//to TRUE by default, and rejects all cookie names containing punctuation.Therefore this test cannot use "name2".
response = _connector.getResponse("POST / HTTP/1.1\r\n" + "Host: whatever\r\n" + "Cookie: name0=value0; name1 = value1 ; \"name2\" = \"\\\"value2\\\"\" \n" + "Cookie: $Version=2; name3=value3=value3;$path=/path;$domain=acme.com;$port=8080; name4=; name5 = ; name6\n" + "Cookie: name7=value7;\n" + "Connection: close\r\n" + "\r\n");
assertEquals("name0", cookies.get(0).getName());
assertEquals("value0", cookies.get(0).getValue());
assertEquals("name1", cookies.get(1).getName());
assertEquals("value1", cookies.get(1).getValue());
assertEquals("name2", cookies.get(2).getName());
assertEquals("\"value2\"", cookies.get(2).getValue());
assertEquals("name3", cookies.get(3).getName());
assertEquals("value3=value3", cookies.get(3).getValue());
assertEquals(2, cookies.get(3).getVersion());
assertEquals("/path", cookies.get(3).getPath());
assertEquals("acme.com", cookies.get(3).getDomain());
assertEquals("$port=8080", cookies.get(3).getComment());
assertEquals("name4", cookies.get(4).getName());
assertEquals("", cookies.get(4).getValue());
assertEquals("name5", cookies.get(5).getName());
assertEquals("", cookies.get(5).getValue());
assertEquals("name6", cookies.get(6).getName());
assertEquals("", cookies.get(6).getValue());
assertEquals("name7", cookies.get(7).getName());
assertEquals("value7", cookies.get(7).getValue());
cookies.clear();
response = _connector.getResponse("GET /other HTTP/1.1\n" + "Host: whatever\n" + "Other: header\n" + "Cookie: __utmz=14316.133020.1.1.utr=gna.de|ucn=(real)|utd=reral|utct=/games/hen-one,gnt-50-ba-keys:key,2072262.html\n" + "Connection: close\n" + "\n");
assertTrue(response.startsWith("HTTP/1.1 200 OK"));
assertEquals(1, cookies.size());
assertEquals("__utmz", cookies.get(0).getName());
assertEquals("14316.133020.1.1.utr=gna.de|ucn=(real)|utd=reral|utct=/games/hen-one,gnt-50-ba-keys:key,2072262.html", cookies.get(0).getValue());
}
Aggregations