Skip to content

Commit

Permalink
Merge pull request #642 from stripe/ob-DX-3870
Browse files Browse the repository at this point in the history
Fix idempotency key check when using automatic retries
  • Loading branch information
ob-stripe authored Apr 26, 2019
2 parents 57d0bb7 + e99bbad commit f66e911
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/HttpClient/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function request($method, $absUrl, $headers, $params, $hasFile)
// It is only safe to retry network failures on POST requests if we
// add an Idempotency-Key header
if (($method == 'post') && (Stripe::$maxNetworkRetries > 0)) {
if (!isset($headers['Idempotency-Key'])) {
if (!$this->hasHeader($headers, "Idempotency-Key")) {
array_push($headers, 'Idempotency-Key: ' . $this->randomGenerator->uuid());
}
}
Expand Down Expand Up @@ -439,4 +439,22 @@ private function canSafelyUseHttp2()
$curlVersion = curl_version()['version'];
return (version_compare($curlVersion, '7.60.0') >= 0);
}

/**
* Checks if a list of headers contains a specific header name.
*
* @param string[] $headers
* @param string $name
* @return boolean
*/
private function hasHeader($headers, $name)
{
foreach ($headers as $header) {
if (strncasecmp($header, "{$name}: ", strlen($name) + 2) === 0) {
return true;
}
}

return false;
}
}

0 comments on commit f66e911

Please sign in to comment.