6
6
use GuzzleHttp \Cookie \CookieJar ;
7
7
use GuzzleHttp \Exception \ConnectException ;
8
8
use GuzzleHttp \HandlerStack ;
9
+ use Illuminate \Support \Collection ;
9
10
use Illuminate \Support \Str ;
10
11
use Illuminate \Support \Traits \Macroable ;
11
12
@@ -100,7 +101,7 @@ class PendingRequest
100
101
/**
101
102
* The middleware callables added by users that will handle requests.
102
103
*
103
- * @var \Illuminate\Support\Collection|null
104
+ * @var \Illuminate\Support\Collection
104
105
*/
105
106
protected $ middleware ;
106
107
@@ -113,6 +114,7 @@ class PendingRequest
113
114
public function __construct (Factory $ factory = null )
114
115
{
115
116
$ this ->factory = $ factory ;
117
+ $ this ->middleware = new Collection ;
116
118
117
119
$ this ->asJson ();
118
120
@@ -393,16 +395,16 @@ public function withOptions(array $options)
393
395
}
394
396
395
397
/**
396
- * Add new middleware the client handlerstack .
398
+ * Add new middleware the client handler stack .
397
399
*
398
400
* @param callable $middleware
399
401
* @return $this
400
402
*/
401
403
public function withMiddleware (callable $ middleware )
402
404
{
403
- return tap ( $ this , function ( $ request ) use ( $ middleware ) {
404
- return $ this -> middleware = collect ( $ this -> middleware )-> push ( $ middleware );
405
- }) ;
405
+ $ this -> middleware -> push ( $ middleware );
406
+
407
+ return $ this ;
406
408
}
407
409
408
410
/**
@@ -620,7 +622,7 @@ public function buildHandlerStack()
620
622
$ stack ->push ($ this ->buildRecorderHandler ());
621
623
$ stack ->push ($ this ->buildStubHandler ());
622
624
623
- collect ( $ this ->middleware ) ->each (function (callable $ middleware ) use ($ stack ) {
625
+ $ this ->middleware ->each (function ($ middleware ) use ($ stack ) {
624
626
$ stack ->push ($ middleware );
625
627
});
626
628
});
0 commit comments