DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7091>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7091 Header value/name swapped when more than one value is set for a header on a HttpResponse Summary: Header value/name swapped when more than one value is set for a header on a HttpResponse Product: Commons Version: 2.0 Alpha 1 Platform: PC OS/Version: Other Status: NEW Severity: Minor Priority: Other Component: HttpClient AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] the HeaderElement[] array taken from HttpMethod.getResponseHeader(String name) returns an array of HeaderElement objects which are name/value pairs. However, when more than one header is set in the response, those elements have a null value and the name is set with the value of the header. I don't know if this behaviour is by default or if it is a bug... Exemple : consider those 2 methods : private static String getHeader(HttpMethod method, String name) { Header header = method.getResponseHeader(name); if (null == header) { return null; } String value = header.getValue(); if (null == value) { return null; } return value; } private static String[] getHeaders(HttpMethod method, String name) Header header = method.getResponseHeader(name); if (null == header) { return null; } try { HeaderElement[] elements = header.getValues(); if (null == elements) { return null; } String[] values = new String[elements.length]; for (int i = 0; i < elements.length; i++ ) { values[i] = elements[i].getValue(); } return values; } catch (HttpException httpError) { //log something return null; } } The getHeader() method uses the only available HeaderElement value. This value is filled with the expected parameter. However, getHeaders() always return null as HeaderElement values. To obtain the actual header value, you need to change for (int i = 0; i < elements.length; i++ ) { values[i] = elements[i].getValue(); } by for (int i = 0; i < elements.length; i++ ) { values[i] = elements[i].getName(); } and utilize the header name as if it was the value... -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
