From 4e0716b0548cbdad37507819294299ae9796d634 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 2 Aug 2023 00:06:47 +1000 Subject: [PATCH] [10.x] Fix Http global middleware for queue, octane, and dependecy injection (#47915) * Ensure global middleware is shared across Octane requests and queued jobs * Rename import * Update FoundationServiceProvider.php --------- Co-authored-by: Taylor Otwell --- .../Providers/FoundationServiceProvider.php | 2 ++ tests/Integration/Http/HttpClientTest.php | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/Integration/Http/HttpClientTest.php diff --git a/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php b/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php index 45b51d6338f6..1d5ed5ff03c8 100644 --- a/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php +++ b/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php @@ -13,6 +13,7 @@ use Illuminate\Foundation\MaintenanceModeManager; use Illuminate\Foundation\Precognition; use Illuminate\Foundation\Vite; +use Illuminate\Http\Client\Factory as HttpFactory; use Illuminate\Http\Request; use Illuminate\Log\Events\MessageLogged; use Illuminate\Support\AggregateServiceProvider; @@ -41,6 +42,7 @@ class FoundationServiceProvider extends AggregateServiceProvider * @var array */ public $singletons = [ + HttpFactory::class => HttpFactory::class, Vite::class => Vite::class, ]; diff --git a/tests/Integration/Http/HttpClientTest.php b/tests/Integration/Http/HttpClientTest.php new file mode 100644 index 000000000000..6c952f195a75 --- /dev/null +++ b/tests/Integration/Http/HttpClientTest.php @@ -0,0 +1,24 @@ + $this->globalMiddleware); + Http::globalRequestMiddleware(fn ($request) => $request->withHeader('User-Agent', 'Example Application/1.0')); + Http::globalRequestMiddleware(fn ($request) => $request->withHeader('User-Agent', 'Example Application/1.0')); + + $this->assertCount(2, Http::getGlobalMiddleware()); + + Facade::clearResolvedInstances(); + + $this->assertCount(2, Http::getGlobalMiddleware()); + } +}