use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header 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(v -> socket.openStream().process(request, new ChunkedResponseListener())).exceptionally(e -> reportException(socket, e));
Thread.sleep(10000000);
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class IntegSingleRequest method createRequest.
private static List<Http2Header> createRequest(String host, boolean isHttp) {
String scheme;
if (isHttp)
scheme = "http";
else
scheme = "https";
List<Http2Header> headers = new ArrayList<>();
headers.add(new Http2Header(Http2HeaderName.METHOD, "GET"));
headers.add(new Http2Header(Http2HeaderName.AUTHORITY, host));
headers.add(new Http2Header(Http2HeaderName.PATH, "/"));
headers.add(new Http2Header(Http2HeaderName.SCHEME, scheme));
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"));
return headers;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class TestCancelStream method testClientCancelWithKeepAlive.
// @Test
// public void testRequestResponseXFutureCancelNoKeepAlive() {
// throw new UnsupportedOperationException("not done yet");
// }
//
// @Test
// public void testRequestResponseXFutureCancelWithKeepAlive() {
// throw new UnsupportedOperationException("not done yet");
// }
@Test
public void testClientCancelWithKeepAlive() {
XFuture<Void> connect = httpSocket.connect(new InetSocketAddress(8555));
MockResponseListener mockListener = new MockResponseListener();
Http2Request req = Requests.createRequest(false);
req.addHeader(new Http2Header(Http2HeaderName.CONNECTION, "keep-alive"));
mockChannel.addWriteResponse(XFuture.completedFuture(null));
RequestStreamHandle requestStream = httpSocket.openStream();
StreamRef ref = requestStream.process(req, mockListener);
CancelReason reason = new RstStreamFrame();
XFuture<Void> cancelDone = ref.cancel(reason);
Assert.assertTrue(cancelDone.isDone());
// Assert the socket is NOT closed
Assert.assertFalse(mockChannel.isClosed());
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class Requests method createRequest.
static Http2Request createRequest(boolean eos) {
List<Http2Header> headers = new ArrayList<>();
headers.add(new Http2Header(Http2HeaderName.METHOD, "GET"));
headers.add(new Http2Header(Http2HeaderName.PATH, "/"));
headers.add(new Http2Header(Http2HeaderName.SCHEME, "http"));
headers.add(new Http2Header(Http2HeaderName.AUTHORITY, "somehost.com"));
headers.add(new Http2Header("serverid", "1"));
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.setEndOfStream(eos);
return request;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class Requests method createResponse.
public static Http2Response createResponse(int id, int contentLength) {
List<Http2Header> headers = new ArrayList<>();
headers.add(new Http2Header(Http2HeaderName.STATUS, "200"));
headers.add(new Http2Header(Http2HeaderName.SERVER, id + ""));
headers.add(new Http2Header(Http2HeaderName.CONTENT_LENGTH, contentLength + ""));
Http2Response response = new Http2Response(headers);
if (contentLength == 0)
response.setEndOfStream(true);
return response;
}
Aggregations