Search in sources :

Example 56 with Http2Header

use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.

the class IntegMultiThreaded method main.

public static void main(String[] args) throws InterruptedException {
    boolean isHttp = true;
    String path = "/";
    // String host = www.google.com;
    // String host = "localhost"; //jetty
    String host = "nghttp2.org";
    int port = 443;
    if (isHttp)
        port = 80;
    if (host.equals("localhost")) {
        // IF jetty, use a path with a bigger download
        path = "/test/data.txt";
        port = 8443;
        if (isHttp)
            port = 8080;
    }
    List<Http2Header> req = createRequest(host, isHttp, path);
    log.info("starting socket");
    InetSocketAddress addr = new InetSocketAddress(host, port);
    Http2Socket socket = IntegSingleRequest.createHttpClient("clientSocket", isHttp, addr);
    socket.connect(addr).thenApply(s -> {
        for (int i = 0; i < 99; i += 100) {
            executor.execute(new WorkItem(socket, req, i, i));
        }
        return s;
    }).exceptionally(e -> {
        reportException(socket, e);
        return null;
    });
    Thread.sleep(100000000);
}
Also used : Logger(org.slf4j.Logger) SortedSet(java.util.SortedSet) Executor(java.util.concurrent.Executor) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) LoggerFactory(org.slf4j.LoggerFactory) CancelReason(com.webpieces.http2.api.dto.lowlevel.CancelReason) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) InetSocketAddress(java.net.InetSocketAddress) TreeSet(java.util.TreeSet) Executors(java.util.concurrent.Executors) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) ArrayList(java.util.ArrayList) List(java.util.List) XFuture(org.webpieces.util.futures.XFuture) com.webpieces.http2.api.streaming(com.webpieces.http2.api.streaming) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) Http2HeaderName(com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName) Http2Socket(org.webpieces.http2client.api.Http2Socket) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) InetSocketAddress(java.net.InetSocketAddress) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) Http2Socket(org.webpieces.http2client.api.Http2Socket)

Example 57 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 streamId) {
    List<Http2Header> headers = new ArrayList<>();
    headers.add(new Http2Header(Http2HeaderName.STATUS, String.valueOf(StatusCode.HTTP_200_OK.getCode())));
    headers.add(new Http2Header(Http2HeaderName.SERVER, "me"));
    Http2Response response = new Http2Response(headers);
    response.setEndOfStream(false);
    response.setStreamId(streamId);
    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)

Example 58 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.AUTHORITY, "somehost.com"));
    headers.add(new Http2Header(Http2HeaderName.PATH, "/"));
    headers.add(new Http2Header(Http2HeaderName.SCHEME, "http"));
    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 59 with Http2Header

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

Example 60 with Http2Header

use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.

the class HeaderDecoding method decodeImpl.

private List<Http2Header> decodeImpl(UnmarshalStateImpl state, DataWrapper data, int streamId, Consumer<Http2Header> knownHeaders) throws IOException {
    List<Http2Header> headers = new ArrayList<>();
    byte[] bytes = data.createByteArray();
    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    Decoder decoder = state.getDecoder();
    // TODO(dhiller): make this an async syncrhonized block instead so threads can keep running!!!
    synchronized (decoder) {
        decoder.decode(in, (n, v, s) -> addToHeaders(headers, knownHeaders, n, v, s, state.getLogId(), streamId));
        decoder.endHeaderBlock();
    }
    if (data.getReadableSize() > 0 && headers.size() == 0)
        throw new ConnectionException(CancelReasonCode.COMPRESSION_ERROR, state.getLogId(), streamId, "Header data came in, but no headers came out");
    return headers;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) ArrayList(java.util.ArrayList) Decoder(com.twitter.hpack.Decoder) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

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