FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sentry-php/src/HttpClient/HttpClient.php at sensitive-data-scrubber · getsentry/sentry-php · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
getsentry
/
sentry-php
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
474
Star
1.9k
Code
Issues
20
Pull requests
10
Discussions
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
sentry-php
/
src
/
HttpClient
/
HttpClient.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
188 lines (158 loc) · 6.62 KB
Breadcrumbs
sentry-php
/
src
/
HttpClient
/
HttpClient.php
Copy path
File metadata and controls
188 lines (158 loc) · 6.62 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
declare
(strict_types=
1
);
namespace
Sentry
\
HttpClient
;
use
Sentry
\
Options
;
use
Sentry
\
Util
\
Http
;
/**
* @internal
*/
class
HttpClient
implements
HttpClientInterface
{
/**
* @var string The Sentry SDK identifier
*/
protected
$
sdkIdentifier
;
/**
* @var string The Sentry SDK identifier
*/
protected
$
sdkVersion
;
/**
* Either a persistent share handle or a regular share handle, or null if no share handle can be obtained.
*
* @var object|resource|null
*/
private
$
shareHandle
;
public
function
__construct
(
string
$
sdkIdentifier
,
string
$
sdkVersion
)
{
$
this
->
sdkIdentifier
=
$
sdkIdentifier
;
$
this
->
sdkVersion
=
$
sdkVersion
;
}
public
function
sendRequest
(
Request
$
request
,
Options
$
options
):
Response
{
$
dsn
=
$
options
->
getDsn
();
if
(
$
dsn
===
null
) {
throw
new
\
RuntimeException
(
'
The DSN option must be set to use the HttpClient.
'
);
}
$
requestData
=
$
request
->
getStringBody
();
if
(
$
requestData
===
null
) {
throw
new
\
RuntimeException
(
'
The request data is empty.
'
);
}
if
(!
\extension_loaded
(
'
curl
'
)) {
throw
new
\
RuntimeException
(
'
The cURL PHP extension must be enabled to use the HttpClient.
'
);
}
$
curlHandle
=
curl_init
();
$
requestHeaders
= Http::
getRequestHeaders
(
$
dsn
,
$
this
->
sdkIdentifier
,
$
this
->
sdkVersion
);
if
(
\extension_loaded
(
'
zlib
'
)
&&
$
options
->
isHttpCompressionEnabled
()
) {
$
requestData
=
gzcompress
(
$
requestData
, -
1
, \
ZLIB_ENCODING_GZIP
);
$
requestHeaders
[] =
'
Content-Encoding: gzip
'
;
}
$
responseHeaders
= [];
$
responseHeaderCallback
=
static
function
(
$
curlHandle
,
$
headerLine
)
use
(&
$
responseHeaders
):
int
{
return
Http::
parseResponseHeaders
(
$
headerLine
,
$
responseHeaders
);
};
curl_setopt
(
$
curlHandle
, \
CURLOPT_URL
,
$
dsn
->
getEnvelopeApiEndpointUrl
());
curl_setopt
(
$
curlHandle
, \
CURLOPT_HTTPHEADER
,
$
requestHeaders
);
curl_setopt
(
$
curlHandle
, \
CURLOPT_USERAGENT
,
$
this
->
sdkIdentifier
.
'
/
'
.
$
this
->
sdkVersion
);
curl_setopt
(
$
curlHandle
, \
CURLOPT_TIMEOUT_MS
,
$
options
->
getHttpTimeout
() *
1000
);
curl_setopt
(
$
curlHandle
, \
CURLOPT_CONNECTTIMEOUT_MS
,
$
options
->
getHttpConnectTimeout
() *
1000
);
curl_setopt
(
$
curlHandle
, \
CURLOPT_ENCODING
,
''
);
curl_setopt
(
$
curlHandle
, \
CURLOPT_POST
,
true
);
curl_setopt
(
$
curlHandle
, \
CURLOPT_POSTFIELDS
,
$
requestData
);
curl_setopt
(
$
curlHandle
, \
CURLOPT_RETURNTRANSFER
,
true
);
curl_setopt
(
$
curlHandle
, \
CURLOPT_HEADERFUNCTION
,
$
responseHeaderCallback
);
curl_setopt
(
$
curlHandle
, \
CURLOPT_HTTP_VERSION
, \
CURL_HTTP_VERSION_1_1
);
if
(
$
options
->
isShareHandleEnabled
()) {
$
shareHandle
=
$
this
->
getShareHandle
();
if
(
$
shareHandle
!==
null
) {
curl_setopt
(
$
curlHandle
, \
CURLOPT_SHARE
,
$
shareHandle
);
}
}
$
httpSslVerifyPeer
=
$
options
->
getHttpSslVerifyPeer
();
if
(!
$
httpSslVerifyPeer
) {
curl_setopt
(
$
curlHandle
, \
CURLOPT_SSL_VERIFYPEER
,
false
);
}
$
httpSslNativeCa
=
$
options
->
getHttpSslNativeCa
();
if
(
$
httpSslNativeCa
) {
if
(
\defined
(
'
CURLSSLOPT_NATIVE_CA
'
)
&&
isset
(
curl_version
()[
'
version
'
])
&&
version_compare
(
curl_version
()[
'
version
'
],
'
7.71
'
,
'
>=
'
)
) {
curl_setopt
(
$
curlHandle
, \
CURLOPT_SSL_OPTIONS
, \
CURLSSLOPT_NATIVE_CA
);
}
}
$
httpProxy
=
$
options
->
getHttpProxy
();
if
(
$
httpProxy
!==
null
) {
curl_setopt
(
$
curlHandle
, \
CURLOPT_PROXY
,
$
httpProxy
);
curl_setopt
(
$
curlHandle
, \
CURLOPT_HEADEROPT
, \
CURLHEADER_SEPARATE
);
}
$
httpProxyAuthentication
=
$
options
->
getHttpProxyAuthentication
();
if
(
$
httpProxyAuthentication
!==
null
) {
curl_setopt
(
$
curlHandle
, \
CURLOPT_PROXYUSERPWD
,
$
httpProxyAuthentication
);
}
/** @var string|false $body */
$
body
=
curl_exec
(
$
curlHandle
);
if
(
$
body
===
false
) {
$
errorCode
=
curl_errno
(
$
curlHandle
);
$
error
=
curl_error
(
$
curlHandle
);
if
(\
PHP_MAJOR_VERSION
<
8
) {
curl_close
(
$
curlHandle
);
}
$
message
=
'
cURL Error (
'
.
$
errorCode
.
'
)
'
.
$
error
;
return
new
Response
(
0
, [],
$
message
);
}
$
statusCode
=
curl_getinfo
(
$
curlHandle
, \
CURLINFO_HTTP_CODE
);
if
(\
PHP_MAJOR_VERSION
<
8
) {
curl_close
(
$
curlHandle
);
}
$
error
=
$
statusCode
>=
400
?
$
body
:
''
;
return
new
Response
(
$
statusCode
,
$
responseHeaders
,
$
error
);
}
/**
* Initializes a share handle for CURL requests. If available, it will always try to use a persistent
* share handle first and fall back to a regular share handle in case it's unavailable.
*
* @return object|resource|null a share handle or null if none could be created
*/
private
function
getShareHandle
()
{
if
(
$
this
->
shareHandle
!==
null
) {
return
$
this
->
shareHandle
;
}
if
(
\function_exists
(
'
curl_share_init_persistent
'
)) {
$
shareOptions
= [\
CURL_LOCK_DATA_DNS
];
if
(
\defined
(
'
CURL_LOCK_DATA_CONNECT
'
)) {
$
shareOptions
[] = \
CURL_LOCK_DATA_CONNECT
;
}
if
(
\defined
(
'
CURL_LOCK_DATA_SSL_SESSION
'
)) {
$
shareOptions
[] = \
CURL_LOCK_DATA_SSL_SESSION
;
}
try
{
$
this
->
shareHandle
=
curl_share_init_persistent
(
$
shareOptions
);
}
catch
(
\
Throwable
$
throwable
) {
// don't crash if the share handle cannot be created
$
this
->
shareHandle
=
null
;
}
}
// If the persistent share handle cannot be created or doesn't exist
if
(
$
this
->
shareHandle
===
null
) {
try
{
$
this
->
shareHandle
=
curl_share_init
();
curl_share_setopt
(
$
this
->
shareHandle
, \
CURLSHOPT_SHARE
, \
CURL_LOCK_DATA_DNS
);
if
(
\defined
(
'
CURL_LOCK_DATA_CONNECT
'
)) {
curl_share_setopt
(
$
this
->
shareHandle
, \
CURLSHOPT_SHARE
, \
CURL_LOCK_DATA_CONNECT
);
}
if
(
\defined
(
'
CURL_LOCK_DATA_SSL_SESSION
'
)) {
curl_share_setopt
(
$
this
->
shareHandle
, \
CURLSHOPT_SHARE
, \
CURL_LOCK_DATA_SSL_SESSION
);
}
}
catch
(
\
Throwable
$
throwable
) {
// don't crash if the share handle cannot be created
$
this
->
shareHandle
=
null
;
}
}
return
$
this
->
shareHandle
;
}
}
Back
|
FazBrowse Home
|
New Git URL