Search in sources :

Example 71 with Http2Header

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

the class HttpsJsonClient method createCurl2.

private String createCurl2(int port, Http2Request req, Supplier<String> supplier) {
    String s = "";
    s += "\n\n************************************************************\n";
    s += "            CURL REQUEST\n";
    s += "***************************************************************\n";
    s += "curl -k --request " + req.getKnownMethod().getCode() + " ";
    for (Http2Header header : req.getHeaders()) {
        if (header.getName().startsWith(":")) {
            // base headers we can discard
            continue;
        }
        s += "-H \"" + header.getName() + ":" + header.getValue() + "\" ";
    }
    String host = req.getSingleHeaderValue(Http2HeaderName.AUTHORITY);
    String path = req.getSingleHeaderValue(Http2HeaderName.PATH);
    s += supplier.get();
    s += " \"https://" + host + ":" + port + path + "\"\n";
    s += "***************************************************************\n";
    return s;
}
Also used : Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 72 with Http2Header

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

the class RouterRequest method getHeaders.

/**
 * Need to remove webpieces http2 stack from router(ie. Http2Request above and Http2Headers!!!!!!)
 * This is a step towards that to only
 * have RouterRequest which is the bare minimum object to allow router to do it's job.  In this way,
 * router is a piece that can work with an http stack(apache, etc. etc.) and a true piece to be
 * re-used.
 *
 * For now, http2 headers is too tightly coupled for worry about while we get this working so this is
 * at least one point of decoupling.  Steps...
 * Step 1. create all read points to read from methods like this reading in objects from org.webpieces.ctx.api
 * Step 2. figure out how to better translate from ANY http2/http1 into RouterRequest in
 *         the webserver connection layer
 * Step 3. Make these fields Object so any platform can insert their http2 or http1 objects
 *         public Http2Request originalRequest;
 * 	       public Http2Headers trailingHeaders;
 */
public synchronized Map<String, List<RouterHeader>> getHeaders() {
    if (routerHeaderMap != null)
        return routerHeaderMap;
    else if (originalRequest == null)
        // some legacy tests at Orderly simulate with no original request
        return routerHeaderMap;
    routerHeaderMap = new HashMap<>();
    // DO NOT cache this as there are clients that modify the Http2Header which will not
    // modify this list so just generate this list every time for now.
    // In webpieces getHeaders is only called once every request anyways!!!
    Http2HeaderStruct headerLookupStruct = originalRequest.getHeaderLookupStruct();
    for (String headerName : headerLookupStruct.getAllHeaderNames()) {
        // http is well, 'interesting' allowing one to repeat header names and if I remember
        // order matters and we keep the order
        List<Http2Header> headerArray = headerLookupStruct.getHeaders(headerName);
        List<RouterHeader> translatedList = translate(headerArray);
        routerHeaderMap.put(headerName, translatedList);
    }
    return routerHeaderMap;
}
Also used : Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) Http2HeaderStruct(com.webpieces.http2.api.dto.highlevel.Http2HeaderStruct)

Example 73 with Http2Header

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

the class TestLesson8JsonHttp2 method createRequest.

public static FullRequest createRequest(String uri, DataWrapper body) {
    Http2Request req = new Http2Request();
    req.addHeader(new Http2Header(Http2HeaderName.AUTHORITY, "yourdomain.com"));
    req.addHeader(new Http2Header(Http2HeaderName.SCHEME, "https"));
    req.addHeader(new Http2Header(Http2HeaderName.METHOD, "GET"));
    req.addHeader(new Http2Header(Http2HeaderName.PATH, uri));
    req.addHeader(new Http2Header(Http2HeaderName.CONTENT_LENGTH, body.getReadableSize() + ""));
    FullRequest fullReq = new FullRequest(req, body, null);
    return fullReq;
}
Also used : Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) FullRequest(org.webpieces.http2client.api.dto.FullRequest)

Example 74 with Http2Header

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

the class Requests method createChunkedResponse.

public static Http2Response createChunkedResponse(int id) {
    List<Http2Header> headers = new ArrayList<>();
    headers.add(new Http2Header(Http2HeaderName.STATUS, "200"));
    headers.add(new Http2Header(Http2HeaderName.SERVER, id + ""));
    Http2Response response = new Http2Response(headers);
    response.setEndOfStream(false);
    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