Search in sources :

Example 36 with DataFrame

use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.

the class TestSMaxConcurrentSetting method testSend2ndPushHeadersOnlyOnAfterSettingsFrameMaxConcurrentBigger.

@Test
public void testSend2ndPushHeadersOnlyOnAfterSettingsFrameMaxConcurrentBigger() throws InterruptedException, ExecutionException, TimeoutException {
    WriterHolder sent = sendTwoRequests();
    // client increases max concurrent
    HeaderSettings settings = new HeaderSettings();
    settings.setMaxConcurrentStreams(2L);
    mockChannel.send(HeaderSettings.createSettingsFrame(settings));
    List<Http2Msg> frames = mockChannel.getFramesAndClear();
    Assert.assertEquals(2, frames.size());
    Assert.assertEquals(sent.getResp2(), frames.get(0));
    SettingsFrame dataRecv1 = (SettingsFrame) frames.get(1);
    Assert.assertTrue(dataRecv1.isAck());
    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 : SettingsFrame(com.webpieces.http2.api.dto.lowlevel.SettingsFrame) HeaderSettings(com.webpieces.http2engine.impl.shared.data.HeaderSettings) 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)

Example 37 with DataFrame

use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.

the class Http2Requests method createData1.

public static DataFrame createData1(int streamId, boolean eos) {
    DataFrame data = new DataFrame(streamId, eos);
    data.setData(DATA_GEN.wrapByteArray(new byte[] { 3, 4, 4 }));
    return data;
}
Also used : DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame)

Example 38 with DataFrame

use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.

the class Http2Requests method createData2.

public static DataFrame createData2(int streamId, boolean eos) {
    DataFrame data = new DataFrame(streamId, eos);
    data.setData(DATA_GEN.wrapByteArray(new byte[] { 3 }));
    return data;
}
Also used : DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame)

Example 39 with DataFrame

use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.

the class TestS4FrameSizeAndHeaders method testSection4_2FrameTooLarge.

/**
 * An endpoint MUST send an error code of FRAME_SIZE_ERROR if a frame
 * exceeds the size defined in SETTINGS_MAX_FRAME_SIZE, exceeds any
 * limit defined for the frame type, or is too small to contain
 * mandatory frame data. A frame size error in a frame that could alter
 * the state of the entire connection MUST be treated as a connection
 * error (Section 5.4.1); this includes any frame carrying a header
 * block (Section 4.3) (that is, HEADERS, PUSH_PROMISE, and
 * CONTINUATION), SETTINGS, and any frame with a stream identifier of 0.
 * @throws TimeoutException
 * @throws ExecutionException
 * @throws InterruptedException
 */
@Test
public void testSection4_2FrameTooLarge() throws InterruptedException, ExecutionException, TimeoutException {
    MockStreamWriter mockWriter = new MockStreamWriter();
    XFuture<StreamWriter> futA = XFuture.completedFuture(mockWriter);
    MockStreamRef mockStream = new MockStreamRef(futA);
    mockListener.addMockStreamToReturn(mockStream);
    int streamId = 1;
    PassedIn info = sendRequestToServer(streamId, false);
    ResponseStream stream = info.stream;
    Http2Request request = info.request;
    Assert.assertFalse(mockStream.isCancelled());
    // send data that goes with request
    DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
    byte[] buf = new byte[localSettings.getMaxFrameSize() + 4];
    dataFrame.setData(DATA_GEN.wrapByteArray(buf));
    // endOfStream=false
    mockChannel.send(dataFrame);
    // remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.FRAME_SIZE_ERROR, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: stream1:(EXCEEDED_MAX_FRAME_SIZE) Frame size=16389 was greater than max=16385", msg);
    Assert.assertTrue(mockChannel.isClosed());
    Assert.assertTrue(mockListener.isClosed());
    Assert.assertTrue(mockStream.isCancelled());
    CancelReason failResp = mockStream.getCancelInfo();
    ShutdownStream reset = (ShutdownStream) failResp;
    Assert.assertEquals(CancelReasonCode.EXCEEDED_MAX_FRAME_SIZE, reset.getCause().getReasonCode());
    // send response with request not complete but failed as well anyways
    Http2Response response = Http2Requests.createResponse(request.getStreamId());
    XFuture<StreamWriter> future = stream.process(response);
    ConnectionClosedException intercept = (ConnectionClosedException) TestAssert.intercept(future);
    Assert.assertTrue(intercept.getMessage().contains("Connection closed or closing"));
    Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) ConnectionClosedException(com.webpieces.http2engine.api.error.ConnectionClosedException) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) ResponseStream(org.webpieces.frontend2.api.ResponseStream) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) DataWrapper(org.webpieces.data.api.DataWrapper) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) CancelReason(com.webpieces.http2.api.dto.lowlevel.CancelReason) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) MockStreamRef(org.webpieces.httpfrontend2.api.mock2.MockStreamRef) Test(org.junit.Test)

Example 40 with DataFrame

use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.

the class Layer2Http11Handler method incomingData.

public XFuture<Void> incomingData(FrontendSocketImpl socket, ByteBuffer buf) {
    Http11StreamImpl currentStream = socket.getCurrentStream();
    if (currentStream != null && currentStream.isForConnectRequeest()) {
        // This is for doing an http proxy that upgrades to an SSL proxy and can't see traffic
        // going through itself.  it just passes traffic through
        DataFrame dataFrame = new DataFrame();
        DataWrapper wrapper = dataGen.wrapByteBuffer(buf);
        dataFrame.setData(wrapper);
        XFuture<StreamWriter> writer = currentStream.getStreamRef().getWriter();
        // We skip permit queue because this is chunking now in SSL that we can't read;
        return writer.thenCompose(w -> w.processPiece(dataFrame));
    }
    Memento state = socket.getHttp11ParseState();
    int newDataSize = buf.remaining();
    state = parse(socket, buf);
    return processWithBackpressure(socket, newDataSize, state.getNumBytesJustParsed()).exceptionally(t -> {
        try {
            MDCUtil.setMDC(true, socket + "");
            log.error("Exception", t);
            socket.close("Exception so closing http1.1 socket=" + t.getMessage());
            return null;
        } finally {
            MDCUtil.setMDC(true, null);
        }
    });
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Memento(org.webpieces.httpparser.api.Memento) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame)

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