Search in sources :

Example 21 with Http2Header

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

the class Translations2 method translate.

public static HttpFullRequest translate(FullRequest request) {
    // String scheme = request.getHeaders().getScheme();
    Http2Request headers = request.getHeaders();
    String authority = headers.getAuthority();
    String path = headers.getPath();
    String methodString = headers.getMethodString();
    if (methodString == null)
        throw new IllegalArgumentException("http2 :method header is required");
    else if (authority == null) {
        throw new IllegalArgumentException("http1 required host header so http2 message must have :authority header set");
    }
    HttpRequestLine reqLine = new HttpRequestLine();
    reqLine.setUri(new HttpUri(path));
    reqLine.setMethod(new HttpRequestMethod(methodString));
    reqLine.setVersion(new HttpVersion());
    HttpRequest httpReq = new HttpRequest();
    httpReq.setRequestLine(reqLine);
    DataWrapper data = request.getPayload();
    // translate all other headers here as well...
    for (Http2Header header : headers.getHeaders()) {
        if (// All standard headers go elsewhere except HOST which we do below
        !header.getName().startsWith(":"))
            httpReq.addHeader(new Header(header.getName(), header.getValue()));
    }
    httpReq.addHeader(new Header(KnownHeaderName.HOST, authority));
    HttpFullRequest req = new HttpFullRequest(httpReq, data);
    return req;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) DataWrapper(org.webpieces.data.api.DataWrapper) HttpRequestMethod(org.webpieces.httpparser.api.dto.HttpRequestMethod) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) Header(org.webpieces.httpparser.api.common.Header) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) HttpUri(org.webpieces.httpparser.api.dto.HttpUri) HttpVersion(org.webpieces.httpparser.api.dto.HttpVersion)

Example 22 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) ResponseStreamHandle(com.webpieces.http2.api.streaming.ResponseStreamHandle) PushPromiseListener(com.webpieces.http2.api.streaming.PushPromiseListener) List(java.util.List) XFuture(org.webpieces.util.futures.XFuture) StreamRef(com.webpieces.http2.api.streaming.StreamRef) 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) 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 23 with Http2Header

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

the class ResponseWrapperHttp2 method modifyCookieMap.

public Map<String, String> modifyCookieMap(Map<String, String> currentCookies) {
    List<Http2Header> headers = getResponse().getHeaderLookupStruct().getHeaders(Http2HeaderName.SET_COOKIE);
    for (Http2Header header : headers) {
        String value = header.getValue();
        if (value.contains(";")) {
            String[] split = value.split(";");
            value = split[0];
        }
        int indexOf = value.indexOf("=");
        String key = value.substring(0, indexOf);
        String val = value.substring(indexOf + 1);
        if (val.length() <= 0) {
            currentCookies.remove(key);
        } else {
            currentCookies.put(key, val);
        }
    }
    return currentCookies;
}
Also used : Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 24 with Http2Header

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

the class ResponseWrapperHttp2 method extractCharset.

private Charset extractCharset() {
    Http2Header header = getResponse().getHeaderLookupStruct().getHeader(Http2HeaderName.CONTENT_TYPE);
    if (header == null)
        throw new IllegalArgumentException("no ContentType header could be found");
    ContentType ct = ContentType.parse(header);
    Charset charset = DEFAULT_CHARSET;
    if (ct.getCharSet() != null)
        charset = Charset.forName(ct.getCharSet());
    return charset;
}
Also used : ContentType(org.webpieces.http2client.api.dto.ContentType) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) Charset(java.nio.charset.Charset)

Example 25 with Http2Header

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

the class XFileReaderFileSystem method createFileReader.

protected ChunkFileSystemReader createFileReader(Http2Response response, RenderStaticResponse renderStatic, String fileName, VirtualFile fullFilePath, RequestInfo info, String extension, ResponseEncodingTuple tuple, ProxyStreamHandle handle) {
    Path file;
    Compression compr = compressionLookup.createCompressionStream(info.getRouterRequest().encodings, tuple.mimeType);
    // during startup as I don't feel like paying a cpu penalty for compressing while live
    if (compr != null && compr.getCompressionType().equals(routerConfig.getStartupCompression())) {
        handle.turnCompressionOff();
        response.addHeader(new Http2Header(Http2HeaderName.CONTENT_ENCODING, compr.getCompressionType()));
        File routesCache = renderStatic.getTargetCache();
        String relativeUrl = renderStatic.getRelativeUrl();
        File fileReference;
        if (relativeUrl == null) {
            fileReference = FileFactory.newFile(routesCache, fileName);
        } else {
            fileReference = FileFactory.newFile(routesCache, relativeUrl);
        }
        file = fetchFile("Compressed File from cache=", fileReference.getAbsolutePath() + ".gz");
    } else {
        file = fetchFile("File=", fullFilePath.getAbsolutePath());
    }
    AsynchronousFileChannel asyncFile;
    try {
        asyncFile = AsynchronousFileChannel.open(file, options, fileExecutor);
        ChunkFileSystemReader reader = new ChunkFileSystemReader(asyncFile, file);
        return reader;
    } catch (IOException e) {
        throw new NioException("Open Channel Exception " + file, e);
    }
}
Also used : Path(java.nio.file.Path) AsynchronousFileChannel(java.nio.channels.AsynchronousFileChannel) Compression(org.webpieces.router.impl.compression.Compression) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) IOException(java.io.IOException) NioException(org.webpieces.util.exceptions.NioException) File(java.io.File) VirtualFile(org.webpieces.util.file.VirtualFile)

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