Skip to content

Commit

Permalink
Merge branch 'hannesvdvreken/7.x' into 7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jun 24, 2020
2 parents d16ff3a + b718d3a commit 9a19527
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Illuminate/Http/Client/PendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use GuzzleHttp\Cookie\CookieJar;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\HandlerStack;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;

Expand Down Expand Up @@ -97,6 +98,13 @@ class PendingRequest
*/
protected $stubCallbacks;

/**
* The middleware callables added by users that will handle requests.
*
* @var \Illuminate\Support\Collection
*/
protected $middleware;

/**
* Create a new HTTP Client instance.
*
Expand All @@ -106,6 +114,7 @@ class PendingRequest
public function __construct(Factory $factory = null)
{
$this->factory = $factory;
$this->middleware = new Collection;

$this->asJson();

Expand Down Expand Up @@ -385,6 +394,19 @@ public function withOptions(array $options)
});
}

/**
* Add new middleware the client handler stack.
*
* @param callable $middleware
* @return $this
*/
public function withMiddleware(callable $middleware)
{
$this->middleware->push($middleware);

return $this;
}

/**
* Add a new "before sending" callback to the request.
*
Expand Down Expand Up @@ -599,6 +621,10 @@ public function buildHandlerStack()
$stack->push($this->buildBeforeSendingHandler());
$stack->push($this->buildRecorderHandler());
$stack->push($this->buildStubHandler());

$this->middleware->each(function ($middleware) use ($stack) {
$stack->push($middleware);
});
});
}

Expand Down

0 comments on commit 9a19527

Please sign in to comment.