hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jasper van Zandbeek" <jasper.van.zandb...@quinity.com>
Subject RE: [PATCH] HttpClient: possibility to specify port number in Host headers
Date Fri, 06 Jan 2006 07:15:26 GMT
The port number specified with calling setHost of HostConfiguration is the port used for the
connection and the port given in the Host request header. So in your example, the connection
is to localhost:100 and the Host header is Host: localhost:100. In the example I've given,
the connection is to localhost:80 and the Host header is Host: localhost:100.
 
It is currently not possible to have a different port number for the connection and in the
Host header. The provided patch adds this functionality.
 
Jasper

	-----Oorspronkelijk bericht----- 
	Van: Oleg Kalnichevski [mailto:olegk@apache.org] 
	Verzonden: do 5-1-2006 17:16 
	Aan: httpclient-dev@jakarta.apache.org 
	CC: 
	Onderwerp: Re: [PATCH] HttpClient: possibility to specify port number in Host headers
	
	

	On Thu, Jan 05, 2006 at 03:36:04PM +0100, Jasper van Zandbeek wrote:
	> Hello,
	>
	> The attached patch adds the possibility to specify the port number for virtual hosts.
	>
	> HttpClient currently uses the port number of the connection in the Host request header
if the port number is different from the default port number for the protocol. Currently it
isn't possible to specify a port number different from the port number of the connection.
This patch adds this functionality.
	>
	> According to the HTTP/1.1 specification, the port number specified in the Host request
header doesn't need to be the same as the port number of the connection. Some web servers,
e.g. Apache, ignore a different port number, but e.g. the application server WebSphere allows
the port number of the connection and the port number in the Host header to be different.
	>
	> This patch allows users of HttpClient to use a different port number for the Host request
header if the webserver they connect to supports this.
	>
	> Here's a code snippet that uses the patched code:
	>
	> HttpClient httpClient = new HttpClient();
	> HttpMethod method = new GetMethod();
	> HostConfiguration hostConfiguration = new HostConfiguration();
	> hostConfiguration.setHost("localhost", 80, "http");
	> HostParams params = new HostParams();
	> params.setVirtualHost("localhost");
	> params.setVirtualHostPort(100);
	> hostConfiguration.setParams(params);
	> httpClient.executeMethod(hostConfiguration, method);
	> System.out.println(method.getResponseBodyAsString());
	> method.releaseConnection();
	>
	> Kind regards,
	>
	> Jasper van Zandbeek
	>
	
	What's wrong with this?
	
	HttpClient httpClient = new HttpClient();
	HttpMethod method = new GetMethod();
	HostConfiguration hostConfiguration = new HostConfiguration();
	hostConfiguration.setHost("localhost", 100, "http");
	HostParams params = new HostParams();
	params.setVirtualHost("localhost");
	hostConfiguration.setParams(params);
	httpClient.executeMethod(hostConfiguration, method);
	System.out.println(method.getResponseBodyAsString());
	method.releaseConnection();
	
	Oleg
	
	> 
	>  <<patchfile.txt>>
	
	Content-Description: patchfile.txt
	> --- org\apache\commons\httpclient\HttpMethodBase.java.orig    2006-01-05 04:03:48.000000000
+0100
	> +++ org\apache\commons\httpclient\HttpMethodBase.java 2006-01-05 14:02:22.108177600
+0100
	> @@ -1221,7 +1221,13 @@
	>          } else {
	>              host = conn.getHost();
	>          }
	> -        int port = conn.getPort();
	> +        int port = this.params.getVirtualHostPort();
	> +        if (port == -1) {
	> +            port = conn.getPort();
	> +        }
	> +        else {
	> +            LOG.debug("Using virtual host port: " + port);
	> +        }
	> 
	>          // Note: RFC 2616 uses the term "internet host name" for what goes on the
	>          // host line.  It would seem to imply that host should be blank if the
	> --- org\apache\commons\httpclient\params\HostParams.java.orig 2006-01-05 04:03:48.000000000
+0100
	> +++ org\apache\commons\httpclient\params\HostParams.java      2006-01-05 14:01:37.857044800
+0100
	> @@ -97,5 +97,23 @@
	>      public String getVirtualHost() {
	>          return (String) getParameter(HttpMethodParams.VIRTUAL_HOST);
	>      }
	> +  
	> +    /**
	> +     * Sets the virtual host port.
	> +     *
	> +     * @param port The port
	> +     */
	> +    public void setVirtualHostPort(int port) {
	> +         setIntParameter(HttpMethodParams.VIRTUAL_HOST_PORT, port);
	> +    }
	> +   
	> +    /**
	> +     * Returns the virtual host port.
	> +     *
	> +     * @return The virtual host port
	> +     */
	> +    public int getVirtualHostPort() {
	> +        return getIntParameter(HttpMethodParams.VIRTUAL_HOST_PORT, -1);
	> +    }  
	>         
	>  }
	> --- org\apache\commons\httpclient\params\HttpMethodParams.java.orig   2006-01-05 04:03:48.000000000
+0100
	> +++ org\apache\commons\httpclient\params\HttpMethodParams.java        2006-01-05 14:10:34.334917000
+0100
	> @@ -265,6 +265,14 @@
	>      public static final String VIRTUAL_HOST = "http.virtual-host";
	> 
	>      /**
	> +     * Defines the virtual host port.
	> +     * <p>
	> +     * This parameter expects a value of type (@link Integer).
	> +     * </p>
	> +     */
	> +    public static final String VIRTUAL_HOST_PORT = "http.virtual-host-port";
	> +
	> +    /**
	>       * Sets the value to use as the multipart boundary.
	>       * <p>
	>       * This parameter expects a value if type {@link String}.
	> @@ -459,6 +467,24 @@
	>          return (String) getParameter(VIRTUAL_HOST);
	>      }
	>     
	> +    /**
	> +     * Sets the virtual host port.
	> +     *
	> +     * @param port The host port
	> +     */
	> +    public void setVirtualHostPort(int port) {
	> +        setIntParameter(VIRTUAL_HOST_PORT, port);
	> +    }
	> +   
	> +    /**
	> +     * Returns the virtual host port.
	> +     *
	> +     * @return The virutal host port.
	> +     */
	> +    public int getVirtualHostPort() {
	> +        return getIntParameter(VIRTUAL_HOST_PORT, -1);
	> +    }   
	> +   
	>      private static final String[] PROTOCOL_STRICTNESS_PARAMETERS = {
	>          UNAMBIGUOUS_STATUS_LINE,
	>          SINGLE_COOKIE_HEADER,
	
	> ---------------------------------------------------------------------
	> To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
	> For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
	
	---------------------------------------------------------------------
	To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
	For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
	
	

Mime
View raw message