/** * Set the value of the header to the supplied value; any existing headers * are removed. * * @param name * the name of the header * @param value * the new value */ public void setHeader(String name, String value) { // look for a header match for (int i = 0; i < headers.size(); i++) { InternetHeader header = (InternetHeader)headers.get(i); // found a matching header if (name.equalsIgnoreCase(header.getName())) { // we update both the name and the value for a set so that // the header ends up with the same case as what is getting set header.setValue(value); header.setName(name); // remove all of the headers from this point removeHeaders(name, i + 1); return; } } // doesn't exist, so process as an add. addHeader(name, value); }
/** * Remove all header entries with the supplied name * * @param name * the header to remove */ public void removeHeader(String name) { // the first occurrance of a header is just zeroed out. int pos = findHeader(name); if (pos != -1) { InternetHeader oldHeader = (InternetHeader)headers.get(pos); // keep the header in the list, but with a null value oldHeader.setValue(null); // now remove all other headers with this name removeHeaders(name, pos + 1); } }