ok2c commented on code in PR #456: URL: https://github.com/apache/httpcomponents-client/pull/456#discussion_r1233386929
########## httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheValidityPolicy.java: ########## @@ -206,28 +207,60 @@ protected TimeValue getApparentAge(final HttpCacheEntry entry) { return TimeValue.ofSeconds(diff.getSeconds()); } + /** + * Extracts and processes the Age value from an HttpCacheEntry by tokenizing the Age header. + * Each token is checked, and direct arithmetic operations are performed to calculate the total age in delta-seconds. + * If a token cannot be parsed into a number or exceeds Integer.MAX_VALUE, the method sets the Age value to MAX_AGE (in seconds). + * This method makes use of CacheSupport.parseTokens to ensure robust handling of the Age header. + * + * @param entry The HttpCacheEntry from which to extract the Age value. + * @return The Age value in delta-seconds, or the MAX_AGE (in seconds) if the Age value is invalid or exceeds Integer.MAX_VALUE. + * @throws NumberFormatException if a token in the Age header cannot be parsed into a number. + */ protected long getAgeValue(final HttpCacheEntry entry) { - // This is a header value, we leave as-is - long ageValue = 0; - for (final Header hdr : entry.getHeaders(HttpHeaders.AGE)) { - long hdrAge; - try { - hdrAge = Long.parseLong(hdr.getValue()); - if (hdrAge < 0) { - hdrAge = MAX_AGE.toSeconds(); + final Header[] ages = entry.getHeaders(HttpHeaders.AGE); Review Comment: RFC 9111, 5.1 ``` Although it is defined as a singleton header field, a cache encountering a message with a list-based Age field value SHOULD use the first member of the field value, discarding subsequent ones. If the field value (after discarding additional members, as per above) is invalid (e.g., it contains something other than a non-negative integer), a cache SHOULD ignore the field. ``` @arturobernalg This looks wrong. We are supposed to take the first value, not the last one, aren't we? Get the first header and get the first token out of it. That is it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org For additional commands, e-mail: dev-h...@hc.apache.org