From 0beae7e8120d0752f0c689ddb2be4434656550cb Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Mon, 16 Nov 2020 10:36:00 -0800 Subject: [PATCH] Force IPv4 resolving --- lib/HttpClient/CurlClient.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/HttpClient/CurlClient.php b/lib/HttpClient/CurlClient.php index 1f9f0d5e2..ae78a6cd7 100644 --- a/lib/HttpClient/CurlClient.php +++ b/lib/HttpClient/CurlClient.php @@ -271,6 +271,10 @@ public function request($method, $absUrl, $headers, $params, $hasFile) $opts[\CURLOPT_HTTP_VERSION] = \CURL_HTTP_VERSION_2TLS; } + // Stripe's API servers are only accessible over IPv4. Force IPv4 resolving to avoid + // potential issues (cf. https://github.com/stripe/stripe-php/issues/1045). + $opts[\CURLOPT_IPRESOLVE] = \CURL_IPRESOLVE_V4; + list($rbody, $rcode, $rheaders) = $this->executeRequestWithRetries($opts, $absUrl); return [$rbody, $rcode, $rheaders]; @@ -283,7 +287,6 @@ public function request($method, $absUrl, $headers, $params, $hasFile) private function executeRequestWithRetries($opts, $absUrl) { $numRetries = 0; - $isPost = \array_key_exists(\CURLOPT_POST, $opts) && 1 === $opts[\CURLOPT_POST]; while (true) { $rcode = 0;