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;
}
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);
}
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;
}
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);
}
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;
}
Aggregations