Skip to content

Dont respect cache headers when $this->respectCacheHeaders=false #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2015

Conversation

Nyholm
Copy link
Member

@Nyholm Nyholm commented Dec 18, 2015

No description provided.

@@ -89,7 +89,9 @@ protected function isCacheable(ResponseInterface $response)
if (!in_array($response->getStatusCode(), [200, 203, 300, 301, 302, 404, 410])) {
return false;
}
if ($this->getCacheControlDirective($response, 'no-store') || $this->getCacheControlDirective($response, 'private')) {
if ($this->respectCacheHeaders &&
Copy link
Member

Choose a reason for hiding this comment

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

I think that this check could be in one return statement.

@Nyholm
Copy link
Member Author

Nyholm commented Dec 18, 2015

I've updated the PR according to your comments

@sagikazarmark
Copy link
Member

Actually I meant the first condition as well. 😄

You could set some helper variables (like the status code list).

@sagikazarmark
Copy link
Member

($this->getCacheControlDirective($response, 'no-store') || $this->getCacheControlDirective($response, 'private'))

This could go into a separate method, like checkCacheControlCacheble or checkCacheControlAllowsCache or something like that.

@Nyholm
Copy link
Member Author

Nyholm commented Dec 18, 2015

ah. Okey. =)

I'll update again and make sure it is readable.

@Nyholm
Copy link
Member Author

Nyholm commented Dec 18, 2015

hm, okey. I put it in a variable now since it not reused.


return true;
// If http status code is cachable and if we respect the headers, make sure there is no private cache headers.
return in_array($response->getStatusCode(), $cachableCodes) && (!$this->respectCacheHeaders || !$privateHeaders);
Copy link
Member

Choose a reason for hiding this comment

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

Hm...

Isn't it the same as !($this->respectCacheHeaders && $privateHeaders)

Copy link
Member Author

Choose a reason for hiding this comment

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

It is the same according to De Morgan's law. You are correct.

Copy link
Member

Choose a reason for hiding this comment

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

De Morgan's law

I knew that there is a name for this, but I couldn't recall.

@sagikazarmark
Copy link
Member

Thanks @Nyholm

sagikazarmark added a commit that referenced this pull request Dec 18, 2015
Dont respect cache headers when $this->respectCacheHeaders=false
@sagikazarmark sagikazarmark merged commit 01ea431 into php-http:master Dec 18, 2015
@Nyholm Nyholm deleted the patch-1 branch December 18, 2015 22:48
@Nyholm
Copy link
Member Author

Nyholm commented Dec 18, 2015

Thank you for merging.


return true;
// If http status code is cachable and if we respect the headers, make sure there is no private cache headers.
return in_array($response->getStatusCode(), $cachableCodes) && !($this->respectCacheHeaders && $privateHeaders);
Copy link
Contributor

Choose a reason for hiding this comment

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

i think the previous code with early returns was more readable. i will do another small PR :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

see #22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants