@Test public void getCanonicalURI_mixedSSE() throws Exception { URI result = HttpUtils.getCanonicalURI("sse: assertLowerCase(result.getHost()); assertEquals("/echo", result.getPath()); }
public static URI getCanonicalURI(URI uri, boolean canonicalizePath) { URI canonicalURI = uri; if (uri != null) { String host = uri.getHost(); String path = uri.getPath(); final boolean emptyPath = "".equals(path); final boolean noPathToCanonicalize = canonicalizePath && (path == null || emptyPath); final boolean trailingSlashPath = "/".equals(path); final boolean pathlessScheme = "ssl".equals(uri.getScheme()) || "tcp".equals(uri.getScheme()) || "pipe".equals(uri.getScheme()) || "udp".equals(uri.getScheme()); final boolean trailingSlashWithPathlessScheme = trailingSlashPath && pathlessScheme; String newPath = trailingSlashWithPathlessScheme ? "" : noPathToCanonicalize ? (pathlessScheme ? null : "/") : null; if (((host != null) && !host.equals(host.toLowerCase())) || newPath != null) { path = newPath == null ? path : newPath; try { canonicalURI = new URI(uri.getScheme(), uri.getUserInfo(), host == null ? null : host.toLowerCase(), uri.getPort(), path, uri.getQuery(), uri.getFragment()); } catch (URISyntaxException ex) { throw new IllegalArgumentException("Invalid URI: " + uri + " in Gateway configuration file", ex); } } } return canonicalURI; }
HttpUtils { public static URI getCanonicalURI(URI uri, boolean canonicalizePath) { URI canonicalURI = uri; if (uri != null) { String host = uri.getHost(); String path = uri.getPath(); final boolean emptyPath = "".equals(path); final boolean noPathToCanonicalize = canonicalizePath && (path == null || emptyPath); final boolean trailingSlashPath = "/".equals(path); final boolean pathlessScheme = "ssl".equals(uri.getScheme()) || "tcp".equals(uri.getScheme()) || "pipe".equals(uri.getScheme()) || "udp".equals(uri.getScheme()); final boolean trailingSlashWithPathlessScheme = trailingSlashPath && pathlessScheme; String newPath = trailingSlashWithPathlessScheme ? "" : noPathToCanonicalize ? (pathlessScheme ? null : "/") : null; if (((host != null) && !host.equals(host.toLowerCase())) || newPath != null) { path = newPath == null ? path : newPath; try { canonicalURI = new URI(uri.getScheme(), uri.getUserInfo(), host == null ? null : host.toLowerCase(), uri.getPort(), path, uri.getQuery(), uri.getFragment()); } catch (URISyntaxException ex) { throw new IllegalArgumentException("Invalid URI: " + uri + " in Gateway configuration file", ex); } } } return canonicalURI; } }
HttpUtils { public static URI getCanonicalURI(URI uri, boolean canonicalizePath) { URI canonicalURI = uri; if (uri != null) { String host = uri.getHost(); String path = uri.getPath(); final boolean emptyPath = "".equals(path); final boolean noPathToCanonicalize = canonicalizePath && (path == null || emptyPath); final boolean trailingSlashPath = "/".equals(path); final boolean pathlessScheme = "ssl".equals(uri.getScheme()) || "tcp".equals(uri.getScheme()) || "pipe".equals(uri.getScheme()) || "udp".equals(uri.getScheme()); final boolean trailingSlashWithPathlessScheme = trailingSlashPath && pathlessScheme; String newPath = trailingSlashWithPathlessScheme ? "" : noPathToCanonicalize ? (pathlessScheme ? null : "/") : null; if (((host != null) && !host.equals(host.toLowerCase())) || newPath != null) { path = newPath == null ? path : newPath; try { canonicalURI = new URI(uri.getScheme(), uri.getUserInfo(), host == null ? null : host.toLowerCase(), uri.getPort(), path, uri.getQuery(), uri.getFragment()); } catch (URISyntaxException ex) { throw new IllegalArgumentException("Invalid URI: " + uri + " in Gateway configuration file", ex); } } } return canonicalURI; }  }
HttpUtils { public static URI getCanonicalURI(URI uri, boolean canonicalizePath) { URI canonicalURI = uri; if (uri != null) { String host = uri.getHost(); String path = uri.getPath(); final boolean emptyPath = "".equals(path); final boolean noPathToCanonicalize = canonicalizePath && (path == null || emptyPath); final boolean trailingSlashPath = "/".equals(path); final boolean pathlessScheme = "ssl".equals(uri.getScheme()) || "tcp".equals(uri.getScheme()) || "pipe".equals(uri.getScheme()) || "udp".equals(uri.getScheme()); final boolean trailingSlashWithPathlessScheme = trailingSlashPath && pathlessScheme; String newPath = trailingSlashWithPathlessScheme ? "" : noPathToCanonicalize ? (pathlessScheme ? null : "/") : null; if (((host != null) && !host.equals(host.toLowerCase())) || newPath != null) { path = newPath == null ? path : newPath; try { canonicalURI = new URI(uri.getScheme(), uri.getUserInfo(), host == null ? null : host.toLowerCase(), uri.getPort(), path, uri.getQuery(), uri.getFragment()); } catch (URISyntaxException ex) { throw new IllegalArgumentException("Invalid URI: " + uri + " in Gateway configuration file", ex); } } } return canonicalURI; }  static String getHostDomain(HttpRequestMessage httpRequest); static String getHostAndPort(HttpRequestMessage httpRequest, boolean secure); static String getHostAndPort(String authority, boolean secure); static long parseDateHeader(String header); static String formatDateHeader(long millis); static void fileRequested(IoBufferAllocatorEx<?> allocator, HttpRequestMessage httpRequest,
        HttpResponseMessage httpResponse, File requestFile); static void writeIfModified(HttpAcceptSession httpSession, File requestFile); static IoBufferEx getBufferForFile(IoBufferAllocatorEx<?> allocator, File requestFile); static boolean hasBeenModified(HttpSession session, String etag, File requestFile); static void addLastModifiedHeader(HttpSession session, File requestFile); static String getETagHeaderValue(File requestFile); static void supplyScriptAsHtml(File xdBridgeFile, long startTime, String resourcePath); static void supplyFile(File bridgeFile, long startTime, String resourcePath); static boolean canStream(HttpSession session); static String newSessionId(); static URI getRequestURI(HttpRequestMessage request, IoSession session); static URI getRequestURI(URI requestURI, String hostHeader, IoSession session); static boolean hasCloseHeader(List<String> connectionValues); static URI getTransportURI(HttpRequestMessage request, IoSession session); static boolean isChunked(String transferEncoding); static boolean isChunked(HttpResponseMessage response); static boolean isGzipped(HttpResponseMessage response); static URI getCanonicalURI(URI uri, boolean canonicalizePath); static URI getCanonicalURI(String uriString, boolean canonicalizePath); static String[] getPathComponents(URI uri); static String getAuthenticationTokenFromPath(URI uri); static boolean containsForbiddenHeaders(HttpRequestMessage request, String[] allowedHeaders); static boolean isForbiddenHeader(String header); static void excludeHeaders(HttpRequestMessage request, String[] exclusions); static void restrictHeaders(HttpRequestMessage request, String[] restrictions); static void mergeHeaders(HttpRequestMessage from, HttpRequestMessage to, String[] ignoreHeaders); static void removeValueFromHeaders(HttpRequestMessage request, String[] headerNames, String valueToRemove); static void mergeParameters(HttpRequestMessage from, HttpRequestMessage to); static void mergeCookies(HttpRequestMessage from, HttpRequestMessage to); static String mergeQueryParameters(URI from, String into); static boolean hasStreamingScheme(URI uri); static boolean hasStreamingScheme(String uri); }
HttpUtils { public static URI getCanonicalURI(URI uri, boolean canonicalizePath) { URI canonicalURI = uri; if (uri != null) { String host = uri.getHost(); String path = uri.getPath(); final boolean emptyPath = "".equals(path); final boolean noPathToCanonicalize = canonicalizePath && (path == null || emptyPath); final boolean trailingSlashPath = "/".equals(path); final boolean pathlessScheme = "ssl".equals(uri.getScheme()) || "tcp".equals(uri.getScheme()) || "pipe".equals(uri.getScheme()) || "udp".equals(uri.getScheme()); final boolean trailingSlashWithPathlessScheme = trailingSlashPath && pathlessScheme; String newPath = trailingSlashWithPathlessScheme ? "" : noPathToCanonicalize ? (pathlessScheme ? null : "/") : null; if (((host != null) && !host.equals(host.toLowerCase())) || newPath != null) { path = newPath == null ? path : newPath; try { canonicalURI = new URI(uri.getScheme(), uri.getUserInfo(), host == null ? null : host.toLowerCase(), uri.getPort(), path, uri.getQuery(), uri.getFragment()); } catch (URISyntaxException ex) { throw new IllegalArgumentException("Invalid URI: " + uri + " in Gateway configuration file", ex); } } } return canonicalURI; }  static String getHostDomain(HttpRequestMessage httpRequest); static String getHostAndPort(HttpRequestMessage httpRequest, boolean secure); static String getHostAndPort(String authority, boolean secure); static long parseDateHeader(String header); static String formatDateHeader(long millis); static void fileRequested(IoBufferAllocatorEx<?> allocator, HttpRequestMessage httpRequest,
        HttpResponseMessage httpResponse, File requestFile); static void writeIfModified(HttpAcceptSession httpSession, File requestFile); static IoBufferEx getBufferForFile(IoBufferAllocatorEx<?> allocator, File requestFile); static boolean hasBeenModified(HttpSession session, String etag, File requestFile); static void addLastModifiedHeader(HttpSession session, File requestFile); static String getETagHeaderValue(File requestFile); static void supplyScriptAsHtml(File xdBridgeFile, long startTime, String resourcePath); static void supplyFile(File bridgeFile, long startTime, String resourcePath); static boolean canStream(HttpSession session); static String newSessionId(); static URI getRequestURI(HttpRequestMessage request, IoSession session); static URI getRequestURI(URI requestURI, String hostHeader, IoSession session); static boolean hasCloseHeader(List<String> connectionValues); static URI getTransportURI(HttpRequestMessage request, IoSession session); static boolean isChunked(String transferEncoding); static boolean isChunked(HttpResponseMessage response); static boolean isGzipped(HttpResponseMessage response); static URI getCanonicalURI(URI uri, boolean canonicalizePath); static URI getCanonicalURI(String uriString, boolean canonicalizePath); static String[] getPathComponents(URI uri); static String getAuthenticationTokenFromPath(URI uri); static boolean containsForbiddenHeaders(HttpRequestMessage request, String[] allowedHeaders); static boolean isForbiddenHeader(String header); static void excludeHeaders(HttpRequestMessage request, String[] exclusions); static void restrictHeaders(HttpRequestMessage request, String[] restrictions); static void mergeHeaders(HttpRequestMessage from, HttpRequestMessage to, String[] ignoreHeaders); static void removeValueFromHeaders(HttpRequestMessage request, String[] headerNames, String valueToRemove); static void mergeParameters(HttpRequestMessage from, HttpRequestMessage to); static void mergeCookies(HttpRequestMessage from, HttpRequestMessage to); static String mergeQueryParameters(URI from, String into); static boolean hasStreamingScheme(URI uri); static boolean hasStreamingScheme(String uri); static Map<String, List<String>> EMPTY_HEADERS; }