Search in sources :

Example 21 with Http2Response

use of com.webpieces.http2.api.dto.highlevel.Http2Response 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(XFuture.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);
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) MockPushListener(org.webpieces.http2client.mock.MockPushListener)

Example 22 with Http2Response

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

the class AbstractTest method sendResponseFromServer.

protected void sendResponseFromServer(MockResponseListener listener1, Http2Request request) {
    Http2Response resp1 = Requests.createResponse(request.getStreamId());
    // endOfStream=false
    mockChannel.write(resp1);
    Http2Response response1 = listener1.getSingleReturnValueIncomingResponse();
    Assert.assertEquals(resp1, response1);
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response)

Example 23 with Http2Response

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

the class TestC4FrameSizeAndHeaders method fillHeaders.

private void fillHeaders(Http2Response response1) {
    String value = "heaheaheaheaheaheahahoz.zhxheh,h,he,he,heaheaeaheaheahoahoahozzoqorqzro.zo.zrszaroatroathoathoathoathoatoh";
    for (int i = 0; i < 10; i++) {
        value = value + value;
        response1.addHeader(new Http2Header("eaheahaheaheaeha" + i, value));
    }
}
Also used : Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 24 with Http2Response

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

the class TestC4FrameSizeAndHeaders method createInterleavedFrames.

private List<Http2Frame> createInterleavedFrames() {
    Http2Response response1 = new Http2Response();
    response1.setStreamId(1);
    response1.setEndOfStream(true);
    fillHeaders(response1);
    HeaderEncoding encoding = new HeaderEncoding();
    List<Http2Frame> frames1 = encoding.translateToFrames(localSettings.getMaxFrameSize(), new Encoder(localSettings.getHeaderTableSize()), response1);
    Http2Response response2 = new Http2Response();
    response2.setStreamId(3);
    response1.setEndOfStream(true);
    response2.addHeader(new Http2Header(Http2HeaderName.ACCEPT, "value"));
    List<Http2Frame> frames2 = encoding.translateToFrames(localSettings.getMaxFrameSize(), new Encoder(localSettings.getHeaderTableSize()), response2);
    List<Http2Frame> frames = new ArrayList<>();
    frames.addAll(frames1);
    frames.add(1, frames2.get(0));
    return frames;
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) HeaderEncoding(com.webpieces.hpack.impl.HeaderEncoding) Encoder(com.twitter.hpack.Encoder) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) ArrayList(java.util.ArrayList) Http2Frame(com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)

Example 25 with Http2Response

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

the class TestBasicHttp2Client method testMaxConcurrentOne.

@Test
public void testMaxConcurrentOne() throws InterruptedException, ExecutionException {
    Http2Request request1 = Requests.createRequest();
    Http2Request request2 = Requests.createRequest();
    MockStreamWriter writer1 = new MockStreamWriter();
    MockResponseListener respListener1 = new MockResponseListener();
    respListener1.setIncomingRespDefault(XFuture.completedFuture(writer1));
    MockResponseListener respListener2 = new MockResponseListener();
    StreamRef streamRef1 = httpSocket.openStream().process(request1, respListener1);
    XFuture<StreamWriter> future = streamRef1.getWriter();
    StreamRef streamRef2 = httpSocket.openStream().process(request2, respListener2);
    XFuture<StreamWriter> future2 = streamRef2.getWriter();
    // max concurrent only 1 so only get 1
    Http2Request req = (Http2Request) mockChannel.getFrameAndClear();
    Assert.assertEquals(1, req.getStreamId());
    Assert.assertEquals(request1, req);
    Assert.assertTrue(future.isDone());
    // do not ack upstream until out the door(backpressure)
    Assert.assertFalse(future2.isDone());
    Http2Response resp1 = Requests.createResponse(request1.getStreamId());
    // endOfStream=false
    mockChannel.write(resp1);
    Http2Response response1 = respListener1.getSingleReturnValueIncomingResponse();
    Assert.assertEquals(resp1, response1);
    Assert.assertFalse(future2.isDone());
    // endOfStream=false
    mockChannel.write(new DataFrame(request1.getStreamId(), false));
    writer1.getSingleFrame();
    // at this point, should not have a call outstanding
    mockChannel.assertNoIncomingMessages();
    // WRITE OUT END STREAM data so the first request starts going again!!
    Assert.assertFalse(future2.isDone());
    DataFrame dataLast = new DataFrame(request1.getStreamId(), true);
    // endOfStream = true
    mockChannel.write(dataLast);
    Assert.assertTrue(future2.isDone());
    DataFrame data = (DataFrame) writer1.getSingleFrame();
    Assert.assertEquals(dataLast.getStreamId(), data.getStreamId());
    Http2Request req2 = (Http2Request) mockChannel.getFrameAndClear();
    Assert.assertEquals(request2, req2);
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) Test(org.junit.Test)

Aggregations

Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)66 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)32 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)30 Test (org.junit.Test)30 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)24 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)16 StreamRef (com.webpieces.http2.api.streaming.StreamRef)15 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)14 DataWrapper (org.webpieces.data.api.DataWrapper)13 Header (org.webpieces.httpparser.api.common.Header)13 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)12 ArrayList (java.util.ArrayList)10 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)10 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)9 HttpPayload (org.webpieces.httpparser.api.dto.HttpPayload)9 HttpData (org.webpieces.httpparser.api.dto.HttpData)8 XFuture (org.webpieces.util.futures.XFuture)8 RouterService (org.webpieces.router.api.RouterService)5 Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)4 Http2HeaderName (com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName)4