Tomasz Kanafa created HTTPCLIENT-2411:
-----------------------------------------

             Summary: Invalid "Date" header generated by 
ResponseCacheConformance
                 Key: HTTPCLIENT-2411
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2411
             Project: HttpComponents HttpClient
          Issue Type: Bug
    Affects Versions: 5.5.2, 5.5.1, 5.6.1
            Reporter: Tomasz Kanafa


I think there is a bug in the httpclient5 handling missing {{Date}} header in 
the response when using cached client.
{code:java}
org.apache.hc.client5.http.impl.cache.ResponseCacheConformance#process
@Override
public void process(final HttpResponse response,
                        final EntityDetails entity,
                        final HttpContext context) throws HttpException, 
IOException {
    if (response.getCode() == HttpStatus.SC_NOT_MODIFIED) {
        for (final String headerName : DISALLOWED_ENTITY_HEADERS) {
            response.removeHeaders(headerName);
        }
    }
    if (!response.containsHeader(HttpHeaders.DATE)) {
        response.addHeader(new BasicHeader(HttpHeaders.DATE, Instant.now())); 
<--- toString on instant
    }
}

other place
org.apache.hc.client5.http.cache.HttpCacheEntryFactory#ensureDate
static void ensureDate(final HeaderGroup headers, final Instant instant) {
        if (!headers.containsHeader(HttpHeaders.DATE)) {
            headers.addHeader(new BasicHeader(HttpHeaders.DATE, 
DateUtils.formatStandardDate(instant)));   <--- formatted here
        }
    }

parsing the header 
org.apache.hc.client5.http.cache.HttpCacheEntry#getInstant(java.util.concurrent.atomic.AtomicReference<java.time.Instant>,
 java.lang.String)
uses 
org.apache.hc.client5.http.utils.DateUtils#parseStandardDate(org.apache.hc.core5.http.MessageHeaders,
 java.lang.String)
    /**
     * Standard date formatters: {@link #FORMATTER_RFC1123}, {@link 
#FORMATTER_RFC1036}, {@link #FORMATTER_ASCTIME}.
     *
     * @since 5.2
     */
    public static final DateTimeFormatter[] STANDARD_PATTERNS = new 
DateTimeFormatter[] {
            FORMATTER_RFC1123, - "EEE, dd MMM yyyy HH:mm:ss zzz"
            FORMATTER_RFC1036, - "EEE, dd-MMM-yy HH:mm:ss zzz"
            FORMATTER_ASCTIME - "EEE MMM d HH:mm:ss yyyy"
    }; {code}
the "Date" in invalid format causes problems in some specific situations eg. 
when using
{code:java}
org.apache.hc.client5.http.cache.HttpCacheEntry#getInstant() 
...
private Instant getInstant(final AtomicReference<Instant> ref, final String 
headerName) {
    Instant instant = ref.get();
    if (instant == null) {
        instant = DateUtils.parseStandardDate(this, headerName);
        if (instant == null) {
            instant = NON_VALUE;
        }
        if (!ref.compareAndSet(null, instant)) {
            instant = ref.get();
        }
    }
    return instant != null && instant != NON_VALUE ? instant : null;
}{code}
 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to