HttpClientConnection.getHeaderFields should support multiple values for same header
Bug: 537166 Change-Id: I1ba645968efe01a88f2484f030b7572228ba169c Signed-off-by: Gabriel Couto <gmcouto@gmail.com>
This commit is contained in:
parent
32798dcfdb
commit
280707b0fc
|
@ -51,6 +51,7 @@ java_library(
|
||||||
name = "httpcore",
|
name = "httpcore",
|
||||||
visibility = [
|
visibility = [
|
||||||
"//org.eclipse.jgit.http.apache:__pkg__",
|
"//org.eclipse.jgit.http.apache:__pkg__",
|
||||||
|
"//org.eclipse.jgit.http.test:__pkg__",
|
||||||
"//org.eclipse.jgit.lfs.server:__pkg__",
|
"//org.eclipse.jgit.lfs.server:__pkg__",
|
||||||
"//org.eclipse.jgit.lfs.server.test:__pkg__",
|
"//org.eclipse.jgit.lfs.server.test:__pkg__",
|
||||||
"//org.eclipse.jgit.pgm:__pkg__",
|
"//org.eclipse.jgit.pgm:__pkg__",
|
||||||
|
|
|
@ -272,10 +272,14 @@ private void execute() throws IOException, ClientProtocolException {
|
||||||
public Map<String, List<String>> getHeaderFields() {
|
public Map<String, List<String>> getHeaderFields() {
|
||||||
Map<String, List<String>> ret = new HashMap<>();
|
Map<String, List<String>> ret = new HashMap<>();
|
||||||
for (Header hdr : resp.getAllHeaders()) {
|
for (Header hdr : resp.getAllHeaders()) {
|
||||||
List<String> list = new LinkedList<>();
|
List<String> list = ret.get(hdr.getName());
|
||||||
for (HeaderElement hdrElem : hdr.getElements())
|
if (list == null) {
|
||||||
|
list = new LinkedList<>();
|
||||||
|
ret.put(hdr.getName(), list);
|
||||||
|
}
|
||||||
|
for (HeaderElement hdrElem : hdr.getElements()) {
|
||||||
list.add(hdrElem.toString());
|
list.add(hdrElem.toString());
|
||||||
ret.put(hdr.getName(), list);
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ junit_tests(
|
||||||
deps = [
|
deps = [
|
||||||
":helpers",
|
":helpers",
|
||||||
"//lib:commons-logging",
|
"//lib:commons-logging",
|
||||||
|
"//lib:httpcore",
|
||||||
"//lib:jetty-http",
|
"//lib:jetty-http",
|
||||||
"//lib:jetty-io",
|
"//lib:jetty-io",
|
||||||
"//lib:jetty-security",
|
"//lib:jetty-security",
|
||||||
|
|
|
@ -11,6 +11,9 @@ Import-Package: javax.servlet;version="[2.5.0,3.2.0)",
|
||||||
javax.servlet.http;version="[2.5.0,3.2.0)",
|
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;version="[1.6.0,2.0.0)",
|
||||||
org.apache.commons.codec.binary;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.continuation;version="[9.4.5,10.0.0)",
|
||||||
org.eclipse.jetty.http;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)",
|
org.eclipse.jetty.io;version="[9.4.5,10.0.0)",
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
package org.eclipse.jgit.transport.http.apache;
|
||||||
|
|
||||||
|
import org.apache.http.HttpEntity;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.ProtocolVersion;
|
||||||
|
import org.apache.http.StatusLine;
|
||||||
|
import org.apache.http.message.AbstractHttpMessage;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class HttpClientConnectionTest {
|
||||||
|
@Test
|
||||||
|
public void testGetHeaderFieldsAllowMultipleValues() throws MalformedURLException {
|
||||||
|
HttpResponse responseMock = new HttpResponseMock();
|
||||||
|
String headerField = "WWW-Authenticate";
|
||||||
|
responseMock.addHeader(headerField, "Basic");
|
||||||
|
responseMock.addHeader(headerField, "Digest");
|
||||||
|
responseMock.addHeader(headerField, "NTLM");
|
||||||
|
HttpClientConnection connection = new HttpClientConnection("http://0.0.0.0/");
|
||||||
|
connection.resp = responseMock;
|
||||||
|
List<String> headerValues = connection.getHeaderFields().get(headerField);
|
||||||
|
assertEquals(3, headerValues.size());
|
||||||
|
assertTrue(headerValues.contains("Basic"));
|
||||||
|
assertTrue(headerValues.contains("Digest"));
|
||||||
|
assertTrue(headerValues.contains("NTLM"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private class HttpResponseMock extends AbstractHttpMessage implements HttpResponse {
|
||||||
|
@Override
|
||||||
|
public StatusLine getStatusLine() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStatusLine(StatusLine statusLine) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStatusLine(ProtocolVersion protocolVersion, int i) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStatusLine(ProtocolVersion protocolVersion, int i, String s) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStatusCode(int i) throws IllegalStateException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setReasonPhrase(String s) throws IllegalStateException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HttpEntity getEntity() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEntity(HttpEntity httpEntity) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Locale getLocale() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLocale(Locale locale) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProtocolVersion getProtocolVersion() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue