Search in sources :

Example 51 with Http2Header

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

the class ResponseCreator method createRedirect.

public Http2Response createRedirect(Http2Request request, RedirectResponse httpResponse) {
    Http2Response response;
    if (httpResponse.isAjaxRedirect) {
        response = addCommonHeaders(request, null, true, Constants.AJAX_REDIRECT_CODE, "Ajax Redirect");
    } else {
        response = addCommonHeaders(request, null, true, StatusCode.HTTP_303_SEE_OTHER.getCode(), StatusCode.HTTP_303_SEE_OTHER.getReason());
    }
    String url = httpResponse.redirectToPath;
    if (url.startsWith("http")) {
    // do nothing
    } else if (httpResponse.domain != null && httpResponse.isHttps != null) {
        String prefix = "http://";
        if (httpResponse.isHttps)
            prefix = "https://";
        String portPostfix = "";
        if (httpResponse.port != 443 && httpResponse.port != 80)
            portPostfix = ":" + httpResponse.port;
        url = prefix + httpResponse.domain + portPostfix + httpResponse.redirectToPath;
    } else if (httpResponse.domain != null) {
        throw new IllegalReturnValueException("Controller is returning a domain without returning isHttps=true or" + " isHttps=false so we can form the entire redirect.  Either drop the domain or set isHttps");
    } else if (httpResponse.isHttps != null) {
        throw new IllegalReturnValueException("Controller is returning isHttps=" + httpResponse.isHttps + " but there is" + "no domain set so we can't form the full redirect.  Either drop setting isHttps or set the domain");
    }
    Http2Header location = new Http2Header(Http2HeaderName.LOCATION, url);
    response.addHeader(location);
    // Firefox requires a content length of 0 on redirect(chrome doesn't)!!!...
    response.addHeader(new Http2Header(Http2HeaderName.CONTENT_LENGTH, 0 + ""));
    return response;
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) IllegalReturnValueException(org.webpieces.router.api.exceptions.IllegalReturnValueException) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 52 with Http2Header

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

the class ResponseCreator method create.

private Http2Header create(RouterCookie c) {
    ResponseCookie cookie = new ResponseCookie();
    cookie.setName(c.name);
    cookie.setValue(c.value);
    cookie.setDomain(c.domain);
    cookie.setPath(c.path);
    cookie.setMaxAgeSeconds(c.maxAgeSeconds);
    cookie.setSecure(c.isSecure);
    cookie.setHttpOnly(c.isHttpOnly);
    return httpSubParser.createHeader(cookie);
}
Also used : ResponseCookie(com.webpieces.http2.api.subparsers.ResponseCookie)

Example 53 with Http2Header

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

the class ResponseCreator method addCommonHeaders.

public Http2Response addCommonHeaders(Http2Request request, String responseMimeType, boolean isDynamicPartOfWebsite, int statusCode, String statusReason) {
    Http2Response response = addCommonHeaders2(request, responseMimeType, statusCode, statusReason);
    boolean isInternalError = statusCode >= 500 && statusCode < 600;
    if (isDynamicPartOfWebsite) {
        List<RouterCookie> cookies = createCookies(isInternalError);
        for (RouterCookie c : cookies) {
            Http2Header cookieHeader = create(c);
            response.addHeader(cookieHeader);
        }
    }
    return response;
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) RouterCookie(org.webpieces.ctx.api.RouterCookie)

Example 54 with Http2Header

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

the class ResponseCreator method addDeleteCookie.

public void addDeleteCookie(Http2Response response, String badCookieName) {
    RouterCookie cookie = cookieTranslator.createDeleteCookie(badCookieName);
    Http2Header cookieHeader = create(cookie);
    response.addHeader(cookieHeader);
}
Also used : Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) RouterCookie(org.webpieces.ctx.api.RouterCookie)

Example 55 with Http2Header

use of com.webpieces.http2.api.dto.lowlevel.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.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