File tree 2 files changed +35
-7
lines changed
src/Illuminate/Http/Client
2 files changed +35
-7
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,13 @@ class PendingRequest
42
42
*/
43
43
protected $ client ;
44
44
45
+ /**
46
+ * The Guzzle HTTP handler.
47
+ *
48
+ * @var callable
49
+ */
50
+ protected $ handler ;
51
+
45
52
/**
46
53
* The base URL for the request.
47
54
*
@@ -966,9 +973,7 @@ protected function populateResponse(Response $response)
966
973
*/
967
974
public function buildClient ()
968
975
{
969
- return $ this ->requestsReusableClient ()
970
- ? $ this ->getReusableClient ()
971
- : $ this ->createClient ($ this ->buildHandlerStack ());
976
+ return $ this ->client ?? $ this ->createClient ($ this ->buildHandlerStack ());
972
977
}
973
978
974
979
/**
@@ -1012,7 +1017,7 @@ public function createClient($handlerStack)
1012
1017
*/
1013
1018
public function buildHandlerStack ()
1014
1019
{
1015
- return $ this ->pushHandlers (HandlerStack::create ());
1020
+ return $ this ->pushHandlers (HandlerStack::create ($ this -> handler ));
1016
1021
}
1017
1022
1018
1023
/**
@@ -1278,9 +1283,7 @@ public function setClient(Client $client)
1278
1283
*/
1279
1284
public function setHandler ($ handler )
1280
1285
{
1281
- $ this ->client = $ this ->createClient (
1282
- $ this ->pushHandlers (HandlerStack::create ($ handler ))
1283
- );
1286
+ $ this ->handler = $ handler ;
1284
1287
1285
1288
return $ this ;
1286
1289
}
Original file line number Diff line number Diff line change @@ -1139,6 +1139,31 @@ public function testMultipleRequestsAreSentInThePoolWithKeys()
1139
1139
$ this ->assertSame (500 , $ responses ['test500 ' ]->status ());
1140
1140
}
1141
1141
1142
+ public function testMiddlewareRunsInPool ()
1143
+ {
1144
+ $ this ->factory ->fake (function (Request $ request ) {
1145
+ return $ this ->factory ->response ('Fake ' );
1146
+ });
1147
+
1148
+ $ history = [];
1149
+
1150
+ $ middleware = Middleware::history ($ history );
1151
+
1152
+ $ responses = $ this ->factory ->pool (fn (Pool $ pool ) => [
1153
+ $ pool ->withMiddleware ($ middleware )->post ('https://example.com ' , ['hyped-for ' => 'laravel-movie ' ]),
1154
+ ]);
1155
+
1156
+ $ response = $ responses [0 ];
1157
+
1158
+ $ this ->assertSame ('Fake ' , $ response ->body ());
1159
+
1160
+ $ this ->assertCount (1 , $ history );
1161
+
1162
+ $ this ->assertSame ('Fake ' , tap ($ history [0 ]['response ' ]->getBody ())->rewind ()->getContents ());
1163
+
1164
+ $ this ->assertSame (['hyped-for ' => 'laravel-movie ' ], json_decode (tap ($ history [0 ]['request ' ]->getBody ())->rewind ()->getContents (), true ));
1165
+ }
1166
+
1142
1167
public function testTheRequestSendingAndResponseReceivedEventsAreFiredWhenARequestIsSent ()
1143
1168
{
1144
1169
$ events = m::mock (Dispatcher::class);
You can’t perform that action at this time.
0 commit comments