-
Notifications
You must be signed in to change notification settings - Fork 61
avoid duplicate requests to the cache proxy. #126
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ | |
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0.x-dev" | ||
"dev-master": "1.1.x-dev" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,7 +130,26 @@ public function flush() | |
*/ | ||
protected function queueRequest($method, $url, array $headers = array()) | ||
{ | ||
$this->queue[] = $this->createRequest($method, $url, $headers); | ||
$signature = $this->getSignature($method, $url, $headers); | ||
if (!isset($this->queue[$signature])) { | ||
$this->queue[$signature] = $this->createRequest($method, $url, $headers); | ||
} | ||
} | ||
|
||
/** | ||
* Calculate a unique hash for the request, based on all significant information. | ||
* | ||
* @param string $method HTTP method | ||
* @param string $url URL | ||
* @param array $headers HTTP headers | ||
* | ||
* @return string A hash value for this request. | ||
*/ | ||
private function getSignature($method, $url, array $headers) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this means that if somebody overwrites queueRequest, he will either have to copy this method or not use a hash. should we make it protected? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the queue is private, so you have to call the parent method anyway if you overwrite it. |
||
{ | ||
ksort($headers); | ||
|
||
return md5($method . "\n" . $url . "\n" . var_export($headers, true)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now respecting the headers too. i opt to not play around with upper/lowercase as it complicates the code (and makes it slower) for no value unless people do really weird code, in which case they just get duplicate requests but no errors. |
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a new feature but no BC break (the behaviour changes, but not sending duplicate requests sounds like it should not break anything) - so i bump the minor version.