Search in sources :

Example 31 with DataFrame

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;
}
Also used : DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) DataSplit(com.webpieces.http2parser.impl.DataSplit) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Example 32 with DataFrame

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);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Example 33 with DataFrame

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());
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) DataWrapper(org.webpieces.data.api.DataWrapper) Header(org.webpieces.httpparser.api.common.Header) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) HttpData(org.webpieces.httpparser.api.dto.HttpData) MockStreamRef(org.webpieces.httpfrontend2.api.mock2.MockStreamRef) Test(org.junit.Test)

Example 34 with DataFrame

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);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Header(org.webpieces.httpparser.api.common.Header) HttpData(org.webpieces.httpparser.api.dto.HttpData) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 35 with DataFrame

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());
}
Also used : StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) Test(org.junit.Test)

Aggregations

DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)52 Test (org.junit.Test)31 DataWrapper (org.webpieces.data.api.DataWrapper)28 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)19 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)13 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)11 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)9 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)9 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)8 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)8 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)7 StreamRef (com.webpieces.http2.api.streaming.StreamRef)6 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)6 ConnectionClosedException (com.webpieces.http2engine.api.error.ConnectionClosedException)5 Header (org.webpieces.httpparser.api.common.Header)5 Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)4 HttpData (org.webpieces.httpparser.api.dto.HttpData)4 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)4 ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)3 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)3