[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-1515?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14026520#comment-14026520
 ] 

Jon Moore commented on HTTPCLIENT-1515:
---------------------------------------

@Tyrone: thanks for this contribution.

I do think adding the request method to the cache entry is a good long-term 
approach. The short-term issue is that this has some backwards-compatibility 
issues for HttpCacheStorage implementations that don't use the default 
serializer, which would not necessarily realize they need to also be storing 
(and loading) the method. There might also be issues after an upgrade even with 
the default serializer, especially with cache storage engines that might 
persist across application restarts.

I might suggest two possible approaches here, and would be interested in 
hearing others' opinions on these:

1. Go ahead and add this new field, but handle the repercussions. Specifically: 
add code that catches the resultant java.io.InvalidClassExceptions, deleting 
that cache entry, and then proceeding as with a cache miss. There's an open 
question about how to treat a null request method on a cache entry, as I think 
we can no longer assume that the method was GET. One possible solution would be 
to test the cache storage implementation at initialization time to see if it is 
retaining the request methods or not, and to disable caching HEAD requests if 
it doesn't.

2. Add a configuration option that converts HEAD requests into GETs to the 
origin; then serve HEAD requests from cache assuming cache entries were always 
the result of GETs. I'm not crazy about this, as although it is conceptually 
simpler, it removes the main benefit of issuing HEADs, which is to avoid 
downloading the bodies.

After writing this out, I'm kind of leaning towards #1, but would be interested 
in hearing from others (including Tyrone).

> Caching responses to HEAD requests
> ----------------------------------
>
>                 Key: HTTPCLIENT-1515
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1515
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>          Components: HttpCache
>            Reporter: Tyrone Cutajar
>
> Our system retrieves metadata via HEAD requests using HTTP Client 4.x and 
> would benefit immensely from having the headers in the response cached.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

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

Reply via email to