Search in sources :

Example 11 with Http2Headers

use of com.webpieces.http2.api.dto.highlevel.Http2Headers 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 12 with Http2Headers

use of com.webpieces.http2.api.dto.highlevel.Http2Headers in project webpieces by deanhiller.

the class RouterServiceImpl method parseAccept.

private void parseAccept(Http2Headers req, RouterRequest routerRequest) {
    List<AcceptType> types = headerParser.parseAcceptFromRequest(req);
    List<AcceptMediaType> acceptedTypes = new ArrayList<>();
    for (AcceptType t : types) {
        if (t.isMatchesAllTypes())
            acceptedTypes.add(new AcceptMediaType());
        else if (t.isMatchesAllSubtypes())
            acceptedTypes.add(new AcceptMediaType(t.getMainType()));
        else
            acceptedTypes.add(new AcceptMediaType(t.getMainType(), t.getSubType()));
    }
    routerRequest.acceptedTypes = acceptedTypes;
}
Also used : ArrayList(java.util.ArrayList) AcceptType(com.webpieces.http2.api.subparsers.AcceptType) AcceptMediaType(org.webpieces.ctx.api.AcceptMediaType)

Aggregations

Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)8 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)4 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)4 Test (org.junit.Test)4 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)3 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)3 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)2 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)2 HeadersFrame (com.webpieces.http2.api.dto.lowlevel.HeadersFrame)2 Http2Frame (com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)2 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)2 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)2 Encoder (com.twitter.hpack.Encoder)1 Http2HeaderStruct (com.webpieces.http2.api.dto.highlevel.Http2HeaderStruct)1 Http2Trailers (com.webpieces.http2.api.dto.highlevel.Http2Trailers)1 PushPromiseFrame (com.webpieces.http2.api.dto.lowlevel.PushPromiseFrame)1 HasHeaderFragment (com.webpieces.http2.api.dto.lowlevel.lib.HasHeaderFragment)1 Http2HeaderName (com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName)1 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)1 StreamMsg (com.webpieces.http2.api.dto.lowlevel.lib.StreamMsg)1