feat(http): add GuzzleHttp middleware to dispatch Laravel HTTP events#172
feat(http): add GuzzleHttp middleware to dispatch Laravel HTTP events#172saeedhosan wants to merge 0 commit into
Conversation
|
Did you have any inspiration from some battle-tested packages? I'm a bit concerned of swapping out the default HTTP client for some homegrown implementation. Maybe we can have a specific flag that invokes this for a bit of A/B testing.
Or if not - any links I can read on how emitted these events creates something Laravel can react with. |
|
Thanks for the feedback!
Not directly — the idea came from our org project, where we needed every request/response logged consistently. About swapping the default HTTP client — I understand the concern. Instead of replacing it, we can keep using Guzzle and let users use pre-defined or custom handlers: Guzzle HandlerStack. Alternatively, this option will allows users to create and use their own custom HTTP handler to interact request/response using handler HandlerStack. Example config: // config/openai.php
'http_handler' => \App\Http\Handlers\CustomHandler::class,Example Package-defined handlers: // config/openai.php
'http_handler' => \OpenAI\Http\Handlers\DefaultHandler::class,Example ServiceProvider setup: ...
->withHttpClient(new \GuzzleHttp\Client([
'timeout' => config('openai.request_timeout', 30),
'handler' => TheResolverClass::resolve(config('openai.http_handler')),
]));Example User Handler class would look: namespace App\Http\Handlers;
class CustomHandler
{
/**
* The handler execute.
*/
public function __invoke(): void
{
// logic here
}
}This keeps the package used client compatibility while giving users flexibility. I can update the PR with this handler-based approach, including tests and docs. |
✨ Feature: Guzzle Middleware for Laravel HTTP Events
Summary
Added a GuzzleHttp middleware that dispatches Laravel HTTP client events for better integration.
Benefits
RequestSending,ResponseReceived, andConnectionFailedChanges
GuzzleHttpAdapterHttp::event listeners are triggered properlyUpdated Core ServiceProvider
This update required modifying the package's core service provider implementation.
Currently
Previously
✅ Tests
All Pest tests passed successfully.
Type:
feat(http)