3649 Commits

Author SHA1 Message Date
Oleg Kalnichevski
6055776245 Fixed invalid flow control in CacheControlHeaderParser 2023-12-13 11:54:46 +01:00
Oleg Kalnichevski
915b9b34d7 HTTPCLIENT-2293: Better name for the standard date pattern 2023-12-13 11:54:46 +01:00
Oleg Kalnichevski
4b7986370f HTTPCLIENT-2293: client protocol handlers to try to send Host as the first header in the request header section per RFC 9110 section 7.2 2023-12-13 11:54:45 +01:00
Oleg Kalnichevski
152ba4736f Renamed cache protocol conformance response interceptor (no functional changes) 2023-12-13 11:54:45 +01:00
Oleg Kalnichevski
77fdc11818 HTTPCLIENT-2293: Via header improvements
* optimized parting of Via response header values in order to generate less intermediate garbage
* optimized Via message header generation
* moved Via request header generation to a cache request interceptor
* moved Via response header generation to a cache response interceptor
2023-12-13 11:54:45 +01:00
Arturo Bernal
83e0339d27 HTTPCLIENT-2293 - Implement RFC-compliant TRACE request interceptor (#486)
- Add RequestTraceInterceptor class to handle HTTP TRACE requests in compliance with RFC 7231, Section 4.3.8.
  - Throw ProtocolException for sensitive headers like 'Authorization' and 'Cookie' in TRACE requests.
  - Throw ProtocolException if TRACE request contains a body.
2023-12-13 11:54:45 +01:00
Arturo Bernal
888232447b HTTPCLIENT-2293 - Implement 'If-Range' request validation as per RFC 9110 (#485)
- Ensure the presence of 'Range' header when 'If-Range' is specified.
- Enforce strong validator requirements when 'If-Range' is paired with a Date.
- Exit processing early if 'Last-Modified' header is missing, ensuring strong validation adherence.
2023-12-13 11:54:45 +01:00
Oleg Kalnichevski
1b0e9cf7b0 HTTPCLIENT-2277: deprecation of obsolete config parameters and removal of oudated or meaningless tests (#484)
* HTTPCLIENT-2277: Deprecated 303 response caching switch as no longer required by RFC 9111

* Javadoc improvements (no functional changes)

* HTTPCLIENT-2277: Revision of HTTP cache protocol requirement and recommendation test cases:
* Removed links to RFC 2616
* Removed verbatim quotes from RFC 2616
* Removed obsolete test cases and test cases without result verification / assertions
* Removed test cases unrelated to HTTP caching
* Removed test cases without test result assertions
2023-12-13 11:54:45 +01:00
Oleg Kalnichevski
c7d79190e6 HTTPCLIENT-2277: revised cache update handling
* improved and simplified internal cache API
* corrected cache update logic after a variant negotiation
* added more tests
2023-12-13 11:54:44 +01:00
Oleg Kalnichevski
02f09c03f4 HTTPCLIENT-2277, regression: corrected wrong variant entry keys in cache hits returned by BasicHttpCache#getVariants 2023-12-13 11:54:44 +01:00
Arturo Bernal
889a6bb085 HTTPCLIENT-2293 Enforce port specification for CONNECT requests as per RFC 9110 (#482)
- This adheres to RFC 9110, which states: "There is no default port; a client MUST send the port number even if the CONNECT request is based on a URI reference that contains an authority component with an elided port.
2023-12-13 11:54:44 +01:00
Oleg Kalnichevski
893574e092 HTTPCLIENT-2284: internal cache storage improvements (#478) 2023-12-13 11:54:44 +01:00
Arturo Bernal
8466b19861 Refactor HttpClient synchronized sections for virtual threads (#476)
- Replaced `synchronized` blocks with `ReentrantLock` in `LeaseRequest` to better support virtual threads introduced in JDK 21.
- Ensured each `LeaseRequest` instance has its own unique lock for maintaining original synchronization semantics.
- Addressed potential performance and deadlock issues with virtual threads by using explicit lock primitives from `java.util.concurrent.locks`.
2023-12-13 11:54:44 +01:00
Oleg Kalnichevski
097c17b78b HTTPCLIENT-2284: Cache entry representation improvements: (#477)
* request URI stored in cache is now normalized and is presently expected to be the same as the root key
* removed references to variant cache keys from the cache entry
* Variants in root entries are now represented as a set, not as a map
2023-12-13 11:54:44 +01:00
Oleg Kalnichevski
5fe89b4e32 Removed unused method argument 2023-12-13 11:54:43 +01:00
Oleg Kalnichevski
a8a66a1616 Fixed deprecation warnings 2023-12-13 11:54:43 +01:00
Oleg Kalnichevski
62d6db25e5 HTTPCLIENT-2277: Revision of the response protocol compliance checks: the caching layer should not attempt to enforce HTTP protocol compliance beyond what it required for correct operation of the caching functionality 2023-12-13 11:54:43 +01:00
Oleg Kalnichevski
0f7de55d41 HTTPCLIENT-2277: Removal of the HTTP protocol logic presently enforced in the caching layer directly related to the caching functionality. The enforcement of general protocol requirements should be implemented in the protocol layer. 2023-12-13 11:54:43 +01:00
Oleg Kalnichevski
a19adcb0dd HTTPCLIENT-2277: Removal of support for deprecated Pragma header 2023-12-13 11:54:43 +01:00
Oleg Kalnichevski
d1d6eec7dd HTTPCLIENT-2277: Removal of deprecated Warning header support 2023-12-13 11:54:43 +01:00
Arturo Bernal
561c949f78 Implement Cache-Control Extension in Response Caching Policy. (#462)
This commit adds the functionality to handle the 'immutable' directive in the Cache-Control header as per the RFC8246 specifications.

Key changes include:
- The 'immutable' directive is checked in the Cache-Control of an HTTP response, indicating that the origin server will not update the resource representation during the response's freshness lifetime.
- If the 'immutable' directive is present and the response is still fresh, the response is considered cacheable without further validation.
- Ignoring any arguments with the 'immutable' directive, as per RFC stipulations.
- Treating multiple instances of the 'immutable' directive as equivalent to one.
2023-12-13 11:54:42 +01:00
Oleg Kalnichevski
9bde706ae7 HTTPCLIENT-2277: Revision and simplification of the cache eviction logic; conformance to RFC 9111 section 4.4 2023-12-13 11:54:42 +01:00
Arturo Bernal
a1d9d19b5b HTTPCLIENT-2277: Implement must-understand directive according to RFC 9111 (#461)
This commit introduces changes to handle the 'must-understand' directive in accordance with the updated HTTP cache-related RFC 9111. The logic ensures that the cache only stores responses with status codes it understands when the 'must-understand' directive is present.

This implementation adheres to the following RFC guidance:

- A cache that understands and conforms to the requirements of a response's status code may cache it when the 'must-understand' directive is present.
- If the 'no-store' directive is present along with the 'must-understand' directive, the cache can ignore the 'no-store' directive if it understands the status code's caching requirements.
2023-12-13 11:54:42 +01:00
Oleg Kalnichevski
5fbef8fc7f HTTPCLIENT-2277: optimization of internal cache operations 2023-12-13 11:54:42 +01:00
Oleg Kalnichevski
e469cbb78d Better request method check (no functional changes) 2023-12-13 11:54:42 +01:00
Oleg Kalnichevski
abbfd8202a HTTPCLIENT-2277: Revision and optimization of cache key generation 2023-12-13 11:54:42 +01:00
Oleg Kalnichevski
0c79379827 Code optimization 2023-12-13 11:54:41 +01:00
Oleg Kalnichevski
48253e8027 Fixed a logical error that can cause a NPE 2023-12-13 11:54:41 +01:00
Oleg Kalnichevski
6f1fd6d26b HTTPCLIENT-2277, HTTPCLIENT-1347: Revision of the variant handling by the HTTP cache implementations
* Cache entries now can be of two distinct types: root entries containing a map of known representation variants of the same resource and resource entries containing a resource potentially sharable by multiple resource entries. The same entry cannot have a variant map and a resource at the same time
* Cache entry factory class added to the public APIs
2023-12-13 11:54:41 +01:00
Oleg Kalnichevski
1d9d6d70c9 Reverted changes to handling of cached responses with variants and different ETag values (f3f07a30); test code cleanups 2023-12-13 11:54:41 +01:00
Arturo Bernal
e26896596f HTTPCLIENT-2277: Improve Age Header Handling and Calculation in Accordance with RFC9111.
This commit enhances the processing and calculation of the "Age" response header field to comply fully with Sections 5.1 and 4.2.3 of RFC9111.
2023-12-13 11:54:41 +01:00
Oleg Kalnichevski
f8eb716c11 Corrected matchers for cache unit tests 2023-12-13 11:54:41 +01:00
Oleg Kalnichevski
6faef71798 Support methods for parsing a message header into a sequence of tokens 2023-12-13 11:54:41 +01:00
Arturo Bernal
5ba0701535 HTTPCLIENT-2277: Update Freshness Lifetime Calculation (RFC 9111 4.2.1)
This commit enhances the getFreshnessLifetime() method in the CacheValidityPolicy class to better comply with RFC 9111 4.2.1. The method now accounts for a negative Duration between the Date and Expires header fields.
2023-12-13 11:54:41 +01:00
Oleg Kalnichevski
65ec9a8e7a HTTPCLIENT-2277: do not store hop-by-hop and connection specific headers in cache (RFC 9111 3.1) 2023-12-13 11:54:40 +01:00
Oleg Kalnichevski
ec6b6630a2 Test code cleanup (no functional changes) 2023-12-13 11:54:40 +01:00
Oleg Kalnichevski
65ef10f9f6 HTTPCLIENT-2277: optimized response header merge upon SC_NOT_MODIFIED 2023-12-13 11:54:40 +01:00
Oleg Kalnichevski
d58320b4c2 HTTPCLIENT-2277: Redesign of the internal cache serialization format 2023-12-13 11:54:40 +01:00
Arturo Bernal
b7a39b3040 Enhancements to HTTP Conditional Request Handling:
1. Added support for HTTP 412 (Precondition Failed) status code. This status code is returned when one or more conditions given in the request header fields evaluated to false when tested on the server.
2. Ensured all instances of `If-Match` and `If-None-Match` headers are considered as required by the specification.
3. Added handling for cases where a weak ETag is used with a range request.
2023-12-13 11:54:40 +01:00
Oleg Kalnichevski
38b8398a20 Removed HttpCacheSupport from public API 2023-12-13 11:54:40 +01:00
Oleg Kalnichevski
fbed77880b Parse Cache-Control request and response headers only once 2023-12-13 11:54:40 +01:00
Oleg Kalnichevski
cd2930af1f * Caching protocol classes to use CacheControlHeaderParser to parse request and response cache control directives
* Several protocol recommendations related to Cache-Control header composition no longer mentioned by RFC 7234 have been removed
* Cleanup of header constants
2023-12-13 11:54:40 +01:00
Oleg Kalnichevski
3f81f21cab Request / response Cache-Control APIs 2023-12-13 11:54:39 +01:00
Arturo Bernal
f0d76de66d Add heuristic expiration warning to cached responses"
Implemented an enhancement to add a heuristic expiration warning to cached responses when the freshness lifetime and current age are both greater than one day. This warning, indicated by the '113' code, helps in identifying potential staleness in cached data and aligns with the HTTP caching specifications.
2023-12-13 11:54:39 +01:00
Arturo Bernal
46fe5a6a81 Refactor CacheControl parser to handle multiple headers.
This commit refactors the CacheControl parsing logic to handle multiple "Cache-Control" headers. The previous implementation treated each header independently, returning an array of CacheControl objects. This caused issues when headers had directives that should be combined into a single CacheControl object.
The updated implementation combines all directives from all headers into a single CacheControl object, ensuring accurate representation of the caching directives.
2023-12-13 11:54:39 +01:00
Arturo Bernal
cf7b582d6e Handle "no-cache" directive with specific header fields.
This commit enhances the handling of the "no-cache" directive when used with specified header fields. The changes include:

* Updated the caching module to correctly identify and handle "no-cache" directives with specific header fields. This was done by modifying the `responseContainsNoCacheDirective` method.
* Modified the `handleCacheHit` method to ensure that a cached entry is revalidated with the origin server when a "no-cache" directive with specific header fields is present in the response.
* Ensured that the rest of the response is still cacheable when the specified header fields are present, as long as the response complies with other caching requirements.
2023-12-13 11:54:39 +01:00
Arturo Bernal
0db4f4fa9e Handling for 304 Not Modified responses in CachingHttpAsyncClient and c. When a 304 response is received, the cache entry is updated and the updated entry is used to generate the response. 2023-12-13 11:54:39 +01:00
Arturo Bernal
5f6d370ccd HTTPCLIENT-1920: Add a check in CachedResponseSuitabilityChecker to ensure that cache entries created by HEAD requests are not used to serve GET requests. 2023-12-13 11:54:39 +01:00
Arturo Bernal
b9e2bbc778 Add Last-Modified header to 304 response when ETag is not present
.

This commit adds the Last-Modified header to the 304 Not Modified response when the ETag header is not present in the cache entry. This aligns the behavior with the recommendations in RFC 7232 and helps clients that rely on the Last-Modified header for cache updates when
2023-12-13 11:54:39 +01:00
Arturo Bernal
e1cfb2add6 Complete the implementation of stale-if-error support as per RFC 5861
- Updated handling of IOExceptions to serve stale responses when allowed by stale-if-error
2023-12-13 11:54:39 +01:00