Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setProtocolVersions 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
)
{
if
(
$options
[
'resolve'
]
)
{
$this
->multi->dnsCache =
$options
[
'resolve'
]
+
$this
->multi->dnsCache;
}
if
(
$options
[
'peer_fingerprint'
]
&& !
isset
(
$options
[
'peer_fingerprint'
]
[
'pin-sha256'
]
)
)
{
throw
new
TransportException
(
__CLASS__.' supports only "pin-sha256" fingerprints.'
)
;
}
$request
=
new
Request
(
implode
(
'',
$url
)
,
$method
)
;
if
(
$options
[
'http_version'
]
)
{
$request
->
setProtocolVersions
(
match
(
(float)
$options
[
'http_version'
]
)
{
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
]
)
;
}