/** * Return the {@code Request-Uri} representation as defined by HTTP spec. For example: * <pre><Method> <Request-URI> HTTP/<Version> (e.g. GET /auth;foo=bar/hello?foo=bar HTTP/1.1)</pre> * * @param uri uri to obtain {@code Request-Uri} from. * @return {@code Request-Uri} representation or {@code null} if {@code uri} is not provided. */ public static String fullRelativeUri(final URI uri) { if (uri == null) { return null; } final String query = uri.getRawQuery(); return uri.getRawPath() + (query != null && query.length() > 0 ? "?" + query : ""); }
/* for testing */ static boolean hasAnotherScheme(URI uri) { return schemePattern.matcher(uri.getSchemeSpecificPart()).matches() && uri.getHost() == null && uri.getRawPath() == null; } }
protected URIBuilder setQueryNVP(List<NameValuePair> nvp) throws URISyntaxException { /* Passing the query string in the URI constructor will * double-escape query parameters and goober things up. So we have * to create a full path+query+fragment and use URI#resolve() to * create the new URI. */ StringBuilder sb = new StringBuilder(); String path = base.getRawPath(); if (path != null) sb.append(path); sb.append('?'); sb.append(format(nvp, isUrlEncodingEnabled, enc)); String frag = base.getRawFragment(); if (frag != null) sb.append('#').append(frag); this.base = base.resolve(sb.toString()); return this; }
this.scheme = uri.getScheme(); if (uri.isOpaque()) { this.ssp = uri.getRawSchemeSpecificPart(); this.userInfo = uri.getRawUserInfo(); if (uri.getHost() != null) { this.host = uri.getHost(); if (uri.getPort() != -1) { this.port = String.valueOf(uri.getPort()); if (StringUtils.hasLength(uri.getRawPath())) { this.pathBuilder = new CompositePathComponentBuilder(); this.pathBuilder.addPath(uri.getRawPath()); if (StringUtils.hasLength(uri.getRawQuery())) { this.queryParams.clear(); query(uri.getRawQuery()); if (uri.getRawFragment() != null) { this.fragment = uri.getRawFragment();
return false; if (hostname != null && !hostname.equals(uri.getHost())) { return false; if (path != null && !path.equals(uri.getRawPath())) { return false; if (noParams && !uri.getRawQuery().equals(null)) { return false;
private ArmeriaClientHttpRequest createRequest(HttpMethod method, URI uri) { final String scheme = uri.getScheme(); final String authority = uri.getRawAuthority(); final String path = uri.getRawPath(); final String query = uri.getRawQuery(); checkArgument(!Strings.isNullOrEmpty(authority), "URI is not absolute: " + uri); checkArgument(!Strings.isNullOrEmpty(path), "path is undefined: " + uri); final URI baseUri = URI.create(Strings.isNullOrEmpty(scheme) ? authority : scheme + "://" + authority); final HttpClientBuilder builder = new HttpClientBuilder(baseUri); configurators.forEach(c -> c.configure(builder)); final String pathAndQuery = Strings.isNullOrEmpty(query) ? path : path + '?' + query; return new ArmeriaClientHttpRequest(builder.build(), method, pathAndQuery, uri, factoryWrapper); }
public String normalizeRequestUrl() throws URISyntaxException { URI uri = new URI(request.getRequestUrl()); String scheme = uri.getScheme().toLowerCase(); String authority = uri.getAuthority().toLowerCase(); boolean dropPort = (scheme.equals("http") && uri.getPort() == 80) || (scheme.equals("https") && uri.getPort() == 443); if (dropPort) { // find the last : in the authority int index = authority.lastIndexOf(":"); if (index >= 0) { authority = authority.substring(0, index); } } String path = uri.getRawPath(); if (path == null || path.length() <= 0) { path = "/"; // conforms to RFC 2616 section 3.2.2 } // we know that there is no query and no fragment here. return scheme + "://" + authority + path; }
/** * Generate a HTTP/2 {code :path} from a URI in accordance with * <a href="https://tools.ietf.org/html/rfc7230#section-5.3">rfc7230, 5.3</a>. */ private static String toHttp2Path(URI uri) { final StringBuilder pathBuilder = new StringBuilder( length(uri.getRawPath()) + length(uri.getRawQuery()) + length(uri.getRawFragment()) + 2); if (!isNullOrEmpty(uri.getRawPath())) { pathBuilder.append(uri.getRawPath()); } if (!isNullOrEmpty(uri.getRawQuery())) { pathBuilder.append('?'); pathBuilder.append(uri.getRawQuery()); } if (!isNullOrEmpty(uri.getRawFragment())) { pathBuilder.append('#'); pathBuilder.append(uri.getRawFragment()); } return pathBuilder.length() != 0 ? pathBuilder.toString() : EMPTY_REQUEST_PATH; }
@Override public WebSocketStream websocketStreamAbs(String url, MultiMap headers, WebsocketVersion version, String subProtocols) { URI uri; try { uri = new URI(url); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } String scheme = uri.getScheme(); if (!"ws".equals(scheme) && !"wss".equals(scheme)) { throw new IllegalArgumentException("Scheme: " + scheme); } boolean ssl = scheme.length() == 3; int port = uri.getPort(); if (port == -1) port = ssl ? 443 : 80; StringBuilder relativeUri = new StringBuilder(); if (uri.getRawPath() != null) { relativeUri.append(uri.getRawPath()); } if (uri.getRawQuery() != null) { relativeUri.append('?').append(uri.getRawQuery()); } if (uri.getRawFragment() != null) { relativeUri.append('#').append(uri.getRawFragment()); } RequestOptions options = new RequestOptions().setHost(uri.getHost()).setPort(port).setSsl(ssl).setURI(relativeUri.toString()); return websocketStream(options, headers, version, subProtocols); }
/** * Create and send the handshake to the other endpoint * @throws InvalidHandshakeException a invalid handshake was created */ private void sendHandshake() throws InvalidHandshakeException { String path; String part1 = uri.getRawPath(); String part2 = uri.getRawQuery(); if( part1 == null || part1.length() == 0 ) path = "/"; else path = part1; if( part2 != null ) path += '?' + part2; int port = getPort(); String host = uri.getHost() + ( (port != WebSocketImpl.DEFAULT_PORT && port != WebSocketImpl.DEFAULT_WSS_PORT) ? ":" + port : "" ); HandshakeImpl1Client handshake = new HandshakeImpl1Client(); handshake.setResourceDescriptor( path ); handshake.put( "Host", host ); if( headers != null ) { for( Map.Entry<String,String> kv : headers.entrySet() ) { handshake.put( kv.getKey(), kv.getValue() ); } } engine.startHandshake( handshake ); }
authority = firstNonNull(uri.getRawAuthority(), FALLBACK_AUTHORITY); final String schemeStr = uri.getScheme(); if (schemeStr != null && schemeStr.indexOf('+') < 0) { sessionProtocol = SessionProtocol.find(schemeStr).orElseThrow( if (uri.getRawQuery() != null) { pathAndQuery = PathAndQuery.parse(uri.getRawPath() + '?' + uri.getRawQuery()); } else { pathAndQuery = PathAndQuery.parse(uri.getRawPath());
/** * Return the {@code Request-Uri} representation as defined by HTTP spec. For example: * <pre><Method> <Request-URI> HTTP/<Version> (e.g. GET /auth;foo=bar/hello?foo=bar HTTP/1.1)</pre> * * @param uri uri to obtain {@code Request-Uri} from. * @return {@code Request-Uri} representation or {@code null} if {@code uri} is not provided. */ public static String fullRelativeUri(final URI uri) { if (uri == null) { return null; } final String query = uri.getRawQuery(); return uri.getRawPath() + (query != null && query.length() > 0 ? "?" + query : ""); }
/** * Generate a HTTP/2 {code :path} from a URI in accordance with * <a href="https://tools.ietf.org/html/rfc7230#section-5.3">rfc7230, 5.3</a>. */ private static AsciiString toHttp2Path(URI uri) { StringBuilder pathBuilder = new StringBuilder(length(uri.getRawPath()) + length(uri.getRawQuery()) + length(uri.getRawFragment()) + 2); if (!isNullOrEmpty(uri.getRawPath())) { pathBuilder.append(uri.getRawPath()); } if (!isNullOrEmpty(uri.getRawQuery())) { pathBuilder.append('?'); pathBuilder.append(uri.getRawQuery()); } if (!isNullOrEmpty(uri.getRawFragment())) { pathBuilder.append('#'); pathBuilder.append(uri.getRawFragment()); } String path = pathBuilder.toString(); return path.isEmpty() ? EMPTY_REQUEST_PATH : new AsciiString(path); }
protected URIBuilder setQueryNVP(List<NameValuePair> nvp) throws URISyntaxException { /* Passing the query string in the URI constructor will * double-escape query parameters and goober things up. So we have * to create a full path+query+fragment and use URI#resolve() to * create the new URI. */ StringBuilder sb = new StringBuilder(); String path = base.getRawPath(); if (path != null) sb.append(path); sb.append('?'); sb.append(format(nvp, isUrlEncodingEnabled, enc)); String frag = base.getRawFragment(); if (frag != null) sb.append('#').append(frag); this.base = base.resolve(sb.toString()); return this; }
private static void checkURI(URI uri) { if (!uri.isAbsolute()) { throw new IllegalArgumentException("URI is not absolute: " + uri); } else if (!uri.getRawSchemeSpecificPart().startsWith("/")) { throw new IllegalArgumentException("URI is not hierarchical: " + uri); } if (!"file".equals(uri.getScheme())) { throw new IllegalArgumentException("Expected file scheme in URI: " + uri); } String rawPath = uri.getRawPath(); if (rawPath == null || rawPath.isEmpty()) { throw new IllegalArgumentException("Expected non-empty path in URI: " + uri); } if (uri.getRawAuthority() != null) { throw new IllegalArgumentException("Found authority in URI: " + uri); } if (uri.getRawQuery() != null) { throw new IllegalArgumentException("Found query in URI: " + uri); } if (uri.getRawFragment() != null) { throw new IllegalArgumentException("Found fragment in URI: " + uri); } }
@Override public void operationComplete(ChannelFuture future) throws Exception { if ( future.isSuccess() ) { String path = uri.getRawPath() + ( ( uri.getRawQuery() == null ) ? "" : "?" + uri.getRawQuery() ); HttpRequest request = new DefaultHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.GET, path ); request.headers().set( HttpHeaders.Names.HOST, uri.getHost() ); future.channel().writeAndFlush( request ); } else { addressCache.invalidate( uri.getHost() ); callback.done( null, future.cause() ); } } };
/** * Return the constructed raw path for the give {@link URI}. */ static String rawPath(URI wsURL) { String path = wsURL.getRawPath(); String query = wsURL.getRawQuery(); if (query != null && !query.isEmpty()) { path = path + '?' + query; } return path == null || path.isEmpty() ? "/" : path; }
target.getHostName(), target.getPort(), uri.getRawPath(), uri.getRawQuery(), dropFragment ? null : uri.getRawFragment()); } else { return URIUtils.createURI( null, -1, uri.getRawPath(), uri.getRawQuery(), dropFragment ? null : uri.getRawFragment());
private void checkURI(URI uri) { if (!uri.isAbsolute()) { throw new IllegalArgumentException(); } else if (!uri.getRawSchemeSpecificPart().startsWith("/")) { throw new IllegalArgumentException(); } String temp = uri.getScheme(); if (temp == null || !temp.equals("file")) { throw new IllegalArgumentException(); } temp = uri.getRawPath(); if (temp == null || temp.length() == 0) { throw new IllegalArgumentException(); } if (uri.getRawAuthority() != null) { throw new IllegalArgumentException(); } if (uri.getRawQuery() != null) { throw new IllegalArgumentException(); } if (uri.getRawFragment() != null) { throw new IllegalArgumentException(); } }
String path = url.getRawPath(); String query = url.getRawQuery(); if (query != null) path = path + '?' + query; path = '/' + path; buf.append("GET ").append(path).append(" HTTP/1.1\r\n" + "Host: ").append(url.getHost()).append("\r\n"); if (_alreadyTransferred > 0) { buf.append("Range: bytes=");