Search in sources :

Example 26 with Http2Header

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

the class Http2Translations method responseToHeaders.

public static Http2Response responseToHeaders(HttpResponse response) {
    List<Http2Header> headers = new ArrayList<>();
    headers.add(new Http2Header(Http2HeaderName.STATUS, response.getStatusLine().getStatus().getCode().toString()));
    for (Header header : response.getHeaders()) {
        if (header.getKnownName() == KnownHeaderName.TRANSFER_ENCODING) {
            if ("chunked".equals(header.getValue())) {
                //skip as http2 does not allow this header
                continue;
            }
        }
        headers.add(new Http2Header(header.getName(), header.getValue()));
    }
    Http2Response resp = new Http2Response(headers);
    Header header = response.getHeaderLookupStruct().getHeader(KnownHeaderName.CONTENT_LENGTH);
    if (header != null) {
        int len = Integer.parseInt(header.getValue());
        if (len == 0) {
            resp.setEndOfStream(true);
        } else {
            resp.setEndOfStream(false);
        }
    } else {
        resp.setEndOfStream(false);
    }
    return resp;
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Header(org.webpieces.httpparser.api.common.Header) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) ArrayList(java.util.ArrayList)

Example 27 with Http2Header

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

the class Http2Requests method createResponse.

public static Http2Response createResponse(int streamId, boolean eos) {
    List<Http2Header> headers = new ArrayList<>();
    headers.add(new Http2Header(Http2HeaderName.SERVER, "id"));
    headers.add(new Http2Header(Http2HeaderName.STATUS, "200"));
    Http2Response response = new Http2Response(headers);
    response.setEndOfStream(eos);
    response.setStreamId(streamId);
    return response;
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) ArrayList(java.util.ArrayList)

Example 28 with Http2Header

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

the class Http2Requests method createTrailers.

public static Http2Trailers createTrailers(int streamId) {
    List<Http2Header> headers = new ArrayList<>();
    headers.add(new Http2Header(Http2HeaderName.SERVER, "trailing"));
    Http2Trailers trailers = new Http2Trailers(headers);
    trailers.setEndOfStream(true);
    trailers.setStreamId(streamId);
    return trailers;
}
Also used : Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) ArrayList(java.util.ArrayList) Http2Trailers(com.webpieces.hpack.api.dto.Http2Trailers)

Example 29 with Http2Header

use of com.webpieces.http2parser.api.dto.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.webpieces.util.logging.Logger) SortedSet(java.util.SortedSet) Executor(java.util.concurrent.Executor) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) CancelReason(com.webpieces.http2parser.api.dto.CancelReason) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) CompletableFuture(java.util.concurrent.CompletableFuture) InetSocketAddress(java.net.InetSocketAddress) TreeSet(java.util.TreeSet) Executors(java.util.concurrent.Executors) Http2HeaderName(com.webpieces.http2parser.api.dto.lib.Http2HeaderName) ArrayList(java.util.ArrayList) PushPromiseListener(com.webpieces.http2engine.api.PushPromiseListener) PushStreamHandle(com.webpieces.http2engine.api.PushStreamHandle) List(java.util.List) StreamWriter(com.webpieces.http2engine.api.StreamWriter) Http2Push(com.webpieces.hpack.api.dto.Http2Push) Http2Request(com.webpieces.hpack.api.dto.Http2Request) LoggerFactory(org.webpieces.util.logging.LoggerFactory) Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Socket(org.webpieces.http2client.api.Http2Socket) ResponseHandler(com.webpieces.http2engine.api.ResponseHandler) InetSocketAddress(java.net.InetSocketAddress) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) Http2Socket(org.webpieces.http2client.api.Http2Socket)

Example 30 with Http2Header

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

the class IntegMultiThreaded method createRequest.

private static List<Http2Header> createRequest(String host, boolean isHttp, String path) {
    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, path));
    headers.add(new Http2Header(Http2HeaderName.SCHEME, scheme));
    headers.add(new Http2Header("host", host));
    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.http2parser.api.dto.lib.Http2Header) ArrayList(java.util.ArrayList)

Aggregations

Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)36 ArrayList (java.util.ArrayList)16 Http2Response (com.webpieces.hpack.api.dto.Http2Response)13 Http2Request (com.webpieces.hpack.api.dto.Http2Request)6 Http2HeaderName (com.webpieces.http2parser.api.dto.lib.Http2HeaderName)6 Http2Push (com.webpieces.hpack.api.dto.Http2Push)5 StreamWriter (com.webpieces.http2engine.api.StreamWriter)4 Http2Frame (com.webpieces.http2parser.api.dto.lib.Http2Frame)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Header (org.webpieces.httpparser.api.common.Header)4 Logger (org.webpieces.util.logging.Logger)4 LoggerFactory (org.webpieces.util.logging.LoggerFactory)4 List (java.util.List)3 BufferPool (org.webpieces.data.api.BufferPool)3 Encoder (com.twitter.hpack.Encoder)2 Http2Headers (com.webpieces.hpack.api.dto.Http2Headers)2 Http2Trailers (com.webpieces.hpack.api.dto.Http2Trailers)2 HeaderEncoding (com.webpieces.hpack.impl.HeaderEncoding)2 PushPromiseListener (com.webpieces.http2engine.api.PushPromiseListener)2 PushStreamHandle (com.webpieces.http2engine.api.PushStreamHandle)2