Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setTcpConnectTimeout example
catch
(
HttpException|StreamException
)
{
// Ignore streaming errors on previous responses
}
++
$info
[
'redirect_count'
]
;
$info
[
'url'
]
=
$info
[
'redirect_url'
]
;
$info
[
'redirect_url'
]
= null;
$previousUrl
=
$location
;
$request
=
new
Request
(
$info
[
'url'
]
,
$info
[
'http_method'
]
)
;
$request
->
setProtocolVersions
(
$originRequest
->
getProtocolVersions
(
)
)
;
$request
->
setTcpConnectTimeout
(
$originRequest
->
getTcpConnectTimeout
(
)
)
;
$request
->
setTlsHandshakeTimeout
(
$originRequest
->
getTlsHandshakeTimeout
(
)
)
;
$request
->
setTransferTimeout
(
$originRequest
->
getTransferTimeout
(
)
)
;
if
(
\
in_array
(
$status
,
[
301, 302, 303
]
, true
)
)
{
$originRequest
->
removeHeader
(
'transfer-encoding'
)
;
$originRequest
->
removeHeader
(
'content-length'
)
;
$originRequest
->
removeHeader
(
'content-type'
)
;
// Do like curl and browsers: turn POST to GET on 301, 302 and 303
if
(
'POST' ===
$response
->
getRequest
(
)
->
getMethod
(
)
|| 303 ===
$status
)
{
$info
[
'http_method'
]
= 'HEAD' ===
$response
->
getRequest
(
)
->
getMethod
(
)
? 'HEAD' : 'GET';
1.0 =>
[
'1.0'
]
,
1.1 =>
$request
->
setProtocolVersions
(
[
'1.1', '1.0'
]
)
,
default
=>
[
'2', '1.1', '1.0'
]
,
}
)
;
}
foreach
(
$options
[
'headers'
]
as
$v
)
{
$h
=
explode
(
': ',
$v
, 2
)
;
$request
->
addHeader
(
$h
[
0
]
,
$h
[
1
]
)
;
}
$request
->
setTcpConnectTimeout
(
1000 *
$options
[
'timeout'
]
)
;
$request
->
setTlsHandshakeTimeout
(
1000 *
$options
[
'timeout'
]
)
;
$request
->
setTransferTimeout
(
1000 *
$options
[
'max_duration'
]
)
;
if
(
method_exists
(
$request
, 'setInactivityTimeout'
)
)
{
$request
->
setInactivityTimeout
(
0
)
;
}
if
(
'' !==
$request
->
getUri
(
)
->
getUserInfo
(
)
&& !
$request
->
hasHeader
(
'authorization'
)
)
{
$auth
=
explode
(
':',
$request
->
getUri
(
)
->
getUserInfo
(
)
, 2
)
;
$auth
=
array_map
(
'rawurldecode',
$auth
)
+
[
1 => ''
]
;
$request
->
setHeader
(
'Authorization', 'Basic '.
base64_encode
(
implode
(
':',
$auth
)
)
)
;
}