//are not present
if (headers.length == 0) {
headers = getResponseHeaderGroup().getHeaders("set-cookie");
}
CookieSpec parser = CookiePolicy.getSpecByPolicy(state.getCookiePolicy());
for (int i = 0; i < headers.length; i++) {
Header header = headers[i];
Cookie[] cookies = null;
try {
cookies = parser.parse(
conn.getHost(),
conn.getPort(),
getPath(),
conn.isSecure(),
header);
} catch (MalformedCookieException e) {
if (LOG.isWarnEnabled()) {
LOG.warn("Invalid cookie header: \""
+ header.getValue()
+ "\". " + e.getMessage());
}
}
if (cookies != null) {
for (int j = 0; j < cookies.length; j++) {
Cookie cookie = cookies[j];
try {
parser.validate(
conn.getHost(),
conn.getPort(),
getPath(),
conn.isSecure(),
cookie);
state.addCookie(cookie);
if (LOG.isDebugEnabled()) {
LOG.debug("Cookie accepted: \""
+ parser.formatCookie(cookie) + "\"");
}
} catch (MalformedCookieException e) {
if (LOG.isWarnEnabled()) {
LOG.warn("Cookie rejected: \"" + parser.formatCookie(cookie)
+ "\". " + e.getMessage());
}
}
}
}