use of com.webpieces.hpack.api.dto.Http2Push in project webpieces by deanhiller.
the class AbstractTest method sendPushPromise.
protected void sendPushPromise(MockResponseListener listener1, int streamId, boolean eos) {
MockPushListener pushListener = new MockPushListener();
pushListener.setDefaultResponse(CompletableFuture.completedFuture(null));
listener1.addReturnValuePush(pushListener);
Http2Push push = Requests.createPush(streamId);
//endOfStream=false
mockChannel.write(push);
Assert.assertEquals(push, listener1.getSinglePush());
Http2Response preemptiveResponse = Requests.createEosResponse(2);
mockChannel.write(preemptiveResponse);
Http2Response frame2 = (Http2Response) pushListener.getSingleParam();
Assert.assertEquals(preemptiveResponse, frame2);
}
use of com.webpieces.hpack.api.dto.Http2Push in project webpieces by deanhiller.
the class TestSMaxConcurrentSetting method sendTwoRequests.
private WriterHolder sendTwoRequests() throws InterruptedException, ExecutionException, TimeoutException {
PassedIn in1 = sendRequestToServer(1, true);
PassedIn in2 = sendRequestToServer(3, true);
Assert.assertTrue(in1.stream != in2.stream);
Http2Push push1 = Http2Requests.createPush(in1.request.getStreamId());
CompletableFuture<PushPromiseListener> future1 = in1.stream.openPushStream().process(push1);
Http2Msg push1Recv = mockChannel.getFrameAndClear();
Assert.assertEquals(push1, push1Recv);
PushPromiseListener pushWriter1 = future1.get(2, TimeUnit.SECONDS);
Http2Push push2 = Http2Requests.createPush(in2.request.getStreamId());
CompletableFuture<PushPromiseListener> future2 = in2.stream.openPushStream().process(push2);
Http2Msg push2Recv = mockChannel.getFrameAndClear();
Assert.assertEquals(push2, push2Recv);
Assert.assertEquals(push1, push1Recv);
PushPromiseListener writer2 = future2.get(2, TimeUnit.SECONDS);
//send the two responses following the pushes
Http2Response resp1 = Http2Requests.createResponse(push1.getPromisedStreamId(), false);
CompletableFuture<StreamWriter> fut1 = pushWriter1.processPushResponse(resp1);
StreamWriter writer1 = fut1.get(2, TimeUnit.SECONDS);
Http2Response resp2 = Http2Requests.createResponse(push2.getPromisedStreamId(), false);
CompletableFuture<StreamWriter> fut2 = writer2.processPushResponse(resp2);
Assert.assertTrue(!fut2.isDone());
Http2Response clientRecvResp = (Http2Response) mockChannel.getFrameAndClear();
Assert.assertEquals(resp1, clientRecvResp);
return new WriterHolder(writer1, fut2, resp1, resp2);
}
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 HpackParserImpl method combineAndSendHeadersToClient.
private void combineAndSendHeadersToClient(UnmarshalStateImpl state) {
List<HasHeaderFragment> hasHeaderFragmentList = state.getHeadersToCombine();
// Now we set the full header list on the first frame and just return that
HasHeaderFragment firstFrame = hasHeaderFragmentList.get(0);
DataWrapper allSerializedHeaders = dataGen.emptyWrapper();
for (HasHeaderFragment iterFrame : hasHeaderFragmentList) {
allSerializedHeaders = dataGen.chainDataWrappers(allSerializedHeaders, iterFrame.getHeaderFragment());
}
Map<Http2HeaderName, Http2Header> knownHeaders = new HashMap<>();
List<Http2Header> headers = decoding.decode(state, allSerializedHeaders, firstFrame.getStreamId(), header -> knownHeaders.put(header.getKnownName(), header));
if (firstFrame instanceof HeadersFrame) {
HeadersFrame f = (HeadersFrame) firstFrame;
Http2Headers fullHeaders = createCorrectType(knownHeaders, headers, state.getLogId(), f.getStreamId());
fullHeaders.setStreamId(f.getStreamId());
fullHeaders.setPriorityDetails(f.getPriorityDetails());
fullHeaders.setEndOfStream(f.isEndOfStream());
state.getParsedFrames().add(fullHeaders);
} else if (firstFrame instanceof PushPromiseFrame) {
PushPromiseFrame f = (PushPromiseFrame) firstFrame;
Http2Push fullHeaders = new Http2Push(headers);
fullHeaders.setStreamId(f.getStreamId());
fullHeaders.setPromisedStreamId(f.getPromisedStreamId());
state.getParsedFrames().add(fullHeaders);
}
hasHeaderFragmentList.clear();
}
Aggregations