Search in sources :

Example 1 with UnmarshalState

use of com.webpieces.hpack.api.UnmarshalState in project webpieces by deanhiller.

the class Http2SynchronousClient method startImpl.

public void startImpl(InetSocketAddress svrAddress) throws UnknownHostException, IOException {
    @SuppressWarnings("resource") Socket socket = new Socket(svrAddress.getHostName(), svrAddress.getPort());
    OutputStream output = socket.getOutputStream();
    Runnable client = new ClientWriter(parser, output);
    Thread t1 = new Thread(client);
    t1.setName("clientWriter");
    t1.start();
    InputStream input = socket.getInputStream();
    RateRecorder recorder = new RateRecorder(10);
    while (true) {
        byte[] bytes = new byte[1024];
        int read = input.read(bytes);
        if (read < 0)
            break;
        DataWrapper dataWrapper = dataGen.wrapByteArray(bytes, 0, read);
        UnmarshalState state = parser.unmarshal(dataWrapper);
        List<Http2Msg> messages = state.getParsedFrames();
        // simulate going all the way to http2 like the other test does as well
        for (Http2Msg p : messages) {
            Http2Response resp = (Http2Response) p;
            resp.getStreamId();
            recorder.increment();
        }
    }
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) DataWrapper(org.webpieces.data.api.DataWrapper) RateRecorder(org.webpieces.util.time.RateRecorder) UnmarshalState(com.webpieces.hpack.api.UnmarshalState) Socket(java.net.Socket)

Example 2 with UnmarshalState

use of com.webpieces.hpack.api.UnmarshalState in project webpieces by deanhiller.

the class TestSplitHeaders method testBytesParsedBySplittingHeaders.

@Test
public void testBytesParsedBySplittingHeaders() {
    Http2Request req = new Http2Request();
    req.setStreamId(1);
    req.addHeader(new Http2Header(Http2HeaderName.SCHEME, "/"));
    req.addHeader(new Http2Header(Http2HeaderName.METHOD, "/"));
    req.addHeader(new Http2Header(Http2HeaderName.PATH, "/"));
    req.addHeader(new Http2Header(Http2HeaderName.AUTHORITY, "/"));
    for (int i = 0; i < 20; i++) {
        req.addHeader(new Http2Header("someHeader" + i, "value"));
    }
    DataWrapper data = parser.marshal(req);
    byte[] first = data.readBytesAt(0, 60);
    DataWrapper data1 = dataGen.wrapByteArray(first);
    UnmarshalState state = parser.unmarshal(data1);
    Assert.assertEquals(0, state.getParsedFrames().size());
    Assert.assertEquals(0, state.getNumBytesJustParsed());
    Assert.assertEquals(first.length, state.getLeftOverDataSize());
    byte[] second = data.readBytesAt(60, data.getReadableSize() - 60);
    DataWrapper data2 = dataGen.wrapByteArray(second);
    state = parser.unmarshal(data2);
    Assert.assertEquals(1, state.getParsedFrames().size());
    Assert.assertEquals(data.getReadableSize(), state.getNumBytesJustParsed());
    Assert.assertEquals(0, state.getLeftOverDataSize());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) UnmarshalState(com.webpieces.hpack.api.UnmarshalState) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) Test(org.junit.Test)

Aggregations

UnmarshalState (com.webpieces.hpack.api.UnmarshalState)2 DataWrapper (org.webpieces.data.api.DataWrapper)2 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)1 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)1 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)1 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Socket (java.net.Socket)1 Test (org.junit.Test)1 RateRecorder (org.webpieces.util.time.RateRecorder)1