Commit Graph

300 Commits

Author SHA1 Message Date
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
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
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
Oleg Kalnichevski f6a37780cf Upgraded HttpClient version to 5.3.1-SNAPSHOT 2023-12-06 16:54:47 +01:00
Oleg Kalnichevski 19ab1111c7 More consistent handling of OperationTimeoutException in MemcachedHttpCacheStorage 2023-09-29 15:24:37 +02:00
Oleg Kalnichevski 9d23ddbea7 Upgraded HttpClient version to 5.3-alpha2-SNAPSHOT 2023-08-19 18:39:58 +02:00
Oleg Kalnichevski 83c6079e65 NTLM scheme deprecated and disabled by default 2023-08-12 17:14:53 +02:00
Oleg Kalnichevski c0194331c3 Upgraded project version to 5.3-alpha1-SNAPSHOT 2023-08-12 17:14:16 +02:00
Gary Gregory 09ae5f212a Mostly missing Javadoc in org.apache.hc.client5.http.entity and minor
clean ups
2023-07-02 16:31:07 -04:00
Oleg Kalnichevski 3e38a5e5ec HTTPCLIENT-2271: Do not optimize the path component of the resolved URI by default. 2023-04-27 17:13:53 +02:00
Michael Lee ec5b1f1d60 Hygiene - remove unused private fields 2023-03-13 15:43:31 +01:00
MartinWitt f198fc0e62 Make inner classes static (#405) 2023-03-13 15:43:24 +01:00
Oleg Kalnichevski 22e5a0be6b Upgraded HttpClient version to 5.2.2-SNAPSHOT 2022-12-07 14:09:11 +01:00
Gary Gregory 290ec22022 Fix compiler warnings in tests
Use try-with-resources, also avoids possible leaks on test failures
2022-11-14 22:13:14 +01:00
Gary Gregory 230a2caf67 Replace deprecated use of LangUtils#equals() with Objects.equals() 2022-11-14 09:57:05 -05:00
Oleg Kalnichevski e52ff02f74 Upgraded HttpClient version to 5.2.1-SNAPSHOT 2022-11-13 12:28:46 +01:00
Gary Gregory dca9108352 Use try-with-resources 2022-07-06 10:56:04 -04:00
Gary Gregory 1cd12fc1dc Cleaning up:
- Super interface already implements FutureCallback
- No need to override methods to only call super
- Add missing Javadoc tag
- Access static field directly
2022-07-06 10:13:23 -04:00
jkmcl 15951d8094 Use HTTP header name constants
Use HTTP header name constants instead of string literals.
2022-06-20 19:25:00 +02:00
Oleg Kalnichevski 8dbaf131f5 Upgraded HttpClient version to 5.2-beta2-SNAPSHOT 2022-06-07 14:42:03 +02:00
j3graham 26dcc6f914 HTTPCLIENT-2218: Use Java 8 Base64 utility (#370) 2022-06-01 23:04:29 +02:00
Oleg Kalnichevski b9a6b5ed89 HTTPCLIENT-2202: MemcachedHttpCacheStorage to support MemcachedClientIF interface 2022-02-10 20:33:59 +01:00
Arturo Bernal 4c464b2432 Avoid redundant validation of '\"'. Its check it before. 2021-12-12 20:50:25 +01:00
Arturo Bernal c091c05b72 Expose method to check the cache is still active. 2021-12-11 12:08:17 +01:00
Arturo Bernal d323e0d684 HTTPCLIENT-2189 - Cookie and Cache APIs to use Java time primitives 2021-11-29 14:21:01 +01:00
Arturo Bernal 0a42d173ef HTTPCLIENT-2186 - Migrate Test to Unit 5. 2021-11-21 19:44:13 +01:00
Arturo Bernal 4d0caa4f42 Fix typo method and class. Deprecate the old ones. 2021-11-12 22:16:52 +01:00
Oleg Kalnichevski 3dd37952bc Use Java 8 Time APIs for date / time operations in the HTTP cache tests 2021-11-09 22:50:00 +01:00
Oleg Kalnichevski 1eb2d40df1 Upgraded HttpClient version to 5.2-alpha2-SNAPSHOT 2021-11-01 18:04:02 +01:00
Oleg Kalnichevski dfc2086d24 Replaced SimpleDateFormat and Calendar with Java 8 Time APIs; removed thread-local from DateUtils 2021-10-24 16:50:07 +02:00
Arturo Bernal 277c7228c3 Change loop that don't loop for "if" conditions. 2021-10-23 18:10:15 +02:00
Gary Gregory b6ae693fe5 Don't initialize AtomicReference to its default value. 2021-10-13 10:36:49 +02:00
Oleg Kalnichevski 5390aef223 Always bind the exchange ID to the execution context 2021-09-29 18:01:46 +02:00
Oleg Kalnichevski aff1d2024c Better exception asserts in unit tests 2021-06-19 21:10:43 +02:00
Oleg Kalnichevski 760795b6df HTTPCLIENT-1244: Replaced EasyMock with Mockito in the HTTP cache unit tests 2021-06-19 16:49:12 +02:00
Arturo Bernal d77112f608 Replace assert calls by simpler but equivalent calls. 2021-06-19 16:47:44 +02:00
Arturo Bernal fde3fca687 Simplify conditions and avoid extra checks.
Inline return variables.
2021-06-19 16:47:41 +02:00
Oleg Kalnichevski 0805cfe582 Updated test cases with exception asserts 2021-05-24 18:53:58 +02:00
Oleg Kalnichevski 82432f50d9 Removed references to deprecated Assert#assertThat 2021-05-24 16:58:33 +02:00
Oleg Kalnichevski 8580d7fddf Redundant type declarations 2021-05-24 14:43:18 +02:00
Oleg Kalnichevski 646257e107 Upgraded project version to 5.2-alpha1-SNAPSHOT 2021-05-24 11:30:08 +02:00
Oleg Kalnichevski bb04d078ad Java 1.8 upgrade 2021-05-11 21:34:49 +02:00
Oleg Kalnichevski 6693c186f4 Upgraded HttpClient version to 5.1.1-SNAPSHOT 2021-05-11 21:03:27 +02:00
Oleg Kalnichevski b151df7e8c HTTPCLIENT-2157: response object generated by the classic caching backend is missing the original content encoding 2021-05-01 17:27:12 +02:00
Oleg Kalnichevski 13137eb6c7 Async clients to support scheduled (delayed) re-execution of requests 2021-04-27 12:57:15 +02:00
Arturo Bernal e0c049060b Fix javadoc 2021-03-28 12:36:14 +02:00
Arturo Bernal 879a063b57 Reuse org.apache.hc.core5.http.Method HTTP spec enum 2021-03-16 12:53:31 +01:00
Arturo Bernal 118e7359a1 Fixed typos javadocs and var names 2021-03-14 16:34:18 +01:00
Oleg Kalnichevski 3de88293fe Deprecated message copiers in favor of generic message builders 2021-03-11 22:47:29 +01:00
Arturo Bernal f2e9ad3b11 Fix Typo 2021-02-10 22:09:20 +01:00
Oleg Kalnichevski 744c9d8020 Upgraded HttpClient version to 5.1-beta2-SNAPSHOT 2021-02-10 22:06:51 +01:00
Oleg Kalnichevski f9ea1b6238 Upgraded project version to 5.1-beta1-SNAPSHOT 2021-02-06 13:28:08 +01:00
Arturo Bernal 0940d35602 Minor Improvement:
* Avoid duplicate code
* Simplify if else
* Inline variables
2021-02-05 22:18:45 +01:00