use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.
the class TestSBasicRequestResponse method testWithDataAndTrailingHeaders.
@Test
public void testWithDataAndTrailingHeaders() throws InterruptedException, ExecutionException, TimeoutException {
MockStreamWriter mockSw = new MockStreamWriter();
mockSw.setDefaultRetValToThis();
mockListener.addMockStreamToReturn(mockSw);
Http2Request request1 = Http2Requests.createRequest(1, false);
DataFrame data1 = Http2Requests.createData1(request1.getStreamId(), false);
Http2Trailers trailing = Http2Requests.createTrailers(request1.getStreamId());
mockChannel.send(request1);
PassedIn incoming1 = mockListener.getSingleRequest();
Assert.assertEquals(request1, incoming1.request);
mockChannel.send(data1);
DataFrame incoming2 = (DataFrame) mockSw.getSingleFrame();
Assert.assertEquals(3, incoming2.getData().getReadableSize());
//clear window update frames
Assert.assertEquals(2, mockChannel.getFramesAndClear().size());
mockChannel.send(trailing);
Http2Headers incoming = (Http2Headers) mockSw.getSingleFrame();
Assert.assertEquals(trailing, incoming);
Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), false);
CompletableFuture<StreamWriter> future = incoming1.stream.sendResponse(resp);
Http2Msg response = mockChannel.getFrameAndClear();
Assert.assertEquals(resp, response);
StreamWriter writer = future.get(2, TimeUnit.SECONDS);
DataFrame data2 = Http2Requests.createData2(request1.getStreamId(), false);
writer.processPiece(data2);
DataFrame dataResp = (DataFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(1, dataResp.getData().getReadableSize());
Http2Trailers trailingResp = Http2Requests.createTrailers(request1.getStreamId());
writer.processPiece(trailingResp);
Http2Headers trailers = (Http2Headers) mockChannel.getFrameAndClear();
Assert.assertEquals(trailingResp, trailers);
}
use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.
the class TestSBasicRequestResponse method testWithData.
@Test
public void testWithData() throws InterruptedException, ExecutionException, TimeoutException {
MockStreamWriter mockSw = new MockStreamWriter();
mockSw.setDefaultRetValToThis();
mockListener.addMockStreamToReturn(mockSw);
Http2Request request1 = Http2Requests.createRequest(1, false);
DataFrame data = Http2Requests.createData1(request1.getStreamId(), true);
mockChannel.send(request1);
PassedIn incoming1 = mockListener.getSingleRequest();
Assert.assertEquals(request1, incoming1.request);
mockChannel.send(data);
DataFrame incoming = (DataFrame) mockSw.getSingleFrame();
Assert.assertEquals(3, incoming.getData().getReadableSize());
//clear window update frames
Assert.assertEquals(2, mockChannel.getFramesAndClear().size());
Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), false);
CompletableFuture<StreamWriter> future = incoming1.stream.sendResponse(resp);
Http2Msg response = mockChannel.getFrameAndClear();
Assert.assertEquals(resp, response);
StreamWriter writer = future.get(2, TimeUnit.SECONDS);
DataFrame data2 = Http2Requests.createData2(request1.getStreamId(), true);
writer.processPiece(data2);
DataFrame dataResp = (DataFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(1, dataResp.getData().getReadableSize());
}
use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.
the class IntegSingleRequest method start.
public void start() throws InterruptedException {
log.info("starting test to download / page from google");
boolean isHttp = true;
String host = "www.google.com";
//String host = "localhost"; //jetty
//String host = "api.push.apple.com";
//String host = "gcm-http.googleapis.com";
//String host = "nghttp2.org";
int port = 443;
if (isHttp)
port = 80;
if ("localhost".equals(host)) {
port = 8443;
if (isHttp)
port = 8080;
}
List<Http2Header> req = createRequest(host, isHttp);
Http2Request request = new Http2Request(req);
request.setEndOfStream(true);
InetSocketAddress addr = new InetSocketAddress(host, port);
Http2Socket socket = createHttpClient("testRunSocket", isHttp, addr);
socket.connect(addr).thenAccept(s -> s.openStream().process(request, new ChunkedResponseListener())).exceptionally(e -> reportException(socket, e));
Thread.sleep(10000000);
}
use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.
the class IntegColoradoEdu method main.
public static void main(String[] args) throws InterruptedException {
boolean isHttp = true;
String host = "www.colorado.edu";
int port = 443;
if (isHttp)
port = 80;
Http2Request req = createRequest(host);
log.info("starting socket");
ChunkedResponseListener listener = new ChunkedResponseListener();
InetSocketAddress addr = new InetSocketAddress(host, port);
Http2Socket socket = IntegSingleRequest.createHttpClient("oneTimerHttp2Socket", isHttp, addr);
socket.connect(addr).thenAccept(socet -> socket.openStream().process(req, listener)).exceptionally(e -> reportException(socket, e));
Thread.sleep(100000);
}
use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.
the class Http2Requests method createRequest.
public static Http2Request createRequest(int streamId, boolean eos) {
List<Http2Header> headers = new ArrayList<>();
headers.add(new Http2Header(Http2HeaderName.METHOD, "GET"));
headers.add(new Http2Header(Http2HeaderName.AUTHORITY, "somehost.com"));
headers.add(new Http2Header(Http2HeaderName.PATH, "/"));
headers.add(new Http2Header(Http2HeaderName.SCHEME, "http"));
headers.add(new Http2Header(Http2HeaderName.HOST, "somehost.com"));
headers.add(new Http2Header(Http2HeaderName.ACCEPT, "*/*"));
headers.add(new Http2Header(Http2HeaderName.ACCEPT_ENCODING, "gzip, deflate"));
headers.add(new Http2Header(Http2HeaderName.USER_AGENT, "webpieces/1.15.0"));
Http2Request request = new Http2Request(headers);
request.setStreamId(streamId);
request.setEndOfStream(eos);
return request;
}
Aggregations