Skip to content

Commit

Permalink
Merge pull request #61 from upmind-automation/47-remove-guzzle-histor…
Browse files Browse the repository at this point in the history
…y-middleware

#47 - Remove GuzzleStack history
  • Loading branch information
uphlewis authored Apr 9, 2024
2 parents 280eb25 + 2ac2fda commit aa89efb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 46 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the package will be documented in this file.

## Unreleased

- Remove Guzzle stack history & request debug data (which use history)

## v4.0.1 - 2024-02-27

- Fix RuleParser issue with Rule expected to be a string, while a class or callback
Expand Down
47 changes: 1 addition & 46 deletions src/Provider/BaseCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ abstract class BaseCategory implements Contract\CategoryInterface
*/
protected $systemInfo;

/**
* Array containing the history of guzzle requests for this instance.
*
* @var array<Message[]>
*/
protected $guzzleHistory = [];

/**
* Returns the result of a successful provision function.
*
Expand Down Expand Up @@ -126,15 +119,12 @@ final public function getSystemInfo(): SystemInfo

/**
* Get a guzzle handler stack which logs requests/responses if provider is
* an instance of LogsDebugData and $debugLog === true. Requests and responses
* will also be stored in $this->guzzleHistory.
* an instance of LogsDebugData and $debugLog === true.
*/
protected function getGuzzleHandlerStack(bool $debugLog = false): HandlerStack
{
$stack = HandlerStack::create();

$stack->push(Middleware::history($this->guzzleHistory));

if (!$debugLog || !$this instanceof LogsDebugData) {
return $stack;
}
Expand All @@ -157,39 +147,4 @@ protected function getGuzzleHandlerStack(bool $debugLog = false): HandlerStack

return $stack;
}

/**
* Returns an assoc array of debug data for the last guzzle request/response
* for guzzle clients whose stack was obtained from `$this->getGuzzleHandlerStack()`.
*
* @return array<array<string[]>>|null
*/
protected function getLastGuzzleRequestDebug(): ?array
{
/** @var Request|null $lastRequest */
$lastRequest = Arr::last($this->guzzleHistory)['request'] ?? null;
/** @var Response|null $lastResponse */
$lastResponse = Arr::last($this->guzzleHistory)['response'] ?? null;

if (!$lastRequest) {
return null;
}

$debug = [
'last_request' => [
'method' => $lastRequest->getMethod(),
'url' => $lastRequest->getUri()->__toString(),
],
'last_response' => null
];

if ($lastResponse) {
$debug['last_response'] = [
'http_code' => $lastResponse->getStatusCode(),
'body' => Str::limit($lastResponse->getBody()->__toString(), 300),
];
}

return $debug;
}
}

0 comments on commit aa89efb

Please sign in to comment.