use of com.webpieces.hpack.api.dto.Http2Push in project webpieces by deanhiller.
the class Level5AStates method translate.
protected Http2Event translate(Http2SendRecieve sendRecv, Http2Msg payload) {
Http2PayloadType payloadType;
if (payload instanceof Http2Headers) {
Http2Headers head = (Http2Headers) payload;
if (head.isEndOfStream())
payloadType = Http2PayloadType.HEADERS_EOS;
else
payloadType = Http2PayloadType.HEADERS;
} else if (payload instanceof DataFrame) {
DataFrame data = (DataFrame) payload;
if (data.isEndOfStream())
payloadType = Http2PayloadType.DATA_EOS;
else
payloadType = Http2PayloadType.DATA;
} else if (payload instanceof Http2Push) {
payloadType = Http2PayloadType.PUSH_PROMISE;
} else if (payload instanceof CancelReason) {
payloadType = Http2PayloadType.RESET_STREAM;
} else
throw new IllegalArgumentException("unknown payload type for payload=" + payload);
return Http2Event.lookup(sendRecv, payloadType);
}
use of com.webpieces.hpack.api.dto.Http2Push in project webpieces by deanhiller.
the class Requests method createPush.
public static Http2Push createPush(int streamId) {
Http2Push push = new Http2Push();
push.setStreamId(streamId);
push.setPromisedStreamId(2);
push.addHeader(new Http2Header(Http2HeaderName.SERVER, "me"));
return push;
}
use of com.webpieces.hpack.api.dto.Http2Push in project webpieces by deanhiller.
the class TestSBasicRequestResponse method testPushPromise.
@Test
public void testPushPromise() throws InterruptedException, ExecutionException, TimeoutException {
Http2Request request1 = Http2Requests.createRequest(1, true);
mockChannel.send(request1);
PassedIn incoming = mockListener.getSingleRequest();
Assert.assertEquals(request1, incoming.request);
Http2Push push = Http2Requests.createPush(request1.getStreamId());
CompletableFuture<PushPromiseListener> future = incoming.stream.openPushStream().process(push);
PushPromiseListener pushWriter = future.get(2, TimeUnit.SECONDS);
Http2Push pushRecv = (Http2Push) mockChannel.getFrameAndClear();
Assert.assertEquals(push, pushRecv);
Http2Response preEmptive = Http2Requests.createResponse(push.getPromisedStreamId());
pushWriter.processPushResponse(preEmptive);
Http2Headers preEmptRecv = (Http2Headers) mockChannel.getFrameAndClear();
Assert.assertEquals(preEmptive, preEmptRecv);
Http2Response response = Http2Requests.createResponse(request1.getStreamId());
incoming.stream.sendResponse(response);
Http2Headers responseRecv = (Http2Headers) mockChannel.getFrameAndClear();
Assert.assertEquals(response, responseRecv);
}
use of com.webpieces.hpack.api.dto.Http2Push in project webpieces by deanhiller.
the class TestC5_1StreamStates 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(CompletableFuture.<Void>completedFuture(null));
MockResponseListener listener1 = new MockResponseListener();
listener1.setIncomingRespDefault(CompletableFuture.<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());
}
use of com.webpieces.hpack.api.dto.Http2Push in project webpieces by deanhiller.
the class TestC5_1StreamStates 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;
}
Aggregations