"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "httpclient5/src/main/java/org/apache/hc/client5/http/utils/URIUtils.java" between
httpcomponents-client-5.0.2-src.tar.gz and httpcomponents-client-5.0.3-src.tar.gz

About: HttpComponents is an Apache project responsible for creating and maintaining a toolset of low level Java components focused on HTTP and associated protocols. Java sources.

URIUtils.java  (httpcomponents-client-5.0.2-src):URIUtils.java  (httpcomponents-client-5.0.3-src)
skipping to change at line 253 skipping to change at line 253
* @param uri * @param uri
* @return the target host if the URI is absolute or {@code null} if the URI is * @return the target host if the URI is absolute or {@code null} if the URI is
* relative or does not contain a valid host name. * relative or does not contain a valid host name.
* *
* @since 4.1 * @since 4.1
*/ */
public static HttpHost extractHost(final URI uri) { public static HttpHost extractHost(final URI uri) {
if (uri == null) { if (uri == null) {
return null; return null;
} }
HttpHost target = null;
if (uri.isAbsolute()) { if (uri.isAbsolute()) {
int port = uri.getPort(); // may be overridden later if (uri.getHost() == null) { // normal parse failed; let's do it our
String host = uri.getHost(); selves
if (host == null) { // normal parse failed; let's do it ourselves
// authority does not seem to care about the valid character-set for host names // authority does not seem to care about the valid character-set for host names
host = uri.getAuthority(); if (uri.getAuthority() != null) {
if (host != null) { String content = uri.getAuthority();
// Strip off any leading user credentials // Strip off any leading user credentials
final int at = host.indexOf('@'); int at = content.indexOf('@');
if (at >= 0) { if (at != -1) {
if (host.length() > at+1 ) { content = content.substring(at + 1);
host = host.substring(at+1);
} else {
host = null; // @ on its own
}
} }
// Extract the port suffix, if present final String scheme = uri.getScheme();
if (host != null) { final String hostname;
final int colon = host.indexOf(':'); final int port;
if (colon >= 0) { at = content.indexOf(":");
final int pos = colon + 1; if (at != -1) {
int len = 0; hostname = content.substring(0, at);
for (int i = pos; i < host.length(); i++) { try {
if (Character.isDigit(host.charAt(i))) { final String portText = content.substring(at + 1);
len++; port = !TextUtils.isEmpty(portText) ? Integer.parseI
} else { nt(portText) : -1;
break; } catch (final NumberFormatException ex) {
} return null;
}
if (len > 0) {
try {
port = Integer.parseInt(host.substring(pos,
pos + len));
} catch (final NumberFormatException ex) {
}
}
host = host.substring(0, colon);
} }
} else {
hostname = content;
port = -1;
}
try {
return new HttpHost(scheme, hostname, port);
} catch (final IllegalArgumentException ex) {
return null;
} }
} }
} } else {
final String scheme = uri.getScheme(); return new HttpHost(uri.getScheme(), uri.getHost(), uri.getPort(
if (!TextUtils.isBlank(host)) { ));
try {
target = new HttpHost(scheme, host, port);
} catch (final IllegalArgumentException ignore) {
}
} }
} }
return target; return null;
} }
/** /**
* Derives the interpreted (absolute) URI that was used to generate the last * Derives the interpreted (absolute) URI that was used to generate the last
* request. This is done by extracting the request-uri and target origin for * request. This is done by extracting the request-uri and target origin for
* the last request and scanning all the redirect locations for the last * the last request and scanning all the redirect locations for the last
* fragment identifier, then combining the result into a {@link URI}. * fragment identifier, then combining the result into a {@link URI}.
* *
* @param originalURI * @param originalURI
* original request before any redirects * original request before any redirects
 End of changes. 8 change blocks. 
42 lines changed or deleted 31 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)