Commit Graph

3678 Commits

Author SHA1 Message Date
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
Arturo Bernal 7bf84b71d4 Extend stale-if-error to apply to non-revalidatable cache entries.
The stale-if-error Cache-Control directive is used to indicate that a cached response can be used to satisfy a request even when an error occurs, as long as the response is still fresh or within the specified staleness limit. However, in the current implementation, this directive is only applied to cache entries that are revalidatable, meaning they have an ETag or Last-Modified header and can be refreshed with a conditional request.

This commit extends the stale-if-error directive to apply to any stale cache entry, whether revalidatable or not. This ensures that clients will continue to receive a cached response even if the original request resulted in an error, and helps to reduce the load on origin servers.
2023-12-13 11:54:38 +01:00
Arturo Bernal b915a3ab33 Improve HttpByteArrayCacheEntrySerializer class by adding new methods and enhancing performance.
This commit adds several new constant values to the HttpByteArrayCacheEntrySerializer class to manage cache entry headers. The HttpByteArrayCacheEntrySerializer class was also updated with a new constructor to set the buffer size and a new method to serialize HTTP cache storage entry objects. Additionally, the code was refactored to enhance performance and remove unnecessary variables.
2023-12-13 11:54:38 +01:00
Arturo Bernal f190e4f52e Avoid using deprecated DateUtils. 2023-12-13 11:54:38 +01:00
Arturo Bernal 4784fdfed4 Fix issue with duplicate parsing of Cache-Control header
Previously, the same Cache-Control header was being parsed twice, once by isExplicitlyNonCacheable and again by calculateFreshnessLifetime. The parsing code was extracted from calculateFreshnessLifetime and enhanced to include the main cache control directive that isExplicitlyNonCacheable could use to make its decision. This improves the efficiency and accuracy of the caching logic.
2023-12-13 11:54:38 +01:00
Arturo Bernal cfcdd11cb6 Allow certain responses from a POST to be cacheable.
Update ResponseCachingPolicy to allow caching of responses to POST requests under certain circumstances, as specified in RFC 2616 and explained in more detail in draft-ietf-httpbis-p2-semantics-20#section-2.3.4. This change extends the cacheability of responses beyond GET and HEAD methods, improving the cache's efficiency and reducing network traffic.
2023-12-13 11:54:38 +01:00
Arturo Bernal 019cf460ec Fix handling of cached responses with variants and different ETag values.
Previously, the getCacheEntry method was not correctly selecting the matching variant for a given request, which led to incorrect behavior when serving cached responses.
This commit improves the method's logic to correctly identify the cache entry using the request's cache key, and then select the variant with the matching ETag value. If no matching variant is found, the cache entry is considered stale and a new response is fetched from the origin server. The fix includes a new test case to ensure the correct behavior of the method in this scenario
2023-12-13 11:54:38 +01:00
Arturo Bernal d1f46e0c66 Fix Heuristic caching for URIs with query strings by adhering to RFC 2616 Section 13.9. The change is based on the fact that caches MUST NOT treat responses to such URIs as fresh unless the server provides an explicit expiration time. However, the updated RFC 7234 note indicates that it would be ok to introduce a configuration option that relaxed this rule. Therefore, a new configuration option is added to allow HTTP/1.1 responses with query strings to be cached. 2023-12-13 11:54:38 +01:00
Oleg Kalnichevski f7de67ff25 Upgraded project version to 5.4-alpha1 2023-12-13 11:54:30 +01:00
Arturo Bernal 7d853d521e Fix Response Body Truncation Issue in ContentResponseHandler (#521)
Resolved a bug where the response body was truncated to 256 bytes in all cases, including successful responses.
2023-12-11 12:19:48 +01:00
Oleg Kalnichevski 9e3d79bede Fixed NPE in debug log 2023-12-10 12:40:50 +01:00
Oleg Kalnichevski 6ad6b82883 Upgraded API compatibility level to 5.3 2023-12-06 21:18:25 +01:00
Arturo Bernal 5ab7f21dcb Refactor ExponentialBackoffManager and TestLinearBackoffManager Tests to Remove Thread.sleep(). (#495)
This commit enhances the ExponentialBackoffManager and TestLinearBackoffManager unit tests by replacing the use of Thread.sleep() with direct manipulation of internal state to simulate the cooldown period. This change improves test reliability and ensures consistent behavior in resource-constrained environments.
2023-12-06 20:36:57 +01:00
Arturo Bernal 5c69779f7d Fix features BackoffManager Unit Tests in Resource-Constrained Environments. (#494)
This commit improves the reliability of BackoffManager unit tests by replacing the use of Thread.sleep() with a more robust approach that manipulates lastRouteProbes to simulate the cooldown period. This enhancement ensures that the tests run successfully even in resource-constrained environments, making them more resilient and reliable.
2023-12-06 20:36:40 +01:00
Oleg Kalnichevski f6a37780cf Upgraded HttpClient version to 5.3.1-SNAPSHOT 2023-12-06 16:54:47 +01:00
Oleg Kalnichevski cf20ea3915 Updated release notes for HttpClient 5.3 release 2023-12-03 09:27:07 +01:00
Oleg Kalnichevski f7ac968aaf HTTPCLIENT-2310: Async Connect exec handler incorrectly pipes CONNECT requests through the main request protocol chain 2023-12-02 11:31:41 +01:00
Oleg Kalnichevski a46c9e5656 Added missing #disconnectEndpoint method to AsyncConnectExec 2023-11-30 13:33:04 +01:00
nfawcett 8a2b0f584a
Improve debug logging around connections that cannot be reused (#515) 2023-11-29 16:50:47 +01:00
Gary Gregory ed1c1d61f2 Use String#isEmpty() 2023-11-28 11:29:24 -05:00
Oleg Kalnichevski efe2598a30 Classic test suits to execute in plain and TLS modes 2023-11-28 11:08:38 +01:00
Oleg Kalnichevski 9ec63474c8 Upgraded HttpCore to version 5.2.4 2023-11-28 09:46:46 +01:00