This is an automated email from the ASF dual-hosted git repository.

jking pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new ce70ba2  THRIFT-4641: Check HTTP Status Code in TCurlClient
ce70ba2 is described below

commit ce70ba20c925e2b641798d791a3e6b9b2727c89c
Author: Josip Sokcevic <[email protected]>
AuthorDate: Thu Sep 20 11:35:22 2018 -0700

    THRIFT-4641: Check HTTP Status Code in TCurlClient
---
 lib/php/lib/Transport/TCurlClient.php | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/php/lib/Transport/TCurlClient.php 
b/lib/php/lib/Transport/TCurlClient.php
index f51fa88..2ca4f65 100644
--- a/lib/php/lib/Transport/TCurlClient.php
+++ b/lib/php/lib/Transport/TCurlClient.php
@@ -220,12 +220,18 @@ class TCurlClient extends TTransport
         curl_setopt(self::$curlHandle, CURLOPT_URL, $fullUrl);
         $this->response_ = curl_exec(self::$curlHandle);
 
-        // Connect failed?
-        if (!$this->response_) {
+        $code = curl_getinfo(self::$curlHandle, CURLINFO_HTTP_CODE);
+
+        // Handle non 200 status code / connect failure
+        if (!$this->response_ || $code !== 200) {
             curl_close(self::$curlHandle);
             self::$curlHandle = null;
+            $this->response_ = null;
             $error = 'TCurlClient: Could not connect to ' . $fullUrl;
-            throw new TTransportException($error, 
TTransportException::NOT_OPEN);
+            if ($code) {
+                $error .= ', HTTP status code: ' . $code;
+            }
+            throw new TTransportException($error, 
TTransportException::UNKNOWN);
         }
     }
 

Reply via email to