use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.
the class DataMarshaller method unmarshal.
@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
DataFrame frame = new DataFrame();
super.unmarshalFrame(state, frame);
byte flags = state.getFrameHeaderData().getFlagsByte();
frame.setEndOfStream((flags & 0x1) == 0x1);
boolean isPadded = (flags & 0x8) == 0x8;
DataSplit split = PaddingUtil.extractPayloadAndPadding(isPadded, framePayloadData, frame.getStreamId());
frame.setData(split.getPayload());
frame.setPadding(split.getPadding());
if (frame.getStreamId() == 0)
throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "headers frame had invalid stream id=" + frame.getStreamId());
return frame;
}
use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.
the class DataMarshaller method marshal.
@Override
public DataWrapper marshal(Http2Frame frame) {
DataFrame castFrame = (DataFrame) frame;
int paddingSize = castFrame.getPadding().getReadableSize();
if (frame.getStreamId() == 0)
throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "data frame had invalid stream id=" + frame.getStreamId());
byte value = (byte) 0x0;
if (castFrame.isEndOfStream())
value |= 0x1;
if (paddingSize > 0)
value |= 0x8;
DataWrapper dataPayload = PaddingUtil.padDataIfNeeded(castFrame.getData(), castFrame.getPadding());
return super.marshalFrame(frame, value, dataPayload);
}
use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.
the class TestHttp11Errors method testCloseAfter2ndRequest.
@Test
public void testCloseAfter2ndRequest() throws InterruptedException, ExecutionException, TimeoutException {
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
HttpRequest req2 = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
XFuture<StreamWriter> futA = XFuture.completedFuture(null);
MockStreamRef mockStreamRefA = new MockStreamRef(futA);
mockListener.addMockStreamToReturn(mockStreamRefA);
mockChannel.sendToSvr(req);
PassedIn in1 = mockListener.getSingleRequest();
XFuture<StreamWriter> futB = XFuture.completedFuture(null);
MockStreamRef mockStreamRefB = new MockStreamRef(futB);
mockListener.addMockStreamToReturn(mockStreamRefB);
XFuture<Void> fut1 = mockChannel.sendToSvrAsync(req2);
Assert.assertFalse(fut1.isDone());
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
HttpResponse resp1 = Requests.createResponse(1);
resp1.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "10"));
Http2Response headers1 = Http11ToHttp2.responseToHeaders(resp1);
XFuture<StreamWriter> future = in1.stream.process(headers1);
HttpPayload payload = mockChannel.getFrameAndClear();
Assert.assertEquals(resp1, payload);
StreamWriter writer = future.get(2, TimeUnit.SECONDS);
Assert.assertFalse(fut1.isDone());
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
byte[] buf = new byte[10];
DataWrapper dataWrapper = DATA_GEN.wrapByteArray(buf);
HttpData data1 = new HttpData(dataWrapper, true);
DataFrame data = (DataFrame) Http11ToHttp2.translateData(data1);
writer.processPiece(data);
fut1.get(2, TimeUnit.SECONDS);
Assert.assertFalse(mockStreamRefA.isCancelled());
Assert.assertFalse(mockStreamRefB.isCancelled());
mockChannel.simulateClose();
// this request is done, nothing to cancel
Assert.assertFalse(mockStreamRefA.isCancelled());
Assert.assertTrue(mockStreamRefB.isCancelled());
}
use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.
the class TestHttp11Basic method testUploadWithBody.
@Test
public void testUploadWithBody() throws InterruptedException, ExecutionException, TimeoutException {
String bodyStr = "hi there, how are you";
DataWrapper dataWrapper = DATA_GEN.wrapByteArray(bodyStr.getBytes(StandardCharsets.UTF_8));
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
HttpData body = new HttpData(dataWrapper, true);
req.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "" + dataWrapper.getReadableSize()));
mockChannel.sendToSvr(req);
mockChannel.sendToSvr(body);
PassedIn in1 = mockListener.getSingleRequest();
HttpRequest req1 = Http2ToHttp11.translateRequest(in1.request);
Assert.assertEquals(req, req1);
DataFrame frame = (DataFrame) mockStreamWriter.getSingleFrame();
DataWrapper data = frame.getData();
Assert.assertEquals(bodyStr, data.createStringFromUtf8(0, data.getReadableSize()));
Assert.assertTrue(frame.isEndOfStream());
HttpResponse resp = Requests.createNobodyResponse();
Http2Response http2Resp = Http11ToHttp2.responseToHeaders(resp);
XFuture<StreamWriter> fut = in1.stream.process(http2Resp);
fut.get(2, TimeUnit.SECONDS);
HttpResponse respToClient = (HttpResponse) mockChannel.getFrameAndClear();
Assert.assertEquals(resp, respToClient);
}
use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.
the class TestSMaxConcurrentSetting method testSend2ndPushHeadersOnlyOnCompletionOfFirst.
@Test
public void testSend2ndPushHeadersOnlyOnCompletionOfFirst() throws InterruptedException, ExecutionException, TimeoutException {
WriterHolder sent = sendTwoRequests();
DataFrame data1 = Http2Requests.createData1(sent.getResp1().getStreamId(), true);
// ending this promise stream starts the next
sent.getWriter1().processPiece(data1);
List<Http2Msg> frames = mockChannel.getFramesAndClear();
Assert.assertEquals(2, frames.size());
Assert.assertEquals(sent.getResp2(), frames.get(0));
DataFrame dataRecv1 = (DataFrame) frames.get(1);
Assert.assertEquals(sent.getResp1().getStreamId(), dataRecv1.getStreamId());
StreamWriter writer2 = sent.getFuture2().get(2, TimeUnit.SECONDS);
DataFrame data2 = Http2Requests.createData1(sent.getResp2().getStreamId(), true);
writer2.processPiece(data2);
DataFrame dataRecv2 = (DataFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(sent.getResp2().getStreamId(), dataRecv2.getStreamId());
}
Aggregations