Search in sources :

Example 1 with SettingsFrame

use of org.eclipse.jetty.http2.frames.SettingsFrame in project jetty.project by eclipse.

the class HTTP2ServerTest method testRequestResponseNoContent.

@Test
public void testRequestResponseNoContent() throws Exception {
    final CountDownLatch latch = new CountDownLatch(3);
    startServer(new HttpServlet() {

        @Override
        protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            latch.countDown();
        }
    });
    ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
    generator.control(lease, new PrefaceFrame());
    generator.control(lease, new SettingsFrame(new HashMap<>(), false));
    MetaData.Request metaData = newRequest("GET", new HttpFields());
    generator.control(lease, new HeadersFrame(1, metaData, null, true));
    try (Socket client = new Socket("localhost", connector.getLocalPort())) {
        OutputStream output = client.getOutputStream();
        for (ByteBuffer buffer : lease.getByteBuffers()) {
            output.write(BufferUtil.toArray(buffer));
        }
        final AtomicReference<HeadersFrame> frameRef = new AtomicReference<>();
        Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter() {

            @Override
            public void onSettings(SettingsFrame frame) {
                latch.countDown();
            }

            @Override
            public void onHeaders(HeadersFrame frame) {
                frameRef.set(frame);
                latch.countDown();
            }
        }, 4096, 8192);
        parseResponse(client, parser);
        Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
        HeadersFrame response = frameRef.get();
        Assert.assertNotNull(response);
        MetaData.Response responseMetaData = (MetaData.Response) response.getMetaData();
        Assert.assertEquals(200, responseMetaData.getStatus());
    }
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) ServerSessionListener(org.eclipse.jetty.http2.api.server.ServerSessionListener) HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) SettingsFrame(org.eclipse.jetty.http2.frames.SettingsFrame) MetaData(org.eclipse.jetty.http.MetaData) HttpFields(org.eclipse.jetty.http.HttpFields) HttpServlet(javax.servlet.http.HttpServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) ByteBuffer(java.nio.ByteBuffer) Parser(org.eclipse.jetty.http2.parser.Parser) PrefaceFrame(org.eclipse.jetty.http2.frames.PrefaceFrame) HttpServletResponse(javax.servlet.http.HttpServletResponse) Socket(java.net.Socket) Test(org.junit.Test)

Example 2 with SettingsFrame

use of org.eclipse.jetty.http2.frames.SettingsFrame in project jetty.project by eclipse.

the class HTTP2ServerTest method testRequestWithPriorityWithContinuationFrames.

@Test
public void testRequestWithPriorityWithContinuationFrames() throws Exception {
    PriorityFrame priority = new PriorityFrame(1, 13, 200, true);
    testRequestWithContinuationFrames(priority, () -> {
        ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
        generator.control(lease, new PrefaceFrame());
        generator.control(lease, new SettingsFrame(new HashMap<>(), false));
        MetaData.Request metaData = newRequest("GET", new HttpFields());
        generator.control(lease, new HeadersFrame(1, metaData, priority, true));
        return lease;
    });
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) PrefaceFrame(org.eclipse.jetty.http2.frames.PrefaceFrame) SettingsFrame(org.eclipse.jetty.http2.frames.SettingsFrame) HashMap(java.util.HashMap) MetaData(org.eclipse.jetty.http.MetaData) HttpFields(org.eclipse.jetty.http.HttpFields) PriorityFrame(org.eclipse.jetty.http2.frames.PriorityFrame) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) Test(org.junit.Test)

Example 3 with SettingsFrame

use of org.eclipse.jetty.http2.frames.SettingsFrame in project jetty.project by eclipse.

the class HTTP2ServerTest method testRequestWithContinuationFramesWithEmptyLastContinuationFrame.

@Test
public void testRequestWithContinuationFramesWithEmptyLastContinuationFrame() throws Exception {
    testRequestWithContinuationFrames(null, () -> {
        ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
        generator.control(lease, new PrefaceFrame());
        generator.control(lease, new SettingsFrame(new HashMap<>(), false));
        MetaData.Request metaData = newRequest("GET", new HttpFields());
        generator.control(lease, new HeadersFrame(1, metaData, null, true));
        // Take the last CONTINUATION frame and reset the flag.
        List<ByteBuffer> buffers = lease.getByteBuffers();
        ByteBuffer continuationFrameHeader = buffers.get(buffers.size() - 2);
        continuationFrameHeader.put(4, (byte) 0);
        // Add a last, empty, CONTINUATION frame.
        ByteBuffer last = ByteBuffer.wrap(new byte[] { // Length
        0, // Length
        0, // Length
        0, (byte) FrameType.CONTINUATION.getType(), (byte) Flags.END_HEADERS, // Stream ID
        0, // Stream ID
        0, // Stream ID
        0, // Stream ID
        1 });
        lease.append(last, false);
        return lease;
    });
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) PrefaceFrame(org.eclipse.jetty.http2.frames.PrefaceFrame) SettingsFrame(org.eclipse.jetty.http2.frames.SettingsFrame) HashMap(java.util.HashMap) MetaData(org.eclipse.jetty.http.MetaData) HttpFields(org.eclipse.jetty.http.HttpFields) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 4 with SettingsFrame

use of org.eclipse.jetty.http2.frames.SettingsFrame in project jetty.project by eclipse.

the class HTTP2ServerTest method testRequestWithContinuationFramesWithEmptyContinuationFrame.

@Test
public void testRequestWithContinuationFramesWithEmptyContinuationFrame() throws Exception {
    testRequestWithContinuationFrames(null, () -> {
        ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
        generator.control(lease, new PrefaceFrame());
        generator.control(lease, new SettingsFrame(new HashMap<>(), false));
        MetaData.Request metaData = newRequest("GET", new HttpFields());
        generator.control(lease, new HeadersFrame(1, metaData, null, true));
        // Take the ContinuationFrame header, duplicate it, and set the length to zero.
        List<ByteBuffer> buffers = lease.getByteBuffers();
        ByteBuffer continuationFrameHeader = buffers.get(4);
        ByteBuffer duplicate = ByteBuffer.allocate(continuationFrameHeader.remaining());
        duplicate.put(continuationFrameHeader).flip();
        continuationFrameHeader.flip();
        continuationFrameHeader.put(0, (byte) 0);
        continuationFrameHeader.putShort(1, (short) 0);
        // Insert a CONTINUATION frame header for the body of the previous CONTINUATION frame.
        lease.insert(5, duplicate, false);
        return lease;
    });
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) PrefaceFrame(org.eclipse.jetty.http2.frames.PrefaceFrame) SettingsFrame(org.eclipse.jetty.http2.frames.SettingsFrame) HashMap(java.util.HashMap) MetaData(org.eclipse.jetty.http.MetaData) HttpFields(org.eclipse.jetty.http.HttpFields) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 5 with SettingsFrame

use of org.eclipse.jetty.http2.frames.SettingsFrame in project jetty.project by eclipse.

the class HTTP2ServerTest method testRequestWithContinuationFramesWithEmptyHeadersFrame.

@Test
public void testRequestWithContinuationFramesWithEmptyHeadersFrame() throws Exception {
    testRequestWithContinuationFrames(null, () -> {
        ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
        generator.control(lease, new PrefaceFrame());
        generator.control(lease, new SettingsFrame(new HashMap<>(), false));
        MetaData.Request metaData = newRequest("GET", new HttpFields());
        generator.control(lease, new HeadersFrame(1, metaData, null, true));
        // Take the HeadersFrame header and set the length to zero.
        List<ByteBuffer> buffers = lease.getByteBuffers();
        ByteBuffer headersFrameHeader = buffers.get(2);
        headersFrameHeader.put(0, (byte) 0);
        headersFrameHeader.putShort(1, (short) 0);
        // Insert a CONTINUATION frame header for the body of the HEADERS frame.
        lease.insert(3, buffers.get(4).slice(), false);
        return lease;
    });
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) PrefaceFrame(org.eclipse.jetty.http2.frames.PrefaceFrame) SettingsFrame(org.eclipse.jetty.http2.frames.SettingsFrame) HashMap(java.util.HashMap) MetaData(org.eclipse.jetty.http.MetaData) HttpFields(org.eclipse.jetty.http.HttpFields) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

SettingsFrame (org.eclipse.jetty.http2.frames.SettingsFrame)33 HashMap (java.util.HashMap)29 Test (org.junit.Test)29 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)26 HttpFields (org.eclipse.jetty.http.HttpFields)25 MetaData (org.eclipse.jetty.http.MetaData)25 ByteBuffer (java.nio.ByteBuffer)22 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)22 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)20 PrefaceFrame (org.eclipse.jetty.http2.frames.PrefaceFrame)20 CountDownLatch (java.util.concurrent.CountDownLatch)19 Parser (org.eclipse.jetty.http2.parser.Parser)15 Session (org.eclipse.jetty.http2.api.Session)14 OutputStream (java.io.OutputStream)12 Socket (java.net.Socket)12 Stream (org.eclipse.jetty.http2.api.Stream)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 Map (java.util.Map)10 HTTP2Session (org.eclipse.jetty.http2.HTTP2Session)10 DataFrame (org.eclipse.jetty.http2.frames.DataFrame)9