Search in sources :

Example 81 with Http2Request

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

the class RouterRequest method getHeaders.

/**
 * Need to remove webpieces http2 stack from router(ie. Http2Request above and Http2Headers!!!!!!)
 * This is a step towards that to only
 * have RouterRequest which is the bare minimum object to allow router to do it's job.  In this way,
 * router is a piece that can work with an http stack(apache, etc. etc.) and a true piece to be
 * re-used.
 *
 * For now, http2 headers is too tightly coupled for worry about while we get this working so this is
 * at least one point of decoupling.  Steps...
 * Step 1. create all read points to read from methods like this reading in objects from org.webpieces.ctx.api
 * Step 2. figure out how to better translate from ANY http2/http1 into RouterRequest in
 *         the webserver connection layer
 * Step 3. Make these fields Object so any platform can insert their http2 or http1 objects
 *         public Http2Request originalRequest;
 * 	       public Http2Headers trailingHeaders;
 */
public synchronized Map<String, List<RouterHeader>> getHeaders() {
    if (routerHeaderMap != null)
        return routerHeaderMap;
    else if (originalRequest == null)
        // some legacy tests at Orderly simulate with no original request
        return routerHeaderMap;
    routerHeaderMap = new HashMap<>();
    // DO NOT cache this as there are clients that modify the Http2Header which will not
    // modify this list so just generate this list every time for now.
    // In webpieces getHeaders is only called once every request anyways!!!
    Http2HeaderStruct headerLookupStruct = originalRequest.getHeaderLookupStruct();
    for (String headerName : headerLookupStruct.getAllHeaderNames()) {
        // http is well, 'interesting' allowing one to repeat header names and if I remember
        // order matters and we keep the order
        List<Http2Header> headerArray = headerLookupStruct.getHeaders(headerName);
        List<RouterHeader> translatedList = translate(headerArray);
        routerHeaderMap.put(headerName, translatedList);
    }
    return routerHeaderMap;
}
Also used : Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) Http2HeaderStruct(com.webpieces.http2.api.dto.highlevel.Http2HeaderStruct)

Example 82 with Http2Request

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

the class TestLesson8JsonHttp2 method createRequest.

public static FullRequest createRequest(String uri, DataWrapper body) {
    Http2Request req = new Http2Request();
    req.addHeader(new Http2Header(Http2HeaderName.AUTHORITY, "yourdomain.com"));
    req.addHeader(new Http2Header(Http2HeaderName.SCHEME, "https"));
    req.addHeader(new Http2Header(Http2HeaderName.METHOD, "GET"));
    req.addHeader(new Http2Header(Http2HeaderName.PATH, uri));
    req.addHeader(new Http2Header(Http2HeaderName.CONTENT_LENGTH, body.getReadableSize() + ""));
    FullRequest fullReq = new FullRequest(req, body, null);
    return fullReq;
}
Also used : Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) FullRequest(org.webpieces.http2client.api.dto.FullRequest)

Example 83 with Http2Request

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

the class WebpiecesStreamHandle method incomingRequest.

@Override
public StreamRef incomingRequest(Http2Request headers, ResponseStream stream) {
    RouterResponseHandler handler = new RouterResponseHandlerImpl(stream);
    StreamRef ref = routingService.incomingRequest(headers, handler);
    return ref;
}
Also used : StreamRef(com.webpieces.http2.api.streaming.StreamRef) RouterResponseHandler(org.webpieces.router.api.RouterResponseHandler)

Example 84 with Http2Request

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

the class TestC5x1StreamStates method testSection5_1ReceiveValidFramesAfterSendRstStreamFrame.

/**
 * If this state is reached as a result of sending a RST_STREAM frame, the
 * peer that receives the RST_STREAM might have already sent — or enqueued for
 * sending — frames on the stream that cannot be withdrawn. An endpoint MUST ignore
 * frames that it receives on closed streams after it has sent a RST_STREAM frame. An
 * endpoint MAY choose to limit the period over which it ignores frames and
 * treat frames that arrive after this time as being in error.
 * @throws TimeoutException
 * @throws ExecutionException
 * @throws InterruptedException
 */
@Test
public void testSection5_1ReceiveValidFramesAfterSendRstStreamFrame() throws InterruptedException, ExecutionException, TimeoutException {
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(null));
    Http2Request request1 = Requests.createRequest();
    RequestStreamHandle stream = httpSocket.openStream();
    StreamRef streamRef = httpSocket.openStream().process(request1, listener1);
    XFuture<StreamWriter> future = streamRef.getWriter();
    @SuppressWarnings("unused") StreamWriter writer = future.get(2, TimeUnit.SECONDS);
    Http2Msg req = mockChannel.getFrameAndClear();
    Assert.assertEquals(request1, req);
    RstStreamFrame rst = new RstStreamFrame(request1.getStreamId(), Http2ErrorCode.CANCEL);
    XFuture<Void> cancel = streamRef.cancel(rst);
    cancel.get(2, TimeUnit.SECONDS);
    Http2Msg svrRst = mockChannel.getFrameAndClear();
    Assert.assertEquals(rst, svrRst);
    // simulate server responding before receiving the cancel
    Http2Response resp1 = Requests.createEosResponse(request1.getStreamId());
    // endOfStream=true
    mockChannel.write(resp1);
// Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
// Assert.assertFalse(mockChannel.isClosed());
// 
// Assert.assertEquals(0, listener1.getReturnValuesIncomingResponse().size());
}
Also used : RequestStreamHandle(com.webpieces.http2.api.streaming.RequestStreamHandle) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) RstStreamFrame(com.webpieces.http2.api.dto.lowlevel.RstStreamFrame) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) Test(org.junit.Test)

Example 85 with Http2Request

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

the class TestC5x1StreamStates method testSection5_1ReceivePriorityAfterReceiveRstStreamFrame.

/**
 * An endpoint MUST NOT send frames other than ----PRIORITY---- on a closed stream. An endpoint
 * that receives any frame other than ----PRIORITY---- after receiving a ----RST_STREAM---- MUST
 * treat that as a stream error (Section 5.4.2) of type STREAM_CLOSED. Similarly, an
 * endpoint that receives any frames after receiving a frame with the
 * END_STREAM flag set MUST treat that as a connection error (Section 5.4.1) of
 * type STREAM_CLOSED, unless the frame is permitted as described below.
 */
@Test
public void testSection5_1ReceivePriorityAfterReceiveRstStreamFrame() {
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(null));
    Http2Request request = sendRequestToServer(listener1);
    sendResetFromServer(listener1, request);
    PriorityDetails details = new PriorityDetails();
    details.setStreamDependency(3);
    PriorityFrame dataFrame = new PriorityFrame(request.getStreamId(), details);
    mockChannel.write(dataFrame);
    // priority is ignored
    Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
    Assert.assertFalse(mockChannel.isClosed());
    Assert.assertEquals(0, listener1.getReturnValuesIncomingResponse().size());
}
Also used : Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) PriorityDetails(com.webpieces.http2.api.dto.lowlevel.lib.PriorityDetails) PriorityFrame(com.webpieces.http2.api.dto.lowlevel.PriorityFrame) Test(org.junit.Test)

Aggregations

Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)71 Test (org.junit.Test)39 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)36 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)36 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)33 StreamRef (com.webpieces.http2.api.streaming.StreamRef)32 DataWrapper (org.webpieces.data.api.DataWrapper)18 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)14 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)14 XFuture (org.webpieces.util.futures.XFuture)13 RequestStreamHandle (com.webpieces.http2.api.streaming.RequestStreamHandle)11 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)10 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)10 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)9 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)9 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)9 InetSocketAddress (java.net.InetSocketAddress)8 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)7 MockStreamWriter (org.webpieces.httpfrontend2.api.mock2.MockStreamWriter)7 Http2HeaderName (com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName)6