1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Qiniu\Http; |
4
|
|
|
|
5
|
|
|
use Qiniu\Http\Middleware\Middleware; |
6
|
|
|
|
7
|
|
|
final class RequestOptions |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @var int|null |
12
|
|
|
* http 请求的超时时间,单位:秒,默认:0,不超时 |
13
|
|
|
*/ |
14
|
|
|
public $connection_timeout; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var int|null |
18
|
|
|
* http 请求的超时时间,单位:毫秒,默认:0,不超时 |
19
|
|
|
*/ |
20
|
|
|
public $connection_timeout_ms; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var int|null |
24
|
|
|
* http 请求的超时时间,单位:秒,默认:0,不超时 |
25
|
|
|
*/ |
26
|
|
|
public $timeout; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var int|null |
31
|
|
|
* http 请求的超时时间,单位:毫秒,默认:0,不超时 |
32
|
|
|
*/ |
33
|
|
|
public $timeout_ms; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string|null |
37
|
|
|
* 代理URL,默认:空 |
38
|
|
|
*/ |
39
|
|
|
public $proxy; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var int|null |
43
|
|
|
* 代理鉴权方式,默认:空 |
44
|
|
|
*/ |
45
|
|
|
public $proxy_auth; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string|null |
49
|
|
|
* 代理鉴权参数,默认:空 |
50
|
|
|
*/ |
51
|
|
|
public $proxy_user_password; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var array<Middleware> |
55
|
|
|
*/ |
56
|
|
|
public $middlewares; |
57
|
|
|
|
58
|
|
|
public function __construct( |
59
|
|
|
$connection_timeout = null, |
60
|
|
|
$connection_timeout_ms = null, |
61
|
|
|
$timeout = null, |
62
|
|
|
$timeout_ms = null, |
63
|
|
|
$middlewares = array(), |
64
|
|
|
$proxy = null, |
65
|
|
|
$proxy_auth = null, |
66
|
|
|
$proxy_user_password = null |
67
|
|
|
) { |
68
|
|
|
$this->connection_timeout = $connection_timeout; |
69
|
|
|
$this->connection_timeout_ms = $connection_timeout_ms; |
70
|
|
|
$this->timeout = $timeout; |
71
|
|
|
$this->timeout_ms = $timeout_ms; |
72
|
|
|
$this->proxy = $proxy; |
73
|
|
|
$this->proxy_auth = $proxy_auth; |
74
|
|
|
$this->proxy_user_password = $proxy_user_password; |
75
|
|
|
$this->middlewares = $middlewares; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getCurlOpt() |
79
|
|
|
{ |
80
|
|
|
$result = array(); |
81
|
|
|
if ($this->connection_timeout != null) { |
|
|
|
|
82
|
|
|
$result[CURLOPT_CONNECTTIMEOUT] = $this->connection_timeout; |
83
|
|
|
} |
84
|
|
|
if ($this->connection_timeout_ms != null) { |
|
|
|
|
85
|
|
|
$result[CURLOPT_CONNECTTIMEOUT_MS] = $this->connection_timeout_ms; |
86
|
|
|
} |
87
|
|
|
if ($this->timeout != null) { |
|
|
|
|
88
|
|
|
$result[CURLOPT_TIMEOUT] = $this->timeout; |
89
|
|
|
} |
90
|
|
|
if ($this->timeout_ms != null) { |
|
|
|
|
91
|
|
|
$result[CURLOPT_TIMEOUT_MS] = $this->timeout_ms; |
92
|
|
|
} |
93
|
|
|
if ($this->proxy != null) { |
|
|
|
|
94
|
|
|
$result[CURLOPT_PROXY] = $this->proxy; |
95
|
|
|
} |
96
|
|
|
if ($this->proxy_auth != null) { |
|
|
|
|
97
|
|
|
$result[CURLOPT_PROXYAUTH] = $this->proxy_auth; |
98
|
|
|
} |
99
|
|
|
if ($this->proxy_user_password != null) { |
|
|
|
|
100
|
|
|
$result[CURLOPT_PROXYUSERPWD] = $this->proxy_user_password; |
101
|
|
|
} |
102
|
|
|
return $result; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|