@@ -889,7 +889,7 @@ public function send(string $method, string $url, array $options = [])
889
889
890
890
return retry ($ this ->tries ?? 1 , function ($ attempt ) use ($ method , $ url , $ options , &$ shouldRetry ) {
891
891
try {
892
- return tap (new Response ($ this ->sendRequest ($ method , $ url , $ options )), function ($ response ) use ($ attempt , &$ shouldRetry ) {
892
+ return tap ($ this -> newResponse ($ this ->sendRequest ($ method , $ url , $ options )), function ($ response ) use ($ attempt , &$ shouldRetry ) {
893
893
$ this ->populateResponse ($ response );
894
894
895
895
$ this ->dispatchResponseReceivedEvent ($ response );
@@ -1001,13 +1001,13 @@ protected function makePromise(string $method, string $url, array $options = [])
1001
1001
{
1002
1002
return $ this ->promise = $ this ->sendRequest ($ method , $ url , $ options )
1003
1003
->then (function (MessageInterface $ message ) {
1004
- return tap (new Response ($ message ), function ($ response ) {
1004
+ return tap ($ this -> newResponse ($ message ), function ($ response ) {
1005
1005
$ this ->populateResponse ($ response );
1006
1006
$ this ->dispatchResponseReceivedEvent ($ response );
1007
1007
});
1008
1008
})
1009
1009
->otherwise (function (TransferException $ e ) {
1010
- return $ e instanceof RequestException && $ e ->hasResponse () ? $ this ->populateResponse (new Response ($ e ->getResponse ())) : $ e ;
1010
+ return $ e instanceof RequestException && $ e ->hasResponse () ? $ this ->populateResponse ($ this -> newResponse ($ e ->getResponse ())) : $ e ;
1011
1011
});
1012
1012
}
1013
1013
@@ -1193,7 +1193,7 @@ public function buildRecorderHandler()
1193
1193
return $ promise ->then (function ($ response ) use ($ request , $ options ) {
1194
1194
$ this ->factory ?->recordRequestResponsePair(
1195
1195
(new Request ($ request ))->withData ($ options ['laravel_data ' ]),
1196
- new Response ($ response )
1196
+ $ this -> newResponse ($ response )
1197
1197
);
1198
1198
1199
1199
return $ response ;
@@ -1298,6 +1298,17 @@ public function mergeOptions(...$options)
1298
1298
);
1299
1299
}
1300
1300
1301
+ /**
1302
+ * Create a new response instance using the given PSR response.
1303
+ *
1304
+ * @param \Psr\Http\Message\MessageInterface $response
1305
+ * @return Response
1306
+ */
1307
+ protected function newResponse ($ response )
1308
+ {
1309
+ return new Response ($ response );
1310
+ }
1311
+
1301
1312
/**
1302
1313
* Register a stub callable that will intercept requests and be able to return stub responses.
1303
1314
*
0 commit comments