Skip to content

Do not follow redirects after cache hit - #4289

Merged
SolidWallOfCode merged 1 commit into
apache:masterfrom
d2r:do-not-follow-cached-redirects
Oct 15, 2018
Merged

SolidWallOfCode merged 1 commit into
apache:masterfrom
d2r:do-not-follow-cached-redirects

Conversation

@d2r

@d2r d2r commented Sep 21, 2018

Copy link
Copy Markdown
Contributor

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.

Comment thread proxy/http/HttpSM.cc

#include "../ProxyClientTransaction.h"
#include "HttpSM.h"
#include "HttpTransact.h"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This include appeared to be missing earlier. Since we are adding a helper in this header, I am adding it here.

Comment thread proxy/http/HttpSM.cc
// 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()) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to check both is_redirect_required() and whether we have exceeded our retries limit. The former already does this.

Comment thread proxy/http/HttpSM.cc
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;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a helper rather than duplicate the conditional expression yet again.

@d2r
d2r force-pushed the do-not-follow-cached-redirects branch from d769fa3 to efdcbfe Compare September 21, 2018 21:51
Comment thread proxy/http/HttpSM.cc
if (enable_redirection && redirection_tries > t_state.txn_conf->number_of_redirections) {
t_state.squid_codes.subcode = SQUID_SUBCODE_NUM_REDIRECTIONS_EXCEEDED;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a helper rather than duplicate the conditional expression yet again.

@d2r
d2r force-pushed the do-not-follow-cached-redirects branch from efdcbfe to 09f0270 Compare September 21, 2018 21:54
@d2r d2r changed the title Do not follow redirects on after cache hit Do not follow redirects after cache hit Sep 21, 2018
Comment thread proxy/http/HttpSM.cc
if (hooks_set) {
do_api_callout_internal();
} else {
do_redirect();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 .

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it. Thanks for your explanation

@d2r d2r added the WIP label Sep 24, 2018
scw00
scw00 previously approved these changes Sep 25, 2018

@scw00 scw00 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@d2r

d2r commented Sep 25, 2018

Copy link
Copy Markdown
Contributor Author

@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.

@d2r

d2r commented Sep 25, 2018

Copy link
Copy Markdown
Contributor Author

how stale cached 3xx redirect responses will be handled

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.

@d2r
d2r force-pushed the do-not-follow-cached-redirects branch from 09f0270 to 906c6df Compare September 25, 2018 20:36
@d2r

d2r commented Sep 25, 2018

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

screen shot 2018-09-25 at 15 37 06

Rendering at 906c6df.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bryancall Does this look OK to you?

@d2r d2r removed the WIP label Sep 26, 2018
@d2r

d2r commented Oct 13, 2018

Copy link
Copy Markdown
Contributor Author

@scw00 @bryancall
I have updated the documentation and squashed commits. Review comments should be addressed.

@scw00 scw00 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants