Skip to content
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

Http caching fixes #242

Merged
merged 14 commits into from
Jan 8, 2019
Merged

Http caching fixes #242

merged 14 commits into from
Jan 8, 2019

Conversation

johanjanssens
Copy link
Member

@johanjanssens johanjanssens commented Dec 31, 2018

  • The PR also moves etag based validation to the http response transport making it an integral part of the request/response cycle.

  • It fixes an issue with setting of headers and serialisation if the header values are set as an array. The code wasn't able to handle this properly.

- Move etag validation to http transport
- If etag validates automatically set the response status to not modified
- Calculate the etag based on the request and not the response content
@johanjanssens
Copy link
Member Author

@ercanozkaya Can you review my last changes too. Small issue in the header parsing. Instead of solving it in the http message in a generic way i'm solving it more locally.

Copy link
Member

@ercanozkaya ercanozkaya left a comment

Choose a reason for hiding this comment

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

@johanjanssens Left inline comments

$result = $cache_control['max-age'];
$values = explode(',', $this->_headers->get('Cache-Control', null));

foreach($values as $key => $value)
Copy link
Member

Choose a reason for hiding this comment

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

@johanjanssens should we refactor this code to a getCacheControl method?

$cache_control = (array) $this->_headers->get('Cache-Control', null, false);
if (isset($cache_control['max-age'])) {
$result = $cache_control['max-age'];
$values = explode(',', $this->_headers->get('Cache-Control', null));
Copy link
Member

Choose a reason for hiding this comment

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

@johanjanssens I'm confused about something. Cacheable behaviors sets the header value as an array. When we come here we parse it as a string. Should we support them both?

Copy link
Member

@ercanozkaya ercanozkaya left a comment

Choose a reason for hiding this comment

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

@johanjanssens Found an issue. details are inline

*/
public function getCacheControl()
{
$values = $this->_headers->get('Cache-Control', null);
Copy link
Member

Choose a reason for hiding this comment

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

@johanjanssens Testing using the following code, there is still an issue:

$response->headers->set('Cache-Control', ['private', 'no-cache', 'max-age' => 100]);

var_dump('actual', $response->headers->get('Cache-Control', null, false));
var_dump('parsed', $response->getCacheControl()); // PROBLEM: only returns 'private'
var_dump('max age', $response->getMaxAge()); // PROBLEM: returns 0 as above call does not return max-age

// The below code works as intended
$response->headers->set('Cache-Control', 'private, no-cache, max-age=100');

var_dump('actual', $response->headers->get('Cache-Control', null, false));
var_dump('parsed', $response->getCacheControl());
var_dump('max age', $response->getMaxAge());

This is happening because we are not passing the third parameter named $first in the above line. However when you pass it this time it breaks the string parsing :) Then the string is returned as an unparsed array

Copy link
Member Author

Choose a reason for hiding this comment

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

@ercanozkaya You are right, i have improved the code to handle this case too. Please review.

@johanjanssens
Copy link
Member Author

@ercanozkaya Can you re-review? I believe to have resolved the issues now, your test is validating on my end.

@johanjanssens johanjanssens merged commit 314e9b1 into master Jan 8, 2019
@johanjanssens johanjanssens deleted the feature/36-caching branch January 8, 2019 22:19
@johanjanssens
Copy link
Member Author

@ercanozkaya Would you mind merging these changed to Kodekit?

@ercanozkaya
Copy link
Member

ercanozkaya commented Jan 9, 2019 via email

ercanozkaya added a commit that referenced this pull request Jan 10, 2019
ercanozkaya added a commit that referenced this pull request Jan 10, 2019
ercanozkaya added a commit that referenced this pull request Jan 10, 2019
ercanozkaya added a commit that referenced this pull request Jan 10, 2019
ercanozkaya added a commit that referenced this pull request Jan 10, 2019
@ercanozkaya ercanozkaya modified the milestones: 3.2, v3.2.4 Feb 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants