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);
}
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;
}
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;
}
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);
}
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;
}
Aggregations