Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
replaceRequest example
$delay
=
$this
->
getDelayFromHeader
(
$context
->
getHeaders
(
)
)
??
$this
->strategy->
getDelay
(
$context
, !
$exception
&&
$chunk
->
isLast
(
)
?
$content
: null,
$exception
)
;
++
$retryCount
;
$content
= '';
$firstChunk
= null;
$this
->logger?->
info
(
'Try #{count} after {delay}ms'.
(
$exception
? ': '.
$exception
->
getMessage
(
)
: ', status code: '.
$context
->
getStatusCode
(
)
)
,
[
'count' =>
$retryCount
,
'delay' =>
$delay
,
]
)
;
$context
->
setInfo
(
'retry_count',
$retryCount
)
;
$context
->
replaceRequest
(
$method
,
$url
, self::
shiftBaseUri
(
$options
,
$baseUris
)
)
;
$context
->
pause
(
$delay
/ 1000
)
;
if
(
$retryCount
>=
$maxRetries
)
{
$context
->
passthru
(
)
;
}
}
)
;
}
private
function
getDelayFromHeader
(
array
$headers
)
: ?int
{
if
(
null !==
$after
=
$headers
[
'retry-after'
]
[
0
]
?? null
)
{
HttpClientTestCase::
testTimeoutOnDestruct
(
)
;
}
public
function
testRetry404
(
)
{
$client
=
$this
->
getHttpClient
(
__FUNCTION__,
function
DChunkInterface
$chunk
, AsyncContext
$context
)
{
$this
->
assertTrue
(
$chunk
->
isFirst
(
)
)
;
$this
->
assertSame
(
404,
$context
->
getStatusCode
(
)
)
;
$context
->
getResponse
(
)
->
cancel
(
)
;
$context
->
replaceRequest
(
'GET', 'http://localhost:8057/'
)
;
$context
->
passthru
(
)
;
}
)
;
$response
=
$client
->
request
(
'GET', 'http://localhost:8057/404'
)
;
foreach
(
$client
->
stream
(
$response
)
as
$chunk
)
{
}
$this
->
assertTrue
(
$chunk
->
isLast
(
)
)
;
$this
->
assertSame
(
200,
$response
->
getStatusCode
(
)
)
;
}
}
catch
(
TransportExceptionInterface
)
{
$state
->lastError =
$lastError
??
hrtime
(
true
)
/ 1E9;
if
(
null ===
$state
->buffer
||
(
$isTimeout
&&
hrtime
(
true
)
/ 1E9 -
$state
->lastError <
$state
->reconnectionTime
)
)
{
yield
$chunk
;
}
else
{
$options
[
'headers'
]
[
'Last-Event-ID'
]
=
$state
->lastEventId;
$state
->buffer = '';
$state
->lastError =
hrtime
(
true
)
/ 1E9;
$context
->
getResponse
(
)
->
cancel
(
)
;
$context
->
replaceRequest
(
$method
,
$url
,
$options
)
;
if
(
$isTimeout
)
{
yield
$chunk
;
}
else
{
$context
->
pause
(
$state
->reconnectionTime
)
;
}
}
return
;
}
if
(
$chunk
->
isFirst
(
)
)
{