commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsde...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient HttpMethodBase.java
Date Fri, 02 Aug 2002 11:40:45 GMT
jsdever     2002/08/02 04:40:45

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodBase.java
  Log:
  Fix for http://nagoya.apache.org/bugzilla/show_bug.cgi?id=11220
  
  Changes the logic for when to add the Host header with the default port or not.
  
  Based on patch by Xiaowei Jiang
  
  Revision  Changes    Path
  1.42      +21 -15    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
  
  Index: HttpMethodBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- HttpMethodBase.java	2 Aug 2002 06:37:26 -0000	1.41
  +++ HttpMethodBase.java	2 Aug 2002 11:40:45 -0000	1.42
  @@ -944,19 +944,25 @@
   
           String host = conn.getHost();
           int port = conn.getPort();
  +
  +        if (requestHeaders.containsKey("host")){
  +            log.debug("Request to add Host header ignored: header already added");
  +            return;
  +        }
           
  -        if (!requestHeaders.containsKey("host")) {
  -            if (!isIpAddress(host)) {
  -                if (port == 80) {
  -                    setRequestHeader("Host", host);
  -                } else {
  -                    setRequestHeader("Host", host + ":" + port);
  -                }
  -            } else {
  -                setRequestHeader("Host", "");
  -            }
  +        if (isIpAddress(host)) {
  +            log.debug("Request to add Host header ignored: host is an ipaddress");
  +            return;
           }
  -    }
  +
  +        log.debug("Adding Host request header");
  +        //appends the port only if not using the default port for the protocol
  +        if(conn.isSecure()) {
  +            setRequestHeader("Host", (port==443) ? host : host+':'+port);
  +        } else {
  +            setRequestHeader("Host", (port==80) ? host : host+':'+port);
  +        }    
  +    }       
   
       /**
        * Adds a <tt>Cookie</tt> request containing the matching {@link Cookie}s.
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message