Search in sources :

Example 1 with Http2Push

use of com.webpieces.http2.api.dto.highlevel.Http2Push in project webpieces by deanhiller.

the class TestC5x1StreamStates method sendPushFromServer.

private Http2Push sendPushFromServer(MockResponseListener listener1, Http2Request request) {
    Http2Push resp1 = Requests.createPush(request.getStreamId());
    mockChannel.write(resp1);
    Http2Push response1 = listener1.getSinglePush();
    Assert.assertEquals(resp1, response1);
    return resp1;
}
Also used : Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push)

Example 2 with Http2Push

use of com.webpieces.http2.api.dto.highlevel.Http2Push in project webpieces by deanhiller.

the class TestC5x1StreamStates method testSection5_1BadFrameReceivedInReservedRemoteState.

/**
 * Receiving any type of frame other than HEADERS, RST_STREAM, or PRIORITY on a
 * stream in this state MUST be treated as a connection
 * error (Section 5.4.1) of type PROTOCOL_ERROR.
 */
@Test
public void testSection5_1BadFrameReceivedInReservedRemoteState() {
    MockPushListener pushListener = new MockPushListener();
    pushListener.setIncomingRespDefault(XFuture.<Void>completedFuture(null));
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(null));
    listener1.addReturnValuePush(pushListener);
    Http2Request request = sendRequestToServer(listener1);
    Http2Push push = sendPushFromServer(listener1, request);
    DataFrame dataFrame = new DataFrame(push.getPromisedStreamId(), false);
    mockChannel.write(dataFrame);
    // remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.PROTOCOL_ERROR, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: MockHttp2Channel1:stream2:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "No transition defined on statemachine for event=RECV_DATA when in state=Reserved(remote)", msg);
    Assert.assertTrue(mockChannel.isClosed());
    ShutdownStream failResp1 = (ShutdownStream) listener1.getSingleRstStream();
    Assert.assertEquals(CancelReasonCode.BAD_FRAME_RECEIVED_FOR_THIS_STATE, failResp1.getCause().getReasonCode());
    ShutdownStream failResp2 = (ShutdownStream) listener1.getSingleCancelPush();
    Assert.assertEquals(CancelReasonCode.BAD_FRAME_RECEIVED_FOR_THIS_STATE, failResp2.getCause().getReasonCode());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) MockPushListener(org.webpieces.http2client.mock.MockPushListener) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Example 3 with Http2Push

use of com.webpieces.http2.api.dto.highlevel.Http2Push in project webpieces by deanhiller.

the class Http2Requests method createPush.

public static Http2Push createPush(int streamId) {
    Http2Push push = new Http2Push();
    push.setStreamId(streamId);
    push.addHeader(new Http2Header(Http2HeaderName.SERVER, "me"));
    return push;
}
Also used : Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push)

Example 4 with Http2Push

use of com.webpieces.http2.api.dto.highlevel.Http2Push in project webpieces by deanhiller.

the class HeaderEncoding method translateToFrames.

public List<Http2Frame> translateToFrames(long maxFrameSize, Encoder encoder, Http2Push p) {
    PushPromiseFrame frame = new PushPromiseFrame();
    frame.setStreamId(p.getStreamId());
    frame.setPromisedStreamId(p.getPromisedStreamId());
    List<Http2Header> headerList = p.getHeaders();
    List<Http2Frame> headerFrames = toHeaderFrames(maxFrameSize, encoder, frame, headerList);
    return headerFrames;
}
Also used : Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) PushPromiseFrame(com.webpieces.http2.api.dto.lowlevel.PushPromiseFrame) Http2Frame(com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)

Example 5 with Http2Push

use of com.webpieces.http2.api.dto.highlevel.Http2Push in project webpieces by deanhiller.

the class TestS5x1StreamStates method testSection5_1BadFrameReceivedInReservedRemoteState.

/**
 * reserved local
 *
 * A PRIORITY or WINDOW_UPDATE frame MAY be received in this state. Receiving any
 * type of frame other than RST_STREAM, PRIORITY, or WINDOW_UPDATE on a stream
 * in this state MUST be treated as a connection error (Section 5.4.1) of type PROTOCOL_ERROR.
 */
@Test
public void testSection5_1BadFrameReceivedInReservedRemoteState() {
    MockStreamWriter mockWriter = new MockStreamWriter();
    XFuture<StreamWriter> futA = XFuture.completedFuture(mockWriter);
    MockStreamRef mockStream = new MockStreamRef(futA);
    mockListener.addMockStreamToReturn(mockStream);
    Http2Request request = Http2Requests.createRequest(1, true);
    mockChannel.send(request);
    PassedIn in = mockListener.getSingleRequest();
    ResponseStream stream = in.stream;
    Http2Push push = Http2Requests.createPush(request.getStreamId());
    stream.openPushStream().process(push);
    Http2Msg pushMsg = mockChannel.getFrameAndClear();
    Assert.assertEquals(push, pushMsg);
    // send bad frame in this state
    DataFrame data = Http2Requests.createData1(push.getPromisedStreamId(), false);
    mockChannel.send(data);
    Assert.assertTrue(mockStream.isCancelled());
    // remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.PROTOCOL_ERROR, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: HttpSocket[Http2ChannelCache1]:stream2:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "No transition defined on statemachine for event=RECV_DATA when in state=Reserved(local)", msg);
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) 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) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) MockStreamRef(org.webpieces.httpfrontend2.api.mock2.MockStreamRef) Test(org.junit.Test)

Aggregations

Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)10 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)4 Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)3 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)3 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)3 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)3 Test (org.junit.Test)3 DataWrapper (org.webpieces.data.api.DataWrapper)3 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)3 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)2 PushPromiseFrame (com.webpieces.http2.api.dto.lowlevel.PushPromiseFrame)2 Http2Frame (com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)2 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)2 PushPromiseListener (com.webpieces.http2.api.streaming.PushPromiseListener)2 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)2 MockPushListener (org.webpieces.http2client.mock.MockPushListener)2 Encoder (com.twitter.hpack.Encoder)1 ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)1 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)1 HeadersFrame (com.webpieces.http2.api.dto.lowlevel.HeadersFrame)1