Fix calculation of freshness lifetime in HttpResponse#419
Closed
arturobernalg wants to merge 4 commits intoapache:5.3.xfrom
Closed
Fix calculation of freshness lifetime in HttpResponse#419arturobernalg wants to merge 4 commits intoapache:5.3.xfrom
arturobernalg wants to merge 4 commits intoapache:5.3.xfrom
Conversation
80ee2d0 to
5f0f349
Compare
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.
5f0f349 to
7da5adb
Compare
Member
Author
|
closed in favor of #420 to 5.3.X branch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds a fix for the calculateFreshnessLifetime method in the HttpResponseCache class. The method calculates the freshness lifetime of a response based on the headers in the response and follows the algorithm for calculating the freshness lifetime described in RFC 7234, section 4.2.1.
The method takes into account the s-maxage, max-age, Expires, and Date headers as follows:
If the s-maxage directive is present in the Cache-Control header of the response, its value is used as the freshness lifetime for shared caches, which typically serve multiple users or clients.
If the max-age directive is present in the Cache-Control header of the response, its value is used as the freshness lifetime for private caches, which serve a single user or client.
If the Expires header is present in the response, its value is used as the expiration time of the response. The freshness lifetime is calculated as the difference between the expiration time and the time specified in the Date header of the response.
If none of the above headers are present or if the calculated freshness lifetime is invalid, a default value of 5 minutes is returned.
The existing implementation had a bug where it did not handle the case where the max-age directive was present in the Cache-Control header but the s-maxage directive was not. In this case, the method would incorrectly return the default freshness lifetime of 5 minutes instead of using the max-age value as the freshness lifetime. This pull request fixes the bug by adding a check for the s-maxage directive and returning the max-age value if the s-maxage directive is not present.
Motivation
The bug in the calculateFreshnessLifetime method could cause incorrect caching behavior, which could lead to degraded performance and unexpected results for clients. By fixing this bug, we ensure that the method correctly calculates the freshness lifetime of responses and that clients can rely on the cache to serve responses efficiently and accurately.
Changes Made
To fix the bug, we added a check for the s-maxage directive in the Cache-Control header and updated the return value of the method to use the max-age value if the s-maxage directive is not present.