Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Guzzle Redirect History Middleware

Guzzle Redirect History Middleware Laravel Package

spatie/guzzle-redirect-history-middleware

Guzzle middleware that records redirect chains for each request. Attach RedirectHistoryMiddleware to your handler stack to capture every Location hop and inspect the final URL and intermediate redirects via a RedirectHistory instance.

View on GitHub
Deep Wiki
Context7

A Guzzle middleware to keep track of redirects

Frequently asked questions about Guzzle Redirect History Middleware
How do I install this package in a Laravel project?
Run `composer require spatie/guzzle-redirect-history-middleware` to install the package. No additional configuration is needed unless you’re using Guzzle 7, which may require manual PSR-7 compatibility checks.
Does this work with Laravel’s built-in HTTP client (Http::client())?
Yes, the middleware integrates natively with Laravel’s HTTP client. Use `Http::withMiddleware()` or register it globally in `AppServiceProvider` via a macro for consistent redirect tracking across requests.
Will this break if I upgrade Guzzle from 6 to 7?
The package was originally built for Guzzle 6. While Guzzle 7 uses PSR-7 interfaces, the middleware’s core functionality remains compatible. Test thoroughly, especially if using custom request/response handling.
Can I use this for logging redirects to a database?
The middleware stores redirects in memory as an array. To persist them, manually log the `RedirectHistory` instance (e.g., via Laravel’s logging or a database) after each request.
Is there a performance impact from tracking redirects?
The overhead is minimal—only the redirect history is stored in memory. No known scalability issues, but monitor response times if tracking thousands of redirects per second.
How do I test redirect tracking in CI?
Use Laravel’s `Http::fake()` to mock requests and verify the `RedirectHistory` array. Alternatively, test with a real Guzzle client in a CI environment by asserting the history after each request.
What Laravel versions does this support?
The package works with Laravel 7+ (Guzzle 6/7). For Laravel 8/9, ensure your Guzzle version is up-to-date, as newer Laravel releases may bundle updated Guzzle versions.
Can I use this for API compliance audits?
Yes, the middleware is observability-first. Capture redirect chains in `RedirectHistory`, then serialize or log them for audits. Combine with Laravel’s logging or a dedicated analytics service.
What if the package stops being maintained?
The MIT license allows forking. Since the middleware is lightweight, you could extend or maintain it yourself. Check Guzzle’s changelog for breaking changes if upgrading versions.
Are there alternatives to this package?
For simple cases, Laravel’s `Http::history()` (via macros) may suffice. For advanced logging, pair this with `monolog/handler` or use Guzzle’s built-in `History` middleware, though it lacks Laravel integration.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport