Repository navigation
Do not follow redirects after cache hit - #4289
Conversation
|
|
||
| #include "../ProxyClientTransaction.h" | ||
| #include "HttpSM.h" | ||
| #include "HttpTransact.h" |
There was a problem hiding this comment.
This include appeared to be missing earlier. Since we are adding a helper in this header, I am adding it here.
| // state_read_server_reponse_header and never get into this logic again. | ||
| if (enable_redirection && !t_state.redirect_info.redirect_in_process && is_redirect_required() && | ||
| (redirection_tries <= t_state.txn_conf->number_of_redirections)) { | ||
| if (enable_redirection && !t_state.redirect_info.redirect_in_process && is_redirect_required()) { |
There was a problem hiding this comment.
There is no need to check both is_redirect_required() and whether we have exceeded our retries limit. The former already does this.
| if (enable_redirection && !t_state.redirect_info.redirect_in_process && is_redirect_required()) { | ||
| do_redirect(); | ||
| } else if (redirection_tries > t_state.txn_conf->number_of_redirections) { | ||
| t_state.squid_codes.subcode = SQUID_SUBCODE_NUM_REDIRECTIONS_EXCEEDED; |
There was a problem hiding this comment.
Moved this to do_redirect(), since that method makes a decision based upon this test.
| HttpTransact::is_cache_hit(CacheLookupResult_t r) { | ||
| return (r == CACHE_LOOKUP_HIT_FRESH || r == CACHE_LOOKUP_HIT_WARNING || r == CACHE_LOOKUP_HIT_STALE); | ||
| } | ||
|
|
There was a problem hiding this comment.
I made a helper rather than duplicate the conditional expression yet again.
d769fa3 to
efdcbfe
Compare
| if (enable_redirection && redirection_tries > t_state.txn_conf->number_of_redirections) { | ||
| t_state.squid_codes.subcode = SQUID_SUBCODE_NUM_REDIRECTIONS_EXCEEDED; | ||
| } | ||
|
|
There was a problem hiding this comment.
I made a helper rather than duplicate the conditional expression yet again.
efdcbfe to
09f0270
Compare
| if (hooks_set) { | ||
| do_api_callout_internal(); | ||
| } else { | ||
| do_redirect(); |
There was a problem hiding this comment.
It looks good to me,
In the original code. we only invoke the hook after redirection . After this change, we will invoke the hook twice (3XX response and normal response ). So it does change the plugin behavior, doesn't it ? If so, I'd like to write a comment or document it .
There was a problem hiding this comment.
So it does change the plugin behavior, doesn't it ?
Changing plugin behavior in this way is not the intention of this patch. I think I should take a look and see if the change can be made without having this effect, if possible.
There was a problem hiding this comment.
@scw00 Because this case is a cache hit, we will not be following redirects. is_redirect_required() should return false, and so we should only call do_api_callout_internal() when hooks_set is true and otherwise we call handle_api_return().
So it should not be the case that we call hooks twice, but please point out if I missed something.
There was a problem hiding this comment.
I got it. Thanks for your explanation
|
@bryancall has brought up the point that we should at least confirm and document how stale cached 3xx redirect responses will be handled. We will look into this behavior, so leaving the WIP label on for now. |
It will not follow the redirect after the cached response expires but will instead freshen the cached response if possible and continue serving it. I will think about whether and how to express this in documentation. |
09f0270 to
906c6df
Compare
|
I have added a documentation note and squashed the branch. The old commit was 09f0270. |
| for a given client request. | ||
|
|
||
| .. note:: When :ts:cv:`proxy.config.http.number_of_redirections` is set to a positive value and |TS| has previously cached a 3XX Redirect response, the cached response will continue to be refreshed and returned until the response is no longer in the cache. | ||
|
|
|
@scw00 @bryancall |

See #4263
Following a redirect response that was a cache hit is not correct behavior, but it can happen in cases when a 3xx response was cached prior to a config change. If the cache key generated from a client request matches an object in the cache, then that object should be used for the client response.