Skip to content

Make sure we vary on the Authorization header #558

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 8 commits into from
Apr 14, 2017

Conversation

Nyholm
Copy link
Collaborator

@Nyholm Nyholm commented Apr 2, 2017

This will fix #557

It is blocked by php-http/cache-plugin#35 and php-http/cache-plugin#36

@@ -181,6 +182,9 @@ public function addHeaderValue($header, $headerValue)
*/
public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
{
if (!isset($config['cache_key_generator'])) {
$config['cache_key_generator'] = new HeaderCacheKeyGenerator(['Authorization', 'Cookie', 'Accept']);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is there any more headers we should vary on?

Copy link
Contributor

Choose a reason for hiding this comment

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

The content type of the request perhaps?

Copy link
Collaborator

@acrobat acrobat Apr 5, 2017

Choose a reason for hiding this comment

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

I think this will be sufficient! Maybe @GrahamCampbell can test this pr to see if it fixes his problem from #557

EDIT: nvm I've missed his comment :p

@Nyholm Nyholm mentioned this pull request Apr 5, 2017
@@ -181,6 +182,9 @@ public function addHeaderValue($header, $headerValue)
*/
public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
{
if (!isset($config['cache_key_generator'])) {
$config['cache_key_generator'] = new HeaderCacheKeyGenerator(['Authorization', 'Cookie', 'Accept']);
Copy link
Contributor

Choose a reason for hiding this comment

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

The content type of the request perhaps?

@GrahamCampbell
Copy link
Contributor

I wonder if we could add an integration test to make sure that we don't reuse caches by mistake?

@Nyholm
Copy link
Collaborator Author

Nyholm commented Apr 8, 2017

I've added functional tests for this. Please review and/or test so I can merge and tag e new release

$this->assertEquals('nyholm', $userA['login']);

$userB = $github->currentUser()->show();
$this->assertEquals('nyholm', $userB['login'], 'Two request following each other should be cached.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Client should always send a request, and then see if we get a "not modified" response. We shouldn't just randomly cache for 600 seconds.

Copy link
Collaborator Author

@Nyholm Nyholm Apr 8, 2017

Choose a reason for hiding this comment

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

Client should always send a request, and then see if we get a "not modified" response

No, not always. If server says that it is okey to cache for X time, we do not need to send a request for that period.
But the logic you are referring to is in the php-http/cache-plugin.

We shouldn't just randomly cache for 600 seconds.

I set the default ttl to arbitrary number here to force the first the request to be cached (for a time longer then the tests run). Doing that I can easily verify if we make a second request or not. (Im using the MockClient, Im not actually making any HTTP calls. )

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.

SERIOUS BUG IN NEW VERSION
3 participants