Commit 37cf5025 authored by tufengqi's avatar tufengqi

curl common

parent 3cee9214
......@@ -32,13 +32,14 @@ class CurlHttpClient
*
* @var array
*/
protected $headers;
protected $headers = [];
protected $uri_no_func;
protected $connect_timeout_ms;
protected $timeout_ms;
protected $method;
protected $curl_handle;
protected $response;
protected $cookies = [];
const METHOD_POST = 'POST';
const METHOD_GET = 'GET';
......@@ -74,16 +75,16 @@ class CurlHttpClient
$scheme = 'https' === $arr[0] ? 'https' : 'http';
$this->scheme = $scheme;
$this->full_url = $url . '?' . http_build_query($get_arr);
if ($options['time']['connect_timeout_ms']) {
if (!empty($options['time']['connect_timeout_ms'])) {
$this->connect_timeout_ms = $options['time']['connect_timeout'];
}
if ($options['time']['timeout_ms']) {
if (!empty($options['time']['timeout_ms'])) {
$this->timeout_ms = $options['time']['timeout_ms'];
}
if ($options['headers']) {
if (!empty($options['headers'])) {
$this->headers = $options['headers'];
}
if ($options['cookies']) {
if (!empty($options['cookies'])) {
$this->cookies = $options['cookies'];
}
$this->method = self::METHOD_GET;
......@@ -98,16 +99,16 @@ class CurlHttpClient
$this->scheme = $scheme;
$this->full_url = $url;
$this->post_arr = $post_arr;
if ($options['time']['connect_timeout_ms']) {
if (!empty($options['time']['connect_timeout_ms'])) {
$this->connect_timeout_ms = $options['time']['connect_timeout'];
}
if ($options['time']['timeout_ms']) {
if (!empty($options['time']['timeout_ms'])) {
$this->timeout_ms = $options['time']['timeout_ms'];
}
if ($options['headers']) {
if (!empty($options['headers'])) {
$this->headers = $options['headers'];
}
if ($options['cookies']) {
if (!empty($options['cookies'])) {
$this->cookies = $options['cookies'];
}
$this->method = self::METHOD_POST;
......@@ -142,7 +143,7 @@ class CurlHttpClient
$cookie_set = true;
}
if (true === $cookie_set) {
foreach ($cookies as $key => $value) {
foreach ($this->cookies as $key => $value) {
$cookie_string .= $key . '=' . $value . ';';
}
curl_setopt($this->curl_handle, CURLOPT_COOKIE, $cookie_string);
......
......@@ -33,13 +33,14 @@ class SwoftHttpClient
*
* @var array
*/
protected $headers;
protected $headers = [];
protected $uri_no_func;
protected $connect_timeout_ms;
protected $timeout_ms;
protected $method;
protected $curl_handle;
protected $response;
protected $cookies = [];
const METHOD_POST = 'POST';
const METHOD_GET = 'GET';
......@@ -75,16 +76,16 @@ class SwoftHttpClient
$scheme = 'https' === $arr[0] ? 'https' : 'http';
$this->scheme = $scheme;
$this->full_url = $url . '?' . http_build_query($get_arr);
if ($options['time']['connect_timeout_ms']) {
if (!empty($options['time']['connect_timeout_ms'])) {
$this->connect_timeout_ms = $options['time']['connect_timeout'];
}
if ($options['time']['timeout_ms']) {
if (!empty($options['time']['timeout_ms'])) {
$this->timeout_ms = $options['time']['timeout_ms'];
}
if ($options['headers']) {
if (!empty($options['headers'])) {
$this->headers = $options['headers'];
}
if ($options['cookies']) {
if (!empty($options['cookies'])) {
$this->cookies = $options['cookies'];
}
$this->method = self::METHOD_GET;
......@@ -99,16 +100,16 @@ class SwoftHttpClient
$this->scheme = $scheme;
$this->full_url = $url;
$this->post_arr = $post_arr;
if ($options['time']['connect_timeout_ms']) {
if (!empty($options['time']['connect_timeout_ms'])) {
$this->connect_timeout_ms = $options['time']['connect_timeout'];
}
if ($options['time']['timeout_ms']) {
if (!empty($options['time']['timeout_ms'])) {
$this->timeout_ms = $options['time']['timeout_ms'];
}
if ($options['headers']) {
if (!empty($options['headers'])) {
$this->headers = $options['headers'];
}
if ($options['cookies']) {
if (!empty($options['cookies'])) {
$this->cookies = $options['cookies'];
}
$this->method = self::METHOD_POST;
......
......@@ -234,6 +234,7 @@ class TCurlClient extends \Thrift\Transport\TTransport
$this->request_ = '';
curl_setopt(self::$curlHandle, CURLOPT_URL, $fullUrl);
$this->response_ = curl_exec(self::$curlHandle);
// echo $this->response_ ;exit;
// Connect failed?
if (!$this->response_) {
curl_close(self::$curlHandle);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment