/** * 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 : ""); }
if (this.uri.getScheme() != null) { uriBuilder.append(this.uri.getScheme()).append(':'); if (this.uri.getRawUserInfo() != null || this.uri.getHost() != null) { uriBuilder.append("//"); if (this.uri.getRawUserInfo() != null) { uriBuilder.append(this.uri.getRawUserInfo()).append('@'); if (this.uri.getHost() != null) { uriBuilder.append(this.uri.getHost()); uriBuilder.append(this.uriPath); if (this.uri.getRawQuery() != null) { uriBuilder.append('?').append(this.uri.getRawQuery()); if (this.uri.getRawFragment() != null) { uriBuilder.append('#').append(this.uri.getRawFragment());
String path; String query; if (_ref.getScheme() != null) { scheme = _ref.getScheme(); authority = _ref.getAuthority(); path = removeDots(_ref.getPath()); query = _ref.getRawQuery(); } else { if (_ref.getAuthority() != null) { authority = _ref.getAuthority(); path = _ref.getPath(); query = _ref.getRawQuery(); } else { if (_ref.getPath().length() == 0) { path = base.getPath(); if (_ref.getRawQuery() != null) { query = _ref.getRawQuery(); } else { query = base.getRawQuery(); query = _ref.getRawQuery(); scheme = base.getScheme();
String query = uri.getRawQuery(); // Don't decode anything here String queryFragment = resource.getTokenName() + "=" + URLEncoder.encode(accessToken.getValue(), "UTF-8"); if (query == null) { URI update = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), null, null);
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); }
/** * 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; }
/** * Determines if a given URI is plain, i.e. it does not contain a query or a fragment. * @param uri The URI to check to for plainness. * @throws NullPointerException if the given URI is <code>null</code>. * @return <code>true</code> if the URI has no query or fragment. */ public static boolean isPlainURI(final URI uri) { requireNonNull(uri, "URI cannot be null"); return uri.getRawQuery() == null && uri.getRawFragment() == null; //see if there is no query and no fragment }
this.scheme = uri.getScheme(); if (uri.isOpaque()) { this.ssp = uri.getRawSchemeSpecificPart(); this.userInfo = uri.getRawUserInfo(); if (uri.getHost() != null) { this.host = uri.getHost(); 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();
/** * Replace query in the URI. * Userinfo cleared if uri contained a query. * Fragment cleared if uri contained a query. * * @param query an ENCODED query, removed if null * @since 0.9 */ private static URI replaceQuery(URI uri, String query) throws URISyntaxException { URI rv = uri; if(rv.getRawQuery() != null) { rv = new URI(rv.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), null, null); } if(query != null) { String newURI = rv.toASCIIString() + '?' + query; rv = new URI(newURI); } return rv; }
URI uri = createURI(sb.toString()); if (uri.getRawSchemeSpecificPart() != null && uri.getRawPath() == null) { this.ssp = uri.getRawSchemeSpecificPart(); } else { if (uri.getRawUserInfo() == null && uri.getHost() == null && uri.getPort() == -1) { authority = uri.getRawAuthority(); userInfo = null; authority = null; userInfo = uri.getRawUserInfo(); host = uri.getHost(); port = uri.getPort(); path.append(replaceNull(uri.getRawPath())); query.append(replaceNull(uri.getRawQuery()));
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());
String path; String query; if (_ref.getScheme() != null) { scheme = _ref.getScheme(); authority = _ref.getAuthority(); path = removeDots(_ref.getPath()); query = _ref.getRawQuery(); } else { if (_ref.getAuthority() != null) { authority = _ref.getAuthority(); path = _ref.getPath(); query = _ref.getRawQuery(); } else { if (_ref.getPath().length() == 0) { path = base.getPath(); if (_ref.getRawQuery() != null) { query = _ref.getRawQuery(); } else { query = base.getRawQuery(); query = _ref.getRawQuery(); scheme = base.getScheme();
/** * 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); }
@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); }
private URI getModifiedUri(URI uri) throws UnsupportedEncodingException, URISyntaxException { Map<String, String> incomingParams = HttpUtilities.stringToUrlParams(uri.getRawQuery(), HttpUtilities.UTF8_CONSTANT); String modifiedIncomingQuery = HttpUtilities.urlParamsToString(_transform.transform(incomingParams), HttpUtilities.UTF8_CONSTANT); return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), modifiedIncomingQuery, uri.getFragment()); } }
/** * 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 ); }
String scheme = uri.getScheme(); String userInfo = uri.getUserInfo(); String host = Misc.extractHost(uri); int port = uri.getPort(); String path = uri.getRawPath(); String query = uri.getRawQuery();
/** * 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; }