use of com.webpieces.http2.api.dto.highlevel.Http2Headers 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(), f.isEndOfStream());
fullHeaders.setStreamId(f.getStreamId());
fullHeaders.setPriorityDetails(f.getPriorityDetails());
fullHeaders.setEndOfStream(f.isEndOfStream());
state.addParsedMessage(fullHeaders);
} else if (firstFrame instanceof PushPromiseFrame) {
PushPromiseFrame f = (PushPromiseFrame) firstFrame;
Http2Push fullHeaders = new Http2Push(headers);
fullHeaders.setStreamId(f.getStreamId());
fullHeaders.setPromisedStreamId(f.getPromisedStreamId());
state.addParsedMessage(fullHeaders);
}
hasHeaderFragmentList.clear();
}
use of com.webpieces.http2.api.dto.highlevel.Http2Headers 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);
}
use of com.webpieces.http2.api.dto.highlevel.Http2Headers in project webpieces by deanhiller.
the class TestCMaxConcurrentSetting method testSend2ndRequestOnlyOnCompletionOfFirst.
@Test
public void testSend2ndRequestOnlyOnCompletionOfFirst() throws InterruptedException, ExecutionException {
RequestsSent sent = sendTwoRequests();
int streamId1 = sent.getRequest1().getRequest().getStreamId();
XFuture<StreamWriter> future2 = sent.getRequest2().getFuture();
RequestHolder holder1 = sent.getRequest1();
RequestHolder holder2 = sent.getRequest2();
MockResponseListener listener1 = holder1.getListener();
MockStreamWriter writer1 = holder1.getWriter();
// endOfStream=false
mockChannel.write(Requests.createResponse(streamId1));
listener1.getSingleReturnValueIncomingResponse();
// endOfStream=false
mockChannel.write(new DataFrame(streamId1, false));
writer1.getSingleFrame();
// at this point, should not have a call outstanding
mockChannel.assertNoIncomingMessages();
Assert.assertFalse(future2.isDone());
MockResponseListener listener2 = holder2.getListener();
MockStreamWriter writer2 = holder2.getWriter();
listener2.addReturnValueIncomingResponse(XFuture.completedFuture(writer2));
Assert.assertFalse(future2.isDone());
DataFrame dataFrame = new DataFrame(streamId1, true);
// endOfStream = true
mockChannel.write(dataFrame);
StreamMsg data = writer1.getSingleFrame();
Assert.assertEquals(dataFrame.getStreamId(), data.getStreamId());
Http2Headers frame = (Http2Headers) mockChannel.getFrameAndClear();
Assert.assertEquals(sent.getRequest2().getRequest(), frame);
Assert.assertTrue(future2.isDone());
}
use of com.webpieces.http2.api.dto.highlevel.Http2Headers in project webpieces by deanhiller.
the class LoginFilter method addCacheHeaders.
private Object addCacheHeaders(Object response) {
Http2Headers resp = (Http2Headers) response;
// http://stackoverflow.com/questions/49547/how-to-control-web-page-caching-across-all-browsers
// This forces the browser back button to re-request the page as it would never have the page
// and is good to use to hide banking information type pages
// resp.addHeader(new Header(KnownHeaderName.CACHE_CONTROL, "no-store"));
resp.addHeader(new Http2Header(Http2HeaderName.CACHE_CONTROL, "no-cache, no-store, must-revalidate"));
resp.addHeader(new Http2Header(Http2HeaderName.PRAGMA, "no-cache"));
resp.addHeader(new Http2Header(Http2HeaderName.EXPIRES, "0"));
return resp;
}
use of com.webpieces.http2.api.dto.highlevel.Http2Headers 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());
XFuture<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.process(response);
Http2Headers responseRecv = (Http2Headers) mockChannel.getFrameAndClear();
Assert.assertEquals(response, responseRecv);
}
Aggregations