You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Remis (JIRA)" <ji...@apache.org> on 2014/03/04 11:29:22 UTC

[jira] [Comment Edited] (HTTPCORE-365) HttpHost(hostname) should be able to parse format hostname:port

    [ https://issues.apache.org/jira/browse/HTTPCORE-365?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13919221#comment-13919221 ] 

Remis edited comment on HTTPCORE-365 at 3/4/14 10:28 AM:
---------------------------------------------------------

A possible implementation:
{code}
/**
 * Parse the proxyString as an HttpHost with localhost and port.
 * 
 * @param proxyString
 *            the proxy String in the format hostname:port
 * 
 * @return the proxy as an HttpHost with localhost and port
 */
private HttpHost parseProxyString(final String proxyString) {
	if (proxyString == null || proxyString.trim().isEmpty()) {
		return null;
	}

	// validate proxy format
	Args.check(proxyString.contains(":"), "proxy format is invalid. It must have the format hostname:port.");

	// split the proxy in hostname:port
	final String[] proxyParts = proxyString.split(":");
	final String hostname = proxyParts[0].trim();
	final int port = Integer.valueOf(proxyParts[1].trim());

	return new HttpHost(hostname, port);
}
{code}


was (Author: remisbaima):
A possible implementation:
{code}
/**
 * Parse the proxyString as an HttpHost with localhost and port.
 * 
 * @param proxyString
 *            the proxy String in the format hostname:port
 * 
 * @return the proxy as an HttpHost with localhost and port
 */
private HttpHost parseProxyString(final String proxyString) {
	if (proxyString == null || proxyString.trim().isEmpty()) {
		return null;
	}

	// validate proxy format
	Args.check(proxyString.contains(":"), "proxy format is invalid. It must have the format hostname:port.");

	// split the proxy in hostname:port
	final String[] proxyParts = proxyString.split(":");
	final String hostname = proxyParts[0].trim();
	final int port = Integer.parseInt(proxyParts[1].trim());

	return new HttpHost(hostname, port);
}
{code}

> HttpHost(hostname) should be able to parse format hostname:port
> ---------------------------------------------------------------
>
>                 Key: HTTPCORE-365
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-365
>             Project: HttpComponents HttpCore
>          Issue Type: New Feature
>          Components: HttpCore
>    Affects Versions: 4.3
>         Environment: JDK6
>            Reporter: Remis
>            Priority: Minor
>             Fix For: 4.4
>
>
> When we write e.g.:
> HttpHost proxy = new HttpHost("my-proxy:8080");
> HttpHost interprets it as a hostname="my-proxy:8080" and port=-1. I believe it should be able to parse the exemplified "my-proxy:8080" correctly.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org