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();
}
}
}
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());
}
Aggregations