Search in sources :

Example 66 with Http2Request

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

the class TestBackpressure method testBasicBackpressureChunked.

@Test
public void testBasicBackpressureChunked() throws InterruptedException, ExecutionException, TimeoutException {
    MockResponseListener listener = new MockResponseListener();
    RequestStreamHandle handle = httpSocket.openStream();
    mockChannel.addWriteResponse(XFuture.completedFuture(null));
    Http2Request request = Requests.createRequest();
    StreamRef streamRef = handle.process(request, listener);
    XFuture<StreamWriter> writer = streamRef.getWriter();
    Assert.assertTrue(writer.isDone());
    Assert.assertEquals(request, mockChannel.getFrameAndClear());
    List<ByteBuffer> buffers = create4BuffersWith3Messags();
    DataListener dataListener = mockChannel.getConnectedListener();
    XFuture<Void> fut1 = dataListener.incomingData(mockChannel, buffers.get(0));
    // consume since not enough data for client
    Assert.assertTrue(fut1.isDone());
    XFuture<StreamWriter> future = new XFuture<StreamWriter>();
    listener.addReturnValueIncomingResponse(future);
    XFuture<Void> fut2 = dataListener.incomingData(mockChannel, buffers.get(1));
    // not resolved yet since client only has part of the data
    Assert.assertFalse(fut2.isDone());
    MockStreamWriter mockWriter = new MockStreamWriter();
    // This releases the response msg acking 10 bytes
    future.complete(mockWriter);
    fut2.get(2, TimeUnit.SECONDS);
    // feed the rest of first chunk in and feed part of last chunk
    XFuture<Void> firstChunkAck = new XFuture<Void>();
    mockWriter.addProcessResponse(firstChunkAck);
    XFuture<Void> fut3 = dataListener.incomingData(mockChannel, buffers.get(2));
    Assert.assertFalse(fut3.isDone());
    // ack the http chunk packet
    firstChunkAck.complete(null);
    fut3.get(2, TimeUnit.SECONDS);
    XFuture<Void> lastChunkAck = new XFuture<Void>();
    mockWriter.addProcessResponse(lastChunkAck);
    XFuture<Void> fut4 = dataListener.incomingData(mockChannel, buffers.get(3));
    Assert.assertFalse(fut4.isDone());
    lastChunkAck.complete(null);
    fut4.get(2, TimeUnit.SECONDS);
}
Also used : XFuture(org.webpieces.util.futures.XFuture) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) ByteBuffer(java.nio.ByteBuffer) RequestStreamHandle(com.webpieces.http2.api.streaming.RequestStreamHandle) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) DataListener(org.webpieces.nio.api.handlers.DataListener) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) Test(org.junit.Test) AbstractTest(org.webpieces.http2client.AbstractTest)

Example 67 with Http2Request

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

the class IntegColoradoEdu method createRequest.

private static Http2Request createRequest(String host) {
    // GET / HTTP/1.1
    // Host: www.colorado.edu
    // User-Agent: curl/7.43.0
    // Accept: */*
    // 
    // HttpRequestLine requestLine = new HttpRequestLine();
    // requestLine.setMethod(KnownHttpMethod.GET);
    // requestLine.setUri(new HttpUri("/"));
    // 
    // HttpRequest req = new HttpRequest();
    // req.setRequestLine(requestLine);
    // req.addHeader(new Header(KnownHeaderName.HOST, host));
    // req.addHeader(new Header(KnownHeaderName.ACCEPT, "*/*"));
    // req.addHeader(new Header(KnownHeaderName.USER_AGENT, "webpieces/0.9"));
    Http2Request req = new Http2Request();
    req.addHeader(new Http2Header(Http2HeaderName.METHOD, "GET"));
    req.addHeader(new Http2Header(Http2HeaderName.PATH, "GET"));
    req.addHeader(new Http2Header(Http2HeaderName.SCHEME, "http"));
    req.addHeader(new Http2Header(Http2HeaderName.AUTHORITY, "www.colorado.edu"));
    req.addHeader(new Http2Header(Http2HeaderName.USER_AGENT, "webpieces/0.9"));
    req.addHeader(new Http2Header(Http2HeaderName.ACCEPT, "*/*"));
    return req;
}
Also used : Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 68 with Http2Request

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

the class AbstractTest method sendRequestToServer.

protected Http2Request sendRequestToServer(MockResponseListener listener1) {
    Http2Request request1 = Requests.createRequest();
    httpSocket.openStream().process(request1, listener1);
    Http2Msg req = mockChannel.getFrameAndClear();
    Assert.assertEquals(request1, req);
    return request1;
}
Also used : Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)

Example 69 with Http2Request

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

the class Level8NotifySvrListeners method fireRequestToApp.

public XFuture<Void> fireRequestToApp(ServerStream stream, Http2Request payload) {
    SvrSideResponseHandler handler = new SvrSideResponseHandler(level1ServerEngine, stream, pushIdGenerator);
    RequestStreamHandle streamHandle = listener.openStream();
    StreamRef streamRef = streamHandle.process(payload, handler);
    stream.setStreamHandle(streamHandle, streamRef);
    return streamRef.getWriter().thenApply(w -> null);
}
Also used : RequestStreamHandle(com.webpieces.http2.api.streaming.RequestStreamHandle) StreamRef(com.webpieces.http2.api.streaming.StreamRef)

Example 70 with Http2Request

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

the class Requests method createBaseRequest.

public static Http2Request createBaseRequest(String method, String scheme, String path) {
    Http2Request req = new Http2Request();
    req.addHeader(new Http2Header(Http2HeaderName.AUTHORITY, "yourdomain.com"));
    req.addHeader(new Http2Header(Http2HeaderName.SCHEME, scheme));
    req.addHeader(new Http2Header(Http2HeaderName.METHOD, method));
    req.addHeader(new Http2Header(Http2HeaderName.PATH, path));
    return req;
}
Also used : Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

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