Search in sources :

Example 6 with LocalEndPoint

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

the class HttpOutputTest method testSendChannelBigChunked.

@Test
public void testSendChannelBigChunked() throws Exception {
    Resource big = Resource.newClassPathResource("simple/big.txt");
    final ReadableByteChannel channel = big.getReadableByteChannel();
    _handler._contentChannel = new ReadableByteChannel() {

        @Override
        public boolean isOpen() {
            return channel.isOpen();
        }

        @Override
        public void close() throws IOException {
            channel.close();
        }

        @Override
        public int read(ByteBuffer dst) throws IOException {
            int filled = 0;
            if (dst.position() == 0 && dst.limit() > 2000) {
                int limit = dst.limit();
                dst.limit(2000);
                filled = channel.read(dst);
                dst.limit(limit);
            } else
                filled = channel.read(dst);
            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 : ReadableByteChannel(java.nio.channels.ReadableByteChannel) Resource(org.eclipse.jetty.util.resource.Resource) IOException(java.io.IOException) Matchers.containsString(org.hamcrest.Matchers.containsString) ByteBuffer(java.nio.ByteBuffer) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) Test(org.junit.Test)

Example 7 with LocalEndPoint

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

the class RequestTest method testContentTypeEncoding.

@Test
public void testContentTypeEncoding() throws Exception {
    final ArrayList<String> results = new ArrayList<>();
    _handler._checker = new RequestTester() {

        @Override
        public boolean check(HttpServletRequest request, HttpServletResponse response) {
            results.add(request.getContentType());
            results.add(request.getCharacterEncoding());
            return true;
        }
    };
    LocalEndPoint endp = _connector.executeRequest("GET / HTTP/1.1\n" + "Host: whatever\n" + "Content-Type: text/test\n" + "\n" + "GET / HTTP/1.1\n" + "Host: whatever\n" + "Content-Type: text/html;charset=utf8\n" + "\n" + "GET / HTTP/1.1\n" + "Host: whatever\n" + "Content-Type: text/html; charset=\"utf8\"\n" + "\n" + "GET / HTTP/1.1\n" + "Host: whatever\n" + "Content-Type: text/html; other=foo ; blah=\"charset=wrong;\" ; charset =   \" x=z; \"   ; more=values \n" + "Connection: close\n" + "\n");
    endp.getResponse();
    endp.getResponse();
    endp.getResponse();
    endp.getResponse();
    int i = 0;
    assertEquals("text/test", results.get(i++));
    assertEquals(null, results.get(i++));
    assertEquals("text/html;charset=utf8", results.get(i++));
    assertEquals("utf-8", results.get(i++));
    assertEquals("text/html; charset=\"utf8\"", results.get(i++));
    assertEquals("utf-8", results.get(i++));
    assertTrue(results.get(i++).startsWith("text/html"));
    assertEquals(" x=z; ", results.get(i++));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ArrayList(java.util.ArrayList) HttpServletResponse(javax.servlet.http.HttpServletResponse) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) Test(org.junit.Test)

Example 8 with LocalEndPoint

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

the class PartialRFC2616Test method test19_6.

@Test
public void test19_6() {
    try {
        int offset = 0;
        String response = connector.getResponse("GET /R1 HTTP/1.0\n" + "\n");
        offset = checkContains(response, offset, "HTTP/1.1 200 OK\015\012", "19.6.2 default close") + 10;
        checkNotContained(response, offset, "Connection: close", "19.6.2 not assumed");
        LocalEndPoint endp = connector.executeRequest("GET /R1 HTTP/1.0\n" + "Host: localhost\n" + "Connection: keep-alive\n" + "\n" + "GET /R2 HTTP/1.0\n" + "Host: localhost\n" + "Connection: close\n" + "\n" + "GET /R3 HTTP/1.0\n" + "Host: localhost\n" + "Connection: close\n" + "\n");
        offset = 0;
        response = endp.getResponse();
        offset = checkContains(response, offset, "HTTP/1.1 200 OK\015\012", "19.6.2 Keep-alive 1") + 1;
        offset = checkContains(response, offset, "Connection: keep-alive", "19.6.2 Keep-alive 1") + 1;
        offset = checkContains(response, offset, "<html>", "19.6.2 Keep-alive 1") + 1;
        offset = checkContains(response, offset, "/R1", "19.6.2 Keep-alive 1") + 1;
        offset = 0;
        response = endp.getResponse();
        offset = checkContains(response, offset, "HTTP/1.1 200 OK\015\012", "19.6.2 Keep-alive 2") + 11;
        offset = checkContains(response, offset, "/R2", "19.6.2 Keep-alive close") + 3;
        offset = 0;
        response = endp.getResponse();
        assertThat("19.6.2 closed", response, nullValue());
        offset = 0;
        endp = connector.executeRequest("GET /R1 HTTP/1.0\n" + "Host: localhost\n" + "Connection: keep-alive\n" + "Content-Length: 10\n" + "\n" + "1234567890\n" + "GET /RA HTTP/1.0\n" + "Host: localhost\n" + "Connection: keep-alive\n" + "Content-Length: 10\n" + "\n" + "ABCDEFGHIJ\n" + "GET /R2 HTTP/1.0\n" + "Host: localhost\n" + "Connection: close\n" + "\n" + "GET /R3 HTTP/1.0\n" + "Host: localhost\n" + "Connection: close\n" + "\n");
        offset = 0;
        response = endp.getResponse();
        offset = checkContains(response, offset, "HTTP/1.1 200 OK\015\012", "19.6.2 Keep-alive 1") + 1;
        offset = checkContains(response, offset, "Connection: keep-alive", "19.6.2 Keep-alive 1") + 1;
        offset = checkContains(response, offset, "<html>", "19.6.2 Keep-alive 1") + 1;
        offset = checkContains(response, offset, "1234567890", "19.6.2 Keep-alive 1") + 1;
        offset = 0;
        response = endp.getResponse();
        offset = checkContains(response, offset, "HTTP/1.1 200 OK\015\012", "19.6.2 Keep-alive 1") + 1;
        offset = checkContains(response, offset, "Connection: keep-alive", "19.6.2 Keep-alive 1") + 1;
        offset = checkContains(response, offset, "<html>", "19.6.2 Keep-alive 1") + 1;
        offset = checkContains(response, offset, "ABCDEFGHIJ", "19.6.2 Keep-alive 1") + 1;
        offset = 0;
        response = endp.getResponse();
        offset = checkContains(response, offset, "HTTP/1.1 200 OK\015\012", "19.6.2 Keep-alive 2") + 11;
        offset = checkContains(response, offset, "/R2", "19.6.2 Keep-alive close") + 3;
        offset = 0;
        response = endp.getResponse();
        assertThat("19.6.2 closed", response, nullValue());
    } catch (Exception e) {
        e.printStackTrace();
        assertTrue(false);
    }
}
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 9 with LocalEndPoint

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

the class PartialRFC2616Test method test3_6_d.

@Test
public void test3_6_d() throws Exception {
    String response;
    int offset = 0;
    // Chunked and keep alive
    LocalEndPoint endp = connector.executeRequest("GET /R1 HTTP/1.1\n" + "Host: localhost\n" + "Transfer-Encoding: chunked\n" + "Content-Type: text/plain\n" + "Connection: keep-alive\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" + "\n");
    offset = 0;
    response = endp.getResponse();
    offset = checkContains(response, offset, "HTTP/1.1 200", "3.6.1 Chunking") + 10;
    offset = checkContains(response, offset, "123456", "3.6.1 Chunking");
    offset = 0;
    response = endp.getResponse();
    offset = checkContains(response, offset, "/R2", "3.6.1 Chunking") + 10;
}
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 10 with LocalEndPoint

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

the class PartialRFC2616Test method test8_1.

@Test
public void test8_1() throws Exception {
    int offset = 0;
    String response = connector.getResponse("GET /R1 HTTP/1.1\n" + "Host: localhost\n" + "\n", 250, TimeUnit.MILLISECONDS);
    offset = checkContains(response, offset, "HTTP/1.1 200 OK\015\012", "8.1.2 default") + 10;
    checkContains(response, offset, "Content-Length: ", "8.1.2 default");
    LocalEndPoint endp = connector.executeRequest("GET /R1 HTTP/1.1\n" + "Host: localhost\n" + "\n" + "GET /R2 HTTP/1.1\n" + "Host: localhost\n" + "Connection: close\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 OK\015\012", "8.1.2 default") + 1;
    offset = checkContains(response, offset, "/R1", "8.1.2 default") + 1;
    offset = 0;
    response = endp.getResponse();
    offset = checkContains(response, offset, "HTTP/1.1 200 OK\015\012", "8.1.2.2 pipeline") + 11;
    offset = checkContains(response, offset, "Connection: close", "8.1.2.2 pipeline") + 1;
    offset = checkContains(response, offset, "/R2", "8.1.2.1 close") + 3;
    offset = 0;
    response = endp.getResponse();
    assertThat(response, nullValue());
}
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)

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