if (HttpHeaders.CACHE.getOrdinal(name) == HttpHeaders.SET_COOKIE_ORDINAL)
{
String cname = null;
String cvalue = null;
QuotedStringTokenizer tok = new QuotedStringTokenizer(value.toString(),"=;",false,false);
tok.setSingle(false);
if (tok.hasMoreElements())
cname = tok.nextToken();
if (tok.hasMoreElements())
cvalue = tok.nextToken();
Cookie cookie = new Cookie(cname,cvalue);
while (tok.hasMoreTokens())
{
String token = tok.nextToken();
if ("Version".equalsIgnoreCase(token))
cookie.setVersion(Integer.parseInt(tok.nextToken()));
else if ("Comment".equalsIgnoreCase(token))
cookie.setComment(tok.nextToken());
else if ("Path".equalsIgnoreCase(token))
cookie.setPath(tok.nextToken());
else if ("Domain".equalsIgnoreCase(token))
cookie.setDomain(tok.nextToken());
else if ("Expires".equalsIgnoreCase(token))
{
try
{
Date date = new SimpleDateFormat("EEE, dd-MMM-yy HH:mm:ss 'GMT'").parse(tok.nextToken());
Long maxAge = TimeUnit.MILLISECONDS.toSeconds(date.getTime() - System.currentTimeMillis());
cookie.setMaxAge(maxAge > 0 ? maxAge.intValue() : 0);
}
catch (ParseException ignored)
{
}
}
else if ("Max-Age".equalsIgnoreCase(token))
{
try
{
int maxAge = Integer.parseInt(tok.nextToken());
cookie.setMaxAge(maxAge);
}
catch (NumberFormatException ignored)
{
}