/** * Identify the host of an HTTP request. This method uses the URI of the request if possible, otherwise it attempts to find the host * in the request headers. * * @param httpRequest HTTP request to parse the host from * @return the host the request is connecting to, or null if no host can be found */ public static String getHostFromRequest(HttpRequest httpRequest) { // try to use the URI from the request first, if the URI starts with http:// or https://. checking for http/https avoids confusing // java's URI class when the request is for a malformed URL like '//some-resource'. String host = null; if (startsWithHttpOrHttps(httpRequest.getUri())) { try { URI uri = new URI(httpRequest.getUri()); host = uri.getHost(); } catch (URISyntaxException e) { } } // if there was no host in the URI, attempt to grab the host from the Host header if (host == null || host.isEmpty()) { host = parseHostHeader(httpRequest, false); } return host; }
/** * Retrieves the raw (unescaped) path + query string from the specified request. The returned path will not include * the scheme, host, or port. * * @param httpRequest HTTP request * @return the unescaped path + query string from the HTTP request * @throws URISyntaxException if the path could not be parsed (due to invalid characters in the URI, etc.) */ public static String getRawPathAndParamsFromRequest(HttpRequest httpRequest) throws URISyntaxException { // if this request's URI contains a full URI (including scheme, host, etc.), strip away the non-path components if (HttpUtil.startsWithHttpOrHttps(httpRequest.getUri())) { return getRawPathAndParamsFromUri(httpRequest.getUri()); } else { // to provide consistent validation behavior for URIs that contain a scheme and those that don't, attempt to parse // the URI, even though we discard the parsed URI object new URI(httpRequest.getUri()); return httpRequest.getUri(); } }
/** * Gets the host and port from the specified request. Returns the host and port from the request URI if available, * otherwise retrieves the host and port from the Host header. * * @param httpRequest HTTP request * @return host and port of the request */ public static String getHostAndPortFromRequest(HttpRequest httpRequest) { if (startsWithHttpOrHttps(httpRequest.getUri())) { try { return getHostAndPortFromUri(httpRequest.getUri()); } catch (URISyntaxException e) { // the URI could not be parsed, so return the host and port in the Host header } } return parseHostHeader(httpRequest, true); }
if (HttpUtil.startsWithHttpOrHttps(uriFromRequest)) { httpRequest.setUri(rewrittenUrl); } else {
if (HttpUtil.startsWithHttpOrHttps(modifiedRequest.getUri())) { return modifiedRequest.getUri();
/** * Identify the host of an HTTP request. This method uses the URI of the request if possible, otherwise it attempts to find the host * in the request headers. * * @param httpRequest HTTP request to parse the host from * @return the host the request is connecting to, or null if no host can be found */ public static String getHostFromRequest(HttpRequest httpRequest) { // try to use the URI from the request first, if the URI starts with http:// or https://. checking for http/https avoids confusing // java's URI class when the request is for a malformed URL like '//some-resource'. String host = null; if (startsWithHttpOrHttps(httpRequest.getUri())) { try { URI uri = new URI(httpRequest.getUri()); host = uri.getHost(); } catch (URISyntaxException e) { } } // if there was no host in the URI, attempt to grab the host from the Host header if (host == null || host.isEmpty()) { host = parseHostHeader(httpRequest, false); } return host; }
/** * Identify the host of an HTTP request. This method uses the URI of the request if possible, otherwise it attempts to find the host * in the request headers. * * @param httpRequest HTTP request to parse the host from * @return the host the request is connecting to, or null if no host can be found */ public static String getHostFromRequest(HttpRequest httpRequest) { // try to use the URI from the request first, if the URI starts with http:// or https://. checking for http/https avoids confusing // java's URI class when the request is for a malformed URL like '//some-resource'. String host = null; if (startsWithHttpOrHttps(httpRequest.getUri())) { try { URI uri = new URI(httpRequest.getUri()); host = uri.getHost(); } catch (URISyntaxException e) { } } // if there was no host in the URI, attempt to grab the host from the Host header if (host == null || host.isEmpty()) { host = parseHostHeader(httpRequest, false); } return host; }
/** * Retrieves the raw (unescaped) path + query string from the specified request. The returned path will not include * the scheme, host, or port. * * @param httpRequest HTTP request * @return the unescaped path + query string from the HTTP request * @throws URISyntaxException if the path could not be parsed (due to invalid characters in the URI, etc.) */ public static String getRawPathAndParamsFromRequest(HttpRequest httpRequest) throws URISyntaxException { // if this request's URI contains a full URI (including scheme, host, etc.), strip away the non-path components if (HttpUtil.startsWithHttpOrHttps(httpRequest.getUri())) { return getRawPathAndParamsFromUri(httpRequest.getUri()); } else { // to provide consistent validation behavior for URIs that contain a scheme and those that don't, attempt to parse // the URI, even though we discard the parsed URI object new URI(httpRequest.getUri()); return httpRequest.getUri(); } }
/** * Retrieves the raw (unescaped) path + query string from the specified request. The returned path will not include * the scheme, host, or port. * * @param httpRequest HTTP request * @return the unescaped path + query string from the HTTP request * @throws URISyntaxException if the path could not be parsed (due to invalid characters in the URI, etc.) */ public static String getRawPathAndParamsFromRequest(HttpRequest httpRequest) throws URISyntaxException { // if this request's URI contains a full URI (including scheme, host, etc.), strip away the non-path components if (HttpUtil.startsWithHttpOrHttps(httpRequest.getUri())) { return getRawPathAndParamsFromUri(httpRequest.getUri()); } else { // to provide consistent validation behavior for URIs that contain a scheme and those that don't, attempt to parse // the URI, even though we discard the parsed URI object new URI(httpRequest.getUri()); return httpRequest.getUri(); } }
/** * Gets the host and port from the specified request. Returns the host and port from the request URI if available, * otherwise retrieves the host and port from the Host header. * * @param httpRequest HTTP request * @return host and port of the request */ public static String getHostAndPortFromRequest(HttpRequest httpRequest) { if (startsWithHttpOrHttps(httpRequest.getUri())) { try { return getHostAndPortFromUri(httpRequest.getUri()); } catch (URISyntaxException e) { // the URI could not be parsed, so return the host and port in the Host header } } return parseHostHeader(httpRequest, true); }
/** * Gets the host and port from the specified request. Returns the host and port from the request URI if available, * otherwise retrieves the host and port from the Host header. * * @param httpRequest HTTP request * @return host and port of the request */ public static String getHostAndPortFromRequest(HttpRequest httpRequest) { if (startsWithHttpOrHttps(httpRequest.getUri())) { try { return getHostAndPortFromUri(httpRequest.getUri()); } catch (URISyntaxException e) { // the URI could not be parsed, so return the host and port in the Host header } } return parseHostHeader(httpRequest, true); }
if (HttpUtil.startsWithHttpOrHttps(uriFromRequest)) { httpRequest.setUri(rewrittenUrl); } else {
if (HttpUtil.startsWithHttpOrHttps(uriFromRequest)) { httpRequest.setUri(rewrittenUrl); } else {
if (HttpUtil.startsWithHttpOrHttps(uriFromRequest)) { httpRequest.setUri(rewrittenUrl); } else {
if (HttpUtil.startsWithHttpOrHttps(modifiedRequest.getUri())) { return modifiedRequest.getUri();
if (HttpUtil.startsWithHttpOrHttps(modifiedRequest.getUri())) { return modifiedRequest.getUri();
if (HttpUtil.startsWithHttpOrHttps(modifiedRequest.getUri())) { return modifiedRequest.getUri();