- 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.