use of org.eclipse.jetty.server.LocalConnector.LocalEndPoint in project jetty.project by eclipse.
the class RequestTest method testPartialInput.
@Test
public void testPartialInput() throws Exception {
Handler handler = new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
InputStream in = request.getInputStream();
byte[] b = ("read=" + in.read() + "\n").getBytes(StandardCharsets.UTF_8);
response.setContentLength(b.length);
response.getOutputStream().write(b);
response.flushBuffer();
}
};
_server.stop();
_server.setHandler(handler);
_server.start();
String requests = "GET / HTTP/1.1\r\n" + "Host: whatever\r\n" + "Content-Type: text/plane\r\n" + "Content-Length: " + 10 + "\r\n" + "\r\n" + "0123456789\r\n" + "GET / HTTP/1.1\r\n" + "Host: whatever\r\n" + "Content-Type: text/plane\r\n" + "Content-Length: " + 10 + "\r\n" + "Connection: close\r\n" + "\r\n" + "ABCDEFGHIJ\r\n";
LocalEndPoint endp = _connector.executeRequest(requests);
String responses = endp.getResponse() + endp.getResponse();
int index = responses.indexOf("read=" + (int) '0');
assertTrue(index > 0);
index = responses.indexOf("read=" + (int) 'A', index + 7);
assertTrue(index > 0);
}
use of org.eclipse.jetty.server.LocalConnector.LocalEndPoint in project jetty.project by eclipse.
the class PartialRFC2616Test method test3_6_b.
@Test
public void test3_6_b() throws Exception {
String response;
int offset = 0;
// Chunked
LocalEndPoint endp = connector.executeRequest("GET /R1 HTTP/1.1\n" + "Host: localhost\n" + "Transfer-Encoding: chunked\n" + "Content-Type: text/plain\n" + "\n" + "2;\n" + "12\n" + "3;\n" + "345\n" + "0;\n\n" + "GET /R2 HTTP/1.1\n" + "Host: localhost\n" + "Transfer-Encoding: chunked\n" + "Content-Type: text/plain\n" + "\n" + "4;\n" + "6789\n" + "5;\n" + "abcde\n" + "0;\n\n" + "GET /R3 HTTP/1.1\n" + "Host: localhost\n" + "Connection: close\n" + "\n");
offset = 0;
response = endp.getResponse();
offset = checkContains(response, offset, "HTTP/1.1 200", "3.6.1 Chunking");
offset = checkContains(response, offset, "12345", "3.6.1 Chunking");
offset = 0;
response = endp.getResponse();
offset = checkContains(response, offset, "HTTP/1.1 200", "3.6.1 Chunking");
offset = checkContains(response, offset, "6789abcde", "3.6.1 Chunking");
offset = 0;
response = endp.getResponse();
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 testExpectContinuesAvailable.
@Test
public void testExpectContinuesAvailable() throws Exception {
LocalEndPoint endp = _connector.connect();
endp.addInput("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" + "01234567890\r\n");
String 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 LocalConnectorTest method testThreeResponse_11.
@Test
public void testThreeResponse_11() throws Exception {
LocalEndPoint endp = _connector.connect();
endp.addInput("GET /R1 HTTP/1.1\r\n" + "Host: localhost\r\n" + "\r\n");
String response = endp.getResponse();
assertThat(response, containsString("HTTP/1.1 200 OK"));
assertThat(response, containsString("pathInfo=/R1"));
endp.addInput("GET /R2 HTTP/1.1\r\n" + "Host: localhost\r\n" + "\r\n");
response = endp.getResponse();
assertThat(response, containsString("HTTP/1.1 200 OK"));
assertThat(response, containsString("pathInfo=/R2"));
endp.addInput("GET /R3 HTTP/1.1\r\n" + "Host: localhost\r\n" + "\r\n");
response = endp.getResponse();
assertThat(response, containsString("HTTP/1.1 200 OK"));
assertThat(response, containsString("pathInfo=/R3"));
}
use of org.eclipse.jetty.server.LocalConnector.LocalEndPoint in project jetty.project by eclipse.
the class LocalConnectorTest method testThreeResponseClosed_11.
@Test
public void testThreeResponseClosed_11() throws Exception {
LocalEndPoint endp = _connector.connect();
endp.addInput("GET /R1 HTTP/1.1\r\n" + "Host: localhost\r\n" + "\r\n" + "GET /R2 HTTP/1.1\r\n" + "Connection: close\r\n" + "Host: localhost\r\n" + "\r\n" + "GET /R3 HTTP/1.1\r\n" + "Host: localhost\r\n" + "\r\n");
String response = endp.getResponse();
assertThat(response, containsString("HTTP/1.1 200 OK"));
assertThat(response, containsString("pathInfo=/R1"));
response = endp.getResponse();
assertThat(response, containsString("HTTP/1.1 200 OK"));
assertThat(response, containsString("pathInfo=/R2"));
response = endp.getResponse();
assertThat(response, nullValue());
}
Aggregations