public Map<String, List<String>> getHeaderFields() {
Map<String, List<String>> ret = new HashMap<>();
for (Header hdr : resp.getAllHeaders()) {
- List<String> list = new LinkedList<>();
- for (HeaderElement hdrElem : hdr.getElements())
+ List<String> list = ret.get(hdr.getName());
+ if (list == null) {
+ list = new LinkedList<>();
+ ret.put(hdr.getName(), list);
+ }
+ for (HeaderElement hdrElem : hdr.getElements()) {
list.add(hdrElem.toString());
- ret.put(hdr.getName(), list);
+ }
}
return ret;
}
javax.servlet.http;version="[2.5.0,3.2.0)",
org.apache.commons.codec;version="[1.6.0,2.0.0)",
org.apache.commons.codec.binary;version="[1.6.0,2.0.0)",
+ org.apache.http;version="[4.3.0,5.0.0)",
+ org.apache.http.client;version="[4.3.0,5.0.0)",
+ org.apache.http.message;version="[4.3.0,5.0.0)",
org.eclipse.jetty.continuation;version="[9.4.5,10.0.0)",
org.eclipse.jetty.http;version="[9.4.5,10.0.0)",
org.eclipse.jetty.io;version="[9.4.5,10.0.0)",
--- /dev/null
+package org.eclipse.jgit.transport.http.apache;\r
+\r
+import org.apache.http.HttpEntity;\r
+import org.apache.http.HttpResponse;\r
+import org.apache.http.ProtocolVersion;\r
+import org.apache.http.StatusLine;\r
+import org.apache.http.message.AbstractHttpMessage;\r
+import org.junit.Test;\r
+\r
+import java.net.MalformedURLException;\r
+import java.util.List;\r
+import java.util.Locale;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertTrue;\r
+\r
+public class HttpClientConnectionTest {\r
+ @Test\r
+ public void testGetHeaderFieldsAllowMultipleValues() throws MalformedURLException {\r
+ HttpResponse responseMock = new HttpResponseMock();\r
+ String headerField = "WWW-Authenticate";\r
+ responseMock.addHeader(headerField, "Basic");\r
+ responseMock.addHeader(headerField, "Digest");\r
+ responseMock.addHeader(headerField, "NTLM");\r
+ HttpClientConnection connection = new HttpClientConnection("http://0.0.0.0/");\r
+ connection.resp = responseMock;\r
+ List<String> headerValues = connection.getHeaderFields().get(headerField);\r
+ assertEquals(3, headerValues.size());\r
+ assertTrue(headerValues.contains("Basic"));\r
+ assertTrue(headerValues.contains("Digest"));\r
+ assertTrue(headerValues.contains("NTLM"));\r
+ }\r
+\r
+ private class HttpResponseMock extends AbstractHttpMessage implements HttpResponse {\r
+ @Override\r
+ public StatusLine getStatusLine() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public void setStatusLine(StatusLine statusLine) {\r
+\r
+ }\r
+\r
+ @Override\r
+ public void setStatusLine(ProtocolVersion protocolVersion, int i) {\r
+\r
+ }\r
+\r
+ @Override\r
+ public void setStatusLine(ProtocolVersion protocolVersion, int i, String s) {\r
+\r
+ }\r
+\r
+ @Override\r
+ public void setStatusCode(int i) throws IllegalStateException {\r
+\r
+ }\r
+\r
+ @Override\r
+ public void setReasonPhrase(String s) throws IllegalStateException {\r
+\r
+ }\r
+\r
+ @Override\r
+ public HttpEntity getEntity() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public void setEntity(HttpEntity httpEntity) {\r
+\r
+ }\r
+\r
+ @Override\r
+ public Locale getLocale() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public void setLocale(Locale locale) {\r
+\r
+ }\r
+\r
+ @Override\r
+ public ProtocolVersion getProtocolVersion() {\r
+ return null;\r
+ }\r
+ }\r
+}\r