Search in sources :

Example 6 with Http2Headers

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();
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) HasHeaderFragment(com.webpieces.http2.api.dto.lowlevel.lib.HasHeaderFragment) HashMap(java.util.HashMap) Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) Http2HeaderName(com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) PushPromiseFrame(com.webpieces.http2.api.dto.lowlevel.PushPromiseFrame) HeadersFrame(com.webpieces.http2.api.dto.lowlevel.HeadersFrame)

Example 7 with Http2Headers

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);
}
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 8 with Http2Headers

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());
}
Also used : StreamMsg(com.webpieces.http2.api.dto.lowlevel.lib.StreamMsg) Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) RequestsSent(org.webpieces.http2client.util.RequestsSent) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) RequestHolder(org.webpieces.http2client.util.RequestHolder) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) Test(org.junit.Test)

Example 9 with Http2Headers

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;
}
Also used : Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 10 with Http2Headers

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);
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) PushPromiseListener(com.webpieces.http2.api.streaming.PushPromiseListener) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Aggregations

Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)8 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)4 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)4 Test (org.junit.Test)4 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)3 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)3 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)2 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)2 HeadersFrame (com.webpieces.http2.api.dto.lowlevel.HeadersFrame)2 Http2Frame (com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)2 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)2 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)2 Encoder (com.twitter.hpack.Encoder)1 Http2HeaderStruct (com.webpieces.http2.api.dto.highlevel.Http2HeaderStruct)1 Http2Trailers (com.webpieces.http2.api.dto.highlevel.Http2Trailers)1 PushPromiseFrame (com.webpieces.http2.api.dto.lowlevel.PushPromiseFrame)1 HasHeaderFragment (com.webpieces.http2.api.dto.lowlevel.lib.HasHeaderFragment)1 Http2HeaderName (com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName)1 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)1 StreamMsg (com.webpieces.http2.api.dto.lowlevel.lib.StreamMsg)1