You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bi...@apache.org on 2005/03/25 04:53:25 UTC

cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http MimeHeaders.java

billbarker    2005/03/24 19:53:25

  Modified:    util/java/org/apache/tomcat/util/http MimeHeaders.java
  Log:
  Make setValue guarantee that the header is unique (that's how it's being used anyway).
  
  Fix for Bug #34113
  
  Revision  Changes    Path
  1.7       +30 -18    jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/MimeHeaders.java
  
  Index: MimeHeaders.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/MimeHeaders.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MimeHeaders.java	24 Feb 2004 08:50:04 -0000	1.6
  +++ MimeHeaders.java	25 Mar 2005 03:53:25 -0000	1.7
  @@ -262,13 +262,19 @@
   	if this .
       */
       public MessageBytes setValue( String name ) {
  - 	MessageBytes value=getValue(name);
  -	if( value == null ) {
  -	    MimeHeaderField mh = createHeader();
  -	    mh.getName().setString(name);
  -	    value=mh.getValue();
  -	}
  -	return value;
  +        for ( int i = 0; i < count; i++ ) {
  +            if(headers[i].getName().equalsIgnoreCase(name)) {
  +                for ( int j=i+1; j < count; j++ ) {
  +                    if(headers[j].getName().equalsIgnoreCase(name)) {
  +                        removeHeader(j--);
  +                    }
  +                }
  +                return headers[i].getValue();
  +            }
  +        }
  +        MimeHeaderField mh = createHeader();
  +        mh.getName().setString(name);
  +        return mh.getValue();
       }
   
       //-------------------- Getting headers --------------------
  @@ -304,19 +310,25 @@
           // warning: rather sticky code; heavily tuned
   
           for (int i = 0; i < count; i++) {
  -	    if (headers[i].getName().equalsIgnoreCase(name)) {
  -	        // reset and swap with last header
  -	        MimeHeaderField mh = headers[i];
  -
  -		mh.recycle();
  -		headers[i] = headers[count - 1];
  -		headers[count - 1] = mh;
  +            if (headers[i].getName().equalsIgnoreCase(name)) {
  +                removeHeader(i--);
  +            }
  +        }
  +    }
   
  -		count--;
  -		i--;
  -	    }
  -	}
  +    /**
  +     * reset and swap with last header
  +     * @param idx the index of the header to remove.
  +     */
  +    private void removeHeader(int idx) {
  +        MimeHeaderField mh = headers[idx];
  +        
  +        mh.recycle();
  +        headers[idx] = headers[count - 1];
  +        headers[count - 1] = mh;
  +        count--;
       }
  +
   }
   
   /** Enumerate the distinct header names.
  
  
  

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


Re: cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http MimeHeaders.java

Posted by Remy Maucherat <re...@apache.org>.
billbarker@apache.org wrote:
> billbarker    2005/03/24 19:53:25
> 
>   Modified:    util/java/org/apache/tomcat/util/http MimeHeaders.java
>   Log:
>   Make setValue guarantee that the header is unique (that's how it's being used anyway).
>   
>   Fix for Bug #34113

>   - 	MessageBytes value=getValue(name);
>   -	if( value == null ) {
>   -	    MimeHeaderField mh = createHeader();
>   -	    mh.getName().setString(name);
>   -	    value=mh.getValue();
>   -	}
>   -	return value;
>   +        for ( int i = 0; i < count; i++ ) {
>   +            if(headers[i].getName().equalsIgnoreCase(name)) {
>   +                for ( int j=i+1; j < count; j++ ) {
>   +                    if(headers[j].getName().equalsIgnoreCase(name)) {
>   +                        removeHeader(j--);
>   +                    }
>   +                }
>   +                return headers[i].getValue();
>   +            }
>   +        }
>   +        MimeHeaderField mh = createHeader();
>   +        mh.getName().setString(name);
>   +        return mh.getValue();

This should be more efficient as I don't like what removeHeader does. 
Since it only happens when actually having a multi valued header, it is 
not that critical, however.

Rémy

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