Commit 3ed4cb42 authored by tufengqi's avatar tufengqi

并发http修复

parent 009f70fa
......@@ -2,7 +2,7 @@
namespace fpf\http;
use fpf\http\exception\SwoftHttpException;
use fpf\http\exception\SwooleHttpException;
use Swoole\Coroutine\Http\Client;
class SwooleHttpClient
......@@ -24,9 +24,9 @@ class SwooleHttpClient
/**
* Buffer for the HTTP request data
*
* @var string
* @var array
*/
protected $post_fields;
protected $post_arr;
/**
* http headers
......@@ -125,7 +125,13 @@ class SwooleHttpClient
register_shutdown_function([$this, 'closeCurlHandle']);
$full_url = $this->full_url;
$parts = parse_url($full_url);
$this->curl_handle = new Client($parts['host'], ($parts['port'] ?? 80), 'http' === $parts['scheme'] ? false : true);
$scheme = 'http' === $parts['scheme'] ? false : true;
$parts['port'] = $parts['port'] ?? '';
if (true === $scheme && !$parts['port']) {
$parts['port'] = 443;
}
$parts['port'] = intval($parts['port'] ?? 80);
$this->curl_handle = new Client($parts['host'], $parts['port'], $scheme);
$full_url = $this->full_url;
$headers = [];
foreach ($this->headers as $key => $value) {
......@@ -135,10 +141,10 @@ class SwooleHttpClient
$options['headers'][VERSION_KEY] = VERSION_VALUE_NO_PTEFIX;
}
if (self::METHOD_POST === $this->method) {
$options['body'] = $this->request_;
$options['body'] = $this->post_arr;
}
$options['timeout'] = $this->timeout_ms / 1000;
$this->post_fields = '';
$options['headers'] = $options['headers'] ?? [];
$this->curl_handle->setHeaders($options['headers']);
$this->curl_handle->set(['timeout' => $options['timeout']]);
if (self::METHOD_POST === $this->method) {
......
......@@ -219,7 +219,13 @@ class SwooleHttpClient extends \Thrift\Transport\TTransport
$this->request_ = '';
$full_url = $this->scheme_ . "://" . $host . $this->uri_;
$parts = parse_url($full_url);
$this->handle = new Client($parts['host'], ($parts['port'] ?? 80), 'http' === $parts['scheme'] ? false : true);
$parts['port'] = $parts['port'] ?? '';
$scheme = 'http' === $parts['scheme'] ? false : true;
if (true === $scheme && !$parts['port']) {
$parts['port'] = 443;
}
$parts['port'] = intval($parts['port'] ?? 80);
$this->handle = new Client($parts['host'], $parts['port'], $scheme);
$this->handle->setHeaders($options['headers']);
$this->handle->set(['timeout' => $options['timeout']]);
$this->handle->post($this->uri_, $options['body']);
......
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