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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to