Skip to content

Commit

Permalink
Force cookies on same Cookie header
Browse files Browse the repository at this point in the history
  • Loading branch information
thc202 committed Jan 19, 2018
1 parent e20c1ae commit 6a2c9aa
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/org/apache/commons/httpclient/HttpMethodBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.cookie.CookieSpec;
import org.apache.commons.httpclient.cookie.CookieVersionSupport;
import org.apache.commons.httpclient.cookie.IgnoreCookiesSpec;
import org.apache.commons.httpclient.cookie.MalformedCookieException;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.protocol.Protocol;
Expand Down Expand Up @@ -1347,17 +1348,8 @@ protected void addCookieRequestHeader(HttpState state, HttpConnection conn)
}
Cookie[] cookies = matcher.match(host, conn.getPort(),
getPath(), conn.isSecure(), state.getCookies());
if ((cookies != null) && (cookies.length > 0)) {
if (getParams().isParameterTrue(HttpMethodParams.SINGLE_COOKIE_HEADER)) {
// In strict mode put all cookies on the same header
putAllCookiesInASingleHeader(host, matcher, cookies);
} else {
// In non-strict mode put each cookie on a separate header
for (int i = 0; i < cookies.length; i++) {
String s = matcher.formatCookie(cookies[i]);
getRequestHeaderGroup().addHeader(new Header(HttpHeader.COOKIE, s, true));
}
}
if ((cookies != null && cookies.length > 0) || cookieheaders.length > 0) {
putAllCookiesInASingleHeader(host, matcher, cookies);
if (matcher instanceof CookieVersionSupport) {
CookieVersionSupport versupport = (CookieVersionSupport) matcher;
int ver = versupport.getVersion();
Expand Down Expand Up @@ -1407,6 +1399,10 @@ private void putAllCookiesInASingleHeader(String host, CookieSpec matcher,
mergedCookies.put(cookie.getName(),cookie);
}
cookies = mergedCookies.values().toArray(new Cookie[mergedCookies.size()]);
if (matcher instanceof IgnoreCookiesSpec) {
matcher = CookiePolicy.getCookieSpec(CookiePolicy.DEFAULT);
}

String s = matcher.formatCookies(cookies);
getRequestHeaderGroup()
.addHeader(new Header(HttpHeader.COOKIE, s, true));
Expand Down

0 comments on commit 6a2c9aa

Please sign in to comment.