Skip to content

Commit 6a2c9aa

Browse files
committed
Force cookies on same Cookie header
1 parent e20c1ae commit 6a2c9aa

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/org/apache/commons/httpclient/HttpMethodBase.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.apache.commons.httpclient.cookie.CookiePolicy;
4747
import org.apache.commons.httpclient.cookie.CookieSpec;
4848
import org.apache.commons.httpclient.cookie.CookieVersionSupport;
49+
import org.apache.commons.httpclient.cookie.IgnoreCookiesSpec;
4950
import org.apache.commons.httpclient.cookie.MalformedCookieException;
5051
import org.apache.commons.httpclient.params.HttpMethodParams;
5152
import org.apache.commons.httpclient.protocol.Protocol;
@@ -1347,17 +1348,8 @@ protected void addCookieRequestHeader(HttpState state, HttpConnection conn)
13471348
}
13481349
Cookie[] cookies = matcher.match(host, conn.getPort(),
13491350
getPath(), conn.isSecure(), state.getCookies());
1350-
if ((cookies != null) && (cookies.length > 0)) {
1351-
if (getParams().isParameterTrue(HttpMethodParams.SINGLE_COOKIE_HEADER)) {
1352-
// In strict mode put all cookies on the same header
1353-
putAllCookiesInASingleHeader(host, matcher, cookies);
1354-
} else {
1355-
// In non-strict mode put each cookie on a separate header
1356-
for (int i = 0; i < cookies.length; i++) {
1357-
String s = matcher.formatCookie(cookies[i]);
1358-
getRequestHeaderGroup().addHeader(new Header(HttpHeader.COOKIE, s, true));
1359-
}
1360-
}
1351+
if ((cookies != null && cookies.length > 0) || cookieheaders.length > 0) {
1352+
putAllCookiesInASingleHeader(host, matcher, cookies);
13611353
if (matcher instanceof CookieVersionSupport) {
13621354
CookieVersionSupport versupport = (CookieVersionSupport) matcher;
13631355
int ver = versupport.getVersion();
@@ -1407,6 +1399,10 @@ private void putAllCookiesInASingleHeader(String host, CookieSpec matcher,
14071399
mergedCookies.put(cookie.getName(),cookie);
14081400
}
14091401
cookies = mergedCookies.values().toArray(new Cookie[mergedCookies.size()]);
1402+
if (matcher instanceof IgnoreCookiesSpec) {
1403+
matcher = CookiePolicy.getCookieSpec(CookiePolicy.DEFAULT);
1404+
}
1405+
14101406
String s = matcher.formatCookies(cookies);
14111407
getRequestHeaderGroup()
14121408
.addHeader(new Header(HttpHeader.COOKIE, s, true));

0 commit comments

Comments
 (0)