Search in sources :

Example 11 with Http2Header

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);
}
Also used : BufferPool(org.webpieces.data.api.BufferPool) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) LoggerFactory(org.slf4j.LoggerFactory) BackpressureConfig(org.webpieces.nio.api.BackpressureConfig) Http2ClientFactory(org.webpieces.http2client.api.Http2ClientFactory) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) ChannelManager(org.webpieces.nio.api.ChannelManager) Metrics(io.micrometer.core.instrument.Metrics) ArrayList(java.util.ArrayList) SSLEngine(javax.net.ssl.SSLEngine) ResponseStreamHandle(com.webpieces.http2.api.streaming.ResponseStreamHandle) PushPromiseListener(com.webpieces.http2.api.streaming.PushPromiseListener) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) HpackParser(com.webpieces.hpack.api.HpackParser) TwoPools(org.webpieces.data.api.TwoPools) Http2Socket(org.webpieces.http2client.api.Http2Socket) HpackParserFactory(com.webpieces.hpack.api.HpackParserFactory) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) Logger(org.slf4j.Logger) Executor(java.util.concurrent.Executor) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) CancelReason(com.webpieces.http2.api.dto.lowlevel.CancelReason) InetSocketAddress(java.net.InetSocketAddress) Executors(java.util.concurrent.Executors) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) Http2Client(org.webpieces.http2client.api.Http2Client) List(java.util.List) XFuture(org.webpieces.util.futures.XFuture) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) Http2HeaderName(com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName) PushStreamHandle(com.webpieces.http2.api.streaming.PushStreamHandle) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) InetSocketAddress(java.net.InetSocketAddress) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) Http2Socket(org.webpieces.http2client.api.Http2Socket)

Example 12 with Http2Header

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;
}
Also used : Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) ArrayList(java.util.ArrayList)

Example 13 with Http2Header

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());
}
Also used : RequestStreamHandle(com.webpieces.http2.api.streaming.RequestStreamHandle) StreamRef(com.webpieces.http2.api.streaming.StreamRef) CancelReason(com.webpieces.http2.api.dto.lowlevel.CancelReason) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) RstStreamFrame(com.webpieces.http2.api.dto.lowlevel.RstStreamFrame) InetSocketAddress(java.net.InetSocketAddress) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) MockResponseListener(org.webpieces.httpclient.api.mocks.MockResponseListener) Test(org.junit.Test)

Example 14 with Http2Header

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;
}
Also used : Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) ArrayList(java.util.ArrayList)

Example 15 with Http2Header

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;
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) ArrayList(java.util.ArrayList)

Aggregations

Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)72 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)26 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)23 ArrayList (java.util.ArrayList)23 DataWrapper (org.webpieces.data.api.DataWrapper)9 Http2HeaderName (com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName)8 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)8 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)7 XFuture (org.webpieces.util.futures.XFuture)7 InetSocketAddress (java.net.InetSocketAddress)6 Header (org.webpieces.httpparser.api.common.Header)6 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)5 Http2Frame (com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)5 StreamRef (com.webpieces.http2.api.streaming.StreamRef)5 List (java.util.List)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 ResponseStreamHandle (com.webpieces.http2.api.streaming.ResponseStreamHandle)4 Executor (java.util.concurrent.Executor)4 Executors (java.util.concurrent.Executors)4