1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Abstraction over Http client implementations. |
5
|
|
|
* |
6
|
|
|
* @author Maksim Masiukevich <[email protected]> |
7
|
|
|
* @license MIT |
8
|
|
|
* @license https://opensource.org/licenses/MIT |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types = 0); |
12
|
|
|
|
13
|
|
|
namespace ServiceBus\HttpClient; |
14
|
|
|
|
15
|
|
|
use function ServiceBus\Common\uuid; |
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Http request options |
19
|
|
|
*/ |
20
|
|
|
final class RequestContext |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @psalm-readonly |
24
|
|
|
* |
25
|
|
|
* @var int |
26
|
|
|
*/ |
27
|
|
|
public $tcpConnectTimeout; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @psalm-readonly |
31
|
|
|
* |
32
|
|
|
* @var int |
33
|
|
|
*/ |
34
|
|
|
public $tlsHandshakeTimeout; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @psalm-readonly |
38
|
|
|
* |
39
|
|
|
* @var int |
40
|
|
|
*/ |
41
|
|
|
public $transferTimeout; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @psalm-readonly |
45
|
|
|
* |
46
|
|
|
* @var int |
47
|
|
|
*/ |
48
|
1 |
|
public $inactivityTimeout; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @psalm-readonly |
52
|
|
|
* |
53
|
|
|
* @var bool |
54
|
1 |
|
*/ |
55
|
1 |
|
public $logRequest; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @psalm-readonly |
59
|
|
|
* |
60
|
1 |
|
* @var bool |
61
|
1 |
|
*/ |
62
|
|
|
public $logResponse; |
63
|
|
|
|
64
|
|
|
/** |
65
|
4 |
|
* @psalm-readonly |
66
|
|
|
* |
67
|
|
|
* @var string |
68
|
|
|
*/ |
69
|
|
|
public $traceId; |
70
|
|
|
|
71
|
|
|
/** @var string|null */ |
72
|
|
|
public $protocolVersion; |
73
|
|
|
|
74
|
|
|
public static function withoutLogging( |
75
|
4 |
|
int $tcpConnectTimeout = 15000, |
76
|
4 |
|
int $tlsHandshakeTimeout = 15000, |
77
|
4 |
|
int $transferTimeout = 15000, |
78
|
4 |
|
int $inactivityTimeout = 15000 |
79
|
4 |
|
): self { |
80
|
4 |
|
return new self( |
81
|
4 |
|
traceId: null, |
82
|
4 |
|
tcpConnectTimeout: $tcpConnectTimeout, |
83
|
4 |
|
tlsHandshakeTimeout: $tlsHandshakeTimeout, |
84
|
|
|
transferTimeout: $transferTimeout, |
85
|
|
|
inactivityTimeout: $inactivityTimeout, |
86
|
|
|
logRequest: false, |
87
|
|
|
logResponse: false, |
88
|
|
|
protocolVersion: null |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function __construct( |
93
|
|
|
?string $traceId = null, |
94
|
|
|
int $tcpConnectTimeout = 15000, |
95
|
|
|
int $tlsHandshakeTimeout = 15000, |
96
|
|
|
int $transferTimeout = 15000, |
97
|
|
|
int $inactivityTimeout = 15000, |
98
|
|
|
bool $logRequest = true, |
99
|
|
|
bool $logResponse = true, |
100
|
|
|
?string $protocolVersion = null |
101
|
|
|
) { |
102
|
|
|
$this->traceId = $traceId ?? uuid(); |
|
|
|
|
103
|
|
|
$this->tcpConnectTimeout = $tcpConnectTimeout; |
104
|
|
|
$this->tlsHandshakeTimeout = $tlsHandshakeTimeout; |
105
|
|
|
$this->transferTimeout = $transferTimeout; |
106
|
|
|
$this->logRequest = $logRequest; |
107
|
|
|
$this->logResponse = $logResponse; |
108
|
|
|
$this->protocolVersion = $protocolVersion; |
109
|
|
|
$this->inactivityTimeout = $inactivityTimeout; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|