Search in sources :

Example 1 with LocalEndPoint

use of org.eclipse.jetty.server.LocalConnector.LocalEndPoint in project jetty.project by eclipse.

the class HttpOutputTest method testSendInputStreamBigChunked.

@Test
public void testSendInputStreamBigChunked() throws Exception {
    Resource big = Resource.newClassPathResource("simple/big.txt");
    _handler._contentInputStream = new FilterInputStream(big.getInputStream()) {

        @Override
        public int read(byte[] b, int off, int len) throws IOException {
            int filled = super.read(b, off, len > 2000 ? 2000 : len);
            return filled;
        }
    };
    LocalEndPoint endp = _connector.executeRequest("GET / HTTP/1.1\nHost: localhost:80\n\n" + "GET / HTTP/1.1\nHost: localhost:80\nConnection: close\n\n");
    String response = endp.getResponse();
    assertThat(response, containsString("HTTP/1.1 200 OK"));
    assertThat(response, containsString("Transfer-Encoding: chunked"));
    assertThat(response, containsString("1\tThis is a big file"));
    assertThat(response, containsString("400\tThis is a big file"));
    assertThat(response, containsString("\r\n0\r\n"));
    response = endp.getResponse();
    assertThat(response, containsString("HTTP/1.1 200 OK"));
    assertThat(response, containsString("Connection: close"));
}
Also used : FilterInputStream(java.io.FilterInputStream) Resource(org.eclipse.jetty.util.resource.Resource) IOException(java.io.IOException) 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 2 with LocalEndPoint

use of org.eclipse.jetty.server.LocalConnector.LocalEndPoint in project jetty.project by eclipse.

the class HttpConnectionTest method testUnconsumedErrorRead.

@Test
public void testUnconsumedErrorRead() throws Exception {
    int offset = 0;
    String requests = "GET /R1?read=1&error=499 HTTP/1.1\r\n" + "Host: localhost\r\n" + "Transfer-Encoding: chunked\r\n" + "Content-Type: text/plain; charset=utf-8\r\n" + "\r\n" + "5;\r\n" + "12345\r\n" + "5;\r\n" + "67890\r\n" + "0;\r\n" + "\r\n" + "GET /R2 HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: text/plain; charset=utf-8\r\n" + "Content-Length: 10\r\n" + "Connection: close\r\n" + "\r\n" + "abcdefghij\r\n";
    LocalEndPoint endp = connector.executeRequest(requests);
    String response = endp.getResponse() + endp.getResponse();
    offset = checkContains(response, offset, "HTTP/1.1 499");
    offset = checkContains(response, offset, "HTTP/1.1 200");
    offset = checkContains(response, offset, "/R2");
    offset = checkContains(response, offset, "encoding=UTF-8");
    checkContains(response, offset, "abcdefghij");
}
Also used : LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) Test(org.junit.Test)

Example 3 with LocalEndPoint

use of org.eclipse.jetty.server.LocalConnector.LocalEndPoint in project jetty.project by eclipse.

the class HttpConnectionTest method testUnconsumedErrorStream.

@Test
public void testUnconsumedErrorStream() throws Exception {
    int offset = 0;
    String requests = "GET /R1?error=599 HTTP/1.1\r\n" + "Host: localhost\r\n" + "Transfer-Encoding: chunked\r\n" + "Content-Type: application/data; charset=utf-8\r\n" + "\r\n" + "5;\r\n" + "12345\r\n" + "5;\r\n" + "67890\r\n" + "0;\r\n" + "\r\n" + "GET /R2 HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: text/plain; charset=utf-8\r\n" + "Content-Length: 10\r\n" + "Connection: close\r\n" + "\r\n" + "abcdefghij\r\n";
    LocalEndPoint endp = connector.executeRequest(requests);
    String response = endp.getResponse() + endp.getResponse();
    offset = checkContains(response, offset, "HTTP/1.1 599");
    offset = checkContains(response, offset, "HTTP/1.1 200");
    offset = checkContains(response, offset, "/R2");
    offset = checkContains(response, offset, "encoding=UTF-8");
    checkContains(response, offset, "abcdefghij");
}
Also used : LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) Test(org.junit.Test)

Example 4 with LocalEndPoint

use of org.eclipse.jetty.server.LocalConnector.LocalEndPoint in project jetty.project by eclipse.

the class HttpConnectionTest method test_0_9.

@Test
public void test_0_9() throws Exception {
    connector.getConnectionFactory(HttpConnectionFactory.class).setHttpCompliance(HttpCompliance.RFC2616);
    LocalEndPoint endp = connector.executeRequest("GET /R1\n");
    endp.waitUntilClosed();
    String response = BufferUtil.toString(endp.takeOutput());
    int offset = 0;
    checkNotContained(response, offset, "HTTP/1.1");
    checkNotContained(response, offset, "200");
    checkContains(response, offset, "pathInfo=/R1");
}
Also used : LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) Test(org.junit.Test)

Example 5 with LocalEndPoint

use of org.eclipse.jetty.server.LocalConnector.LocalEndPoint in project jetty.project by eclipse.

the class HttpConnectionTest method testUnconsumed.

@Test
public void testUnconsumed() throws Exception {
    int offset = 0;
    String requests = "GET /R1?read=4 HTTP/1.1\r\n" + "Host: localhost\r\n" + "Transfer-Encoding: chunked\r\n" + "Content-Type: text/plain; charset=utf-8\r\n" + "\r\n" + "5;\r\n" + "12345\r\n" + "5;\r\n" + "67890\r\n" + "0;\r\n" + "\r\n" + "GET /R2 HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: text/plain; charset=utf-8\r\n" + "Content-Length: 10\r\n" + "Connection: close\r\n" + "\r\n" + "abcdefghij\r\n";
    LocalEndPoint endp = connector.executeRequest(requests);
    String response = endp.getResponse() + endp.getResponse();
    offset = checkContains(response, offset, "HTTP/1.1 200");
    offset = checkContains(response, offset, "pathInfo=/R1");
    offset = checkContains(response, offset, "1234");
    checkNotContained(response, offset, "56789");
    offset = checkContains(response, offset, "HTTP/1.1 200");
    offset = checkContains(response, offset, "pathInfo=/R2");
    offset = checkContains(response, offset, "encoding=UTF-8");
    checkContains(response, offset, "abcdefghij");
}
Also used : LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) 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