use of org.webpieces.ctx.api.UriInfo in project webpieces by deanhiller.
the class RouterServiceImpl method fillInRouterRequest.
private void fillInRouterRequest(Http2Request requestHeaders, RouterRequest routerRequest, RouterStreamHandle handler) {
routerRequest.originalRequest = requestHeaders;
fillInHttpsValue(requestHeaders, routerRequest, handler);
routerRequest.isBackendRequest = handler.requestCameFromBackendSocket();
String domain = requestHeaders.getAuthority();
if (domain == null) {
throw new IllegalArgumentException("Must contain Host Header in http1.1 or :authority header in http2 header");
}
int port = 80;
if (routerRequest.isHttps)
port = 443;
int index2 = domain.indexOf(":");
// TODO(dhiller): find when user is used and test implement
if (index2 >= 0) {
port = Integer.parseInt(domain.substring(index2 + 1));
domain = domain.substring(0, index2);
}
// if there is a firewall the socket's port is wrong(ie. the line below)....and the above is correct!!!
// int port = socketInfo.getLocalBoundAddress().getPort();
String methodString = requestHeaders.getMethodString();
HttpMethod method = HttpMethod.lookup(methodString);
if (method == null)
throw new UnsupportedOperationException("method not supported=" + methodString);
parseCookies(requestHeaders, routerRequest);
parseAcceptLang(requestHeaders, routerRequest);
parseAccept(requestHeaders, routerRequest);
routerRequest.encodings = headerParser.parseAcceptEncoding(requestHeaders);
routerRequest.contentTypeHeaderValue = parse(requestHeaders);
String referHeader = requestHeaders.getSingleHeaderValue(Http2HeaderName.REFERER);
if (referHeader != null)
routerRequest.referrer = referHeader;
String xRequestedWithHeader = requestHeaders.getSingleHeaderValue(Http2HeaderName.X_REQUESTED_WITH);
if ("XMLHttpRequest".equals(xRequestedWithHeader))
routerRequest.isAjaxRequest = true;
String thePath = requestHeaders.getPath();
if (thePath == null)
throw new IllegalArgumentException(":path header(http2) or path in request line(http1.1) is required");
UriInfo uriBreakdown = getUriBreakdown(thePath);
String fullPath = uriBreakdown.getFullPath();
routerRequest.requestUri = uriBreakdown;
routerRequest.method = method;
routerRequest.domain = domain;
routerRequest.port = port;
int index = fullPath.indexOf("?");
if (index > 0) {
routerRequest.relativePath = fullPath.substring(0, index);
String postfix = fullPath.substring(index + 1);
urlEncodeParse(postfix, routerRequest);
} else {
routerRequest.queryParams = new HashMap<>();
routerRequest.relativePath = fullPath;
}
// http1.1 so no...
routerRequest.isSendAheadNextResponses = false;
if (routerRequest.relativePath.contains("?"))
throw new UnsupportedOperationException("not supported yet");
}
use of org.webpieces.ctx.api.UriInfo in project webpieces by deanhiller.
the class RouterServiceImpl method getUriBreakdown.
// TODO(dhiller): This code now exists in TWO locations. modify to share SAME code instead of copying
public UriInfo getUriBreakdown(String uri) {
int doubleslashIndex = uri.indexOf("://");
if (doubleslashIndex == -1)
return new UriInfo(uri);
int domainStartIndex = doubleslashIndex + 3;
String prefix = uri.substring(0, doubleslashIndex);
Integer port = null;
String path = "";
int firstSlashIndex = uri.indexOf('/', domainStartIndex);
if (firstSlashIndex < 0) {
firstSlashIndex = uri.length();
path = "/";
} else {
path = uri.substring(firstSlashIndex);
}
int domainEndIndex = firstSlashIndex;
int portIndex = uri.indexOf(':', domainStartIndex);
if (portIndex > 0 && portIndex < firstSlashIndex) {
domainEndIndex = portIndex;
String portStr = uri.substring(portIndex + 1, firstSlashIndex);
port = convert(portStr, uri);
}
String host = uri.substring(domainStartIndex, domainEndIndex);
return new UriInfo(prefix, host, port, path);
}
Aggregations