Search in sources :

Example 6 with CancelReason

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

the class RequestStreamWriter2 method processPiece.

@Override
public XFuture<Void> processPiece(StreamMsg frame) {
    if (cancelled) {
        return XFuture.completedFuture(null);
    } else if (frame instanceof CancelReason) {
        cancelled = true;
        responseFuture.cancel(true);
    } else if (frame instanceof DataFrame) {
        DataFrame dataFrame = (DataFrame) frame;
        data = dataGen.chainDataWrappers(data, dataFrame.getData());
    } else if (frame instanceof Http2Headers) {
        if (!frame.isEndOfStream())
            throw new IllegalArgumentException("Trailing headers from client must have end of stream set");
        trailingHeaders = (Http2Headers) frame;
    } else {
        throw new IllegalStateException("frame not expected=" + frame);
    }
    if (frame.isEndOfStream()) {
        return handleCompleteRequestImpl();
    }
    // return immediately resolved as we need more data to form request
    return XFuture.completedFuture(null);
}
Also used : CancelReason(com.webpieces.http2.api.dto.lowlevel.CancelReason) Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame)

Example 7 with CancelReason

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

the class TestC4FrameSizeAndHeaders method testSection4_3BadDecompression.

// /**
// *  A decoding error in a header block MUST be treated as a connection error (Section 5.4.1) of type COMPRESSION_ERROR.
// *
// */
@Test
public void testSection4_3BadDecompression() {
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(null));
    Http2Request request = sendRequestToServer(listener1);
    // has to be 1 since we use 1 in the response
    Assert.assertEquals(1, request.getStreamId());
    String badHeaderFrame = // length
    "00 00 10" + // type
    "01" + // flags (ack)
    "05" + // R + streamid
    "00 00 00 01" + // payload
    "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00";
    // endOfStream=false
    mockChannel.writeHexBack(badHeaderFrame);
    // remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.COMPRESSION_ERROR, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: MockHttp2Channel1:stream1:(HEADER_DECODE) Error from hpack library", msg);
    Assert.assertTrue(mockChannel.isClosed());
    List<CancelReason> results = listener1.getRstStreams();
    Assert.assertEquals(1, results.size());
    ShutdownStream failResp = (ShutdownStream) results.get(0);
    Assert.assertEquals(CancelReasonCode.HEADER_DECODE, failResp.getCause().getReasonCode());
}
Also used : 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) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Example 8 with CancelReason

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

the class Level8NotifySvrListeners method sendRstToApp.

@Override
public XFuture<Void> sendRstToApp(Stream stream, CancelReason payload) {
    if (stream instanceof ServerStream) {
        ServerStream str = (ServerStream) stream;
        StreamRef streamRef = str.getStreamRef();
        return streamRef.cancel(payload);
    }
    // since the stream is closed, any writes to the push streams will automatically close and be cancelled
    return XFuture.completedFuture(null);
}
Also used : StreamRef(com.webpieces.http2.api.streaming.StreamRef)

Example 9 with CancelReason

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

the class Level8NotifyClntListeners method sendRstToApp.

@Override
public XFuture<Void> sendRstToApp(Stream stream, CancelReason payload) {
    if (stream instanceof ClientStream) {
        ClientStream str = (ClientStream) stream;
        ResponseStreamHandle handler = str.getResponseListener();
        return handler.cancel(payload);
    }
    ClientPushStream str = (ClientPushStream) stream;
    PushStreamHandle handle = str.getPushStreamHandle();
    return handle.cancelPush(payload);
}
Also used : PushStreamHandle(com.webpieces.http2.api.streaming.PushStreamHandle) ResponseStreamHandle(com.webpieces.http2.api.streaming.ResponseStreamHandle)

Aggregations

CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)7 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)4 StreamRef (com.webpieces.http2.api.streaming.StreamRef)4 Test (org.junit.Test)4 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)3 Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)2 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)2 RstStreamFrame (com.webpieces.http2.api.dto.lowlevel.RstStreamFrame)2 RequestStreamHandle (com.webpieces.http2.api.streaming.RequestStreamHandle)2 ResponseStreamHandle (com.webpieces.http2.api.streaming.ResponseStreamHandle)2 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)2 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)2 InetSocketAddress (java.net.InetSocketAddress)2 DataWrapper (org.webpieces.data.api.DataWrapper)2 MockResponseListener (org.webpieces.httpclient.api.mocks.MockResponseListener)2 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)1 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)1 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)1 PushStreamHandle (com.webpieces.http2.api.streaming.PushStreamHandle)1 ConnectionClosedException (com.webpieces.http2engine.api.error.ConnectionClosedException)1