diff --git a/src/main/java/com/ning/http/util/AsyncHttpProviderUtils.java b/src/main/java/com/ning/http/util/AsyncHttpProviderUtils.java index 0a6759c678..d313f5e724 100644 --- a/src/main/java/com/ning/http/util/AsyncHttpProviderUtils.java +++ b/src/main/java/com/ning/http/util/AsyncHttpProviderUtils.java @@ -460,7 +460,7 @@ public static Cookie parseCookie(String value) { // favor 'max-age' field over 'expires' if (!maxAgeSet && "max-age".equalsIgnoreCase(f[0])) { try { - maxAge = Integer.valueOf(removeQuote(f[1])); + maxAge = Math.max(Integer.valueOf(removeQuote(f[1])), 0); } catch (NumberFormatException e1) { // ignore failure to parse -> treat as session cookie // invalidate a previously parsed expires-field @@ -469,11 +469,11 @@ public static Cookie parseCookie(String value) { maxAgeSet = true; } else if (!maxAgeSet && !expiresSet && "expires".equalsIgnoreCase(f[0])) { try { - maxAge = convertExpireField(f[1]); + maxAge = Math.max(convertExpireField(f[1]), 0); } catch (Exception e) { // original behavior, is this correct at all (expires field with max-age semantics)? try { - maxAge = Integer.valueOf(f[1]); + maxAge = Math.max(Integer.valueOf(f[1]), 0); } catch (NumberFormatException e1) { // ignore failure to parse -> treat as session cookie } @@ -487,10 +487,6 @@ public static Cookie parseCookie(String value) { } } - if (maxAge < -1) { - maxAge = -1; - } - return new Cookie(domain, cookieName, cookieValue, path, maxAge, secure); }