Search in sources :

Example 61 with Http2Header

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

the class Requests method createEosResponse.

public static Http2Response createEosResponse(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(true);
    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 62 with Http2Header

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

the class LoginFilter method addCacheHeaders.

private Object addCacheHeaders(Object response) {
    Http2Headers resp = (Http2Headers) response;
    // http://stackoverflow.com/questions/49547/how-to-control-web-page-caching-across-all-browsers
    // This forces the browser back button to re-request the page as it would never have the page
    // and is good to use to hide banking information type pages
    // resp.addHeader(new Header(KnownHeaderName.CACHE_CONTROL, "no-store"));
    resp.addHeader(new Http2Header(Http2HeaderName.CACHE_CONTROL, "no-cache, no-store, must-revalidate"));
    resp.addHeader(new Http2Header(Http2HeaderName.PRAGMA, "no-cache"));
    resp.addHeader(new Http2Header(Http2HeaderName.EXPIRES, "0"));
    return resp;
}
Also used : Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 63 with Http2Header

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

the class Requests method createBaseRequest.

public static Http2Request createBaseRequest(String method, String scheme, String path) {
    Http2Request req = new Http2Request();
    req.addHeader(new Http2Header(Http2HeaderName.AUTHORITY, "yourdomain.com"));
    req.addHeader(new Http2Header(Http2HeaderName.SCHEME, scheme));
    req.addHeader(new Http2Header(Http2HeaderName.METHOD, method));
    req.addHeader(new Http2Header(Http2HeaderName.PATH, path));
    return req;
}
Also used : Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 64 with Http2Header

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

the class Requests method createJsonRequest.

public static FullRequest createJsonRequest(String method, String url, String json) {
    Http2Request req = createBaseRequest(method, "https", url);
    DataWrapper body = gen.wrapByteArray(json.getBytes());
    req.addHeader(new Http2Header(Http2HeaderName.CONTENT_LENGTH, body.getReadableSize() + ""));
    return new FullRequest(req, body, null);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) FullRequest(org.webpieces.http2client.api.dto.FullRequest) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest)

Example 65 with Http2Header

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

the class ResponseWrapperHttp2 method createCookieRequestHeader.

/**
 * Example request cookie from chrome
 * Cookie: webSession=1-gzvc03bKRP2YYvWySwgENREwFSg=:__ST=3a2fda5dad7547d3b15b1f61bd3d12f5; webFlash=1:_message=Invalid+values+below&user.address.zipCode=Text+instead+of+number&__secureToken=3a2fda5dad7547d3b15b1f61bd3d12f5&user.firstName=Dean+Hiller; webErrors=1:user.address.zipCode=Could+not+convert+value
 * @return
 */
public Http2Header createCookieRequestHeader() {
    List<Http2Header> headers = getResponse().getHeaderLookupStruct().getHeaders(Http2HeaderName.SET_COOKIE);
    String fullRequestCookie = "";
    boolean firstLine = true;
    for (Http2Header header : headers) {
        String value = header.getValue();
        if (value.contains(";")) {
            String[] split = value.split(";");
            value = split[0];
        }
        String[] keyVal = value.split("=");
        if (keyVal.length <= 1)
            // skip adding this cookie as it was cleared out
            continue;
        if (firstLine) {
            firstLine = false;
            fullRequestCookie += value;
        } else
            fullRequestCookie += "; " + value;
    }
    return new Http2Header(Http2HeaderName.COOKIE, fullRequestCookie);
}
Also used : Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

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