Search in sources :

Example 16 with LocalEndPoint

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletInputStream(javax.servlet.ServletInputStream) InputStream(java.io.InputStream) HttpServletRequest(javax.servlet.http.HttpServletRequest) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HttpServletResponse(javax.servlet.http.HttpServletResponse) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) Test(org.junit.Test)

Example 17 with LocalEndPoint

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");
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) Test(org.junit.Test)

Example 18 with LocalEndPoint

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"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) Test(org.junit.Test)

Example 19 with LocalEndPoint

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"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) Test(org.junit.Test)

Example 20 with LocalEndPoint

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());
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) Test(org.junit.Test)

Aggregations

LocalEndPoint (org.eclipse.jetty.server.LocalConnector.LocalEndPoint)21 Test (org.junit.Test)21 Matchers.containsString (org.hamcrest.Matchers.containsString)14 IOException (java.io.IOException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 ArrayList (java.util.ArrayList)2 Resource (org.eclipse.jetty.util.resource.Resource)2 FilterInputStream (java.io.FilterInputStream)1 InputStream (java.io.InputStream)1 ByteBuffer (java.nio.ByteBuffer)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 ServletInputStream (javax.servlet.ServletInputStream)1 Cookie (javax.servlet.http.Cookie)1 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)1 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)1