Skip to content

Commit 4e0716b

Browse files
[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 <[email protected]>
1 parent 872b086 commit 4e0716b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Illuminate/Foundation/Providers/FoundationServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Illuminate\Foundation\MaintenanceModeManager;
1414
use Illuminate\Foundation\Precognition;
1515
use Illuminate\Foundation\Vite;
16+
use Illuminate\Http\Client\Factory as HttpFactory;
1617
use Illuminate\Http\Request;
1718
use Illuminate\Log\Events\MessageLogged;
1819
use Illuminate\Support\AggregateServiceProvider;
@@ -41,6 +42,7 @@ class FoundationServiceProvider extends AggregateServiceProvider
4142
* @var array
4243
*/
4344
public $singletons = [
45+
HttpFactory::class => HttpFactory::class,
4446
Vite::class => Vite::class,
4547
];
4648

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Integration\Http;
4+
5+
use Illuminate\Http\Client\Factory;
6+
use Illuminate\Support\Facades\Facade;
7+
use Illuminate\Support\Facades\Http;
8+
use Orchestra\Testbench\TestCase;
9+
10+
class HttpClientTest extends TestCase
11+
{
12+
public function testGlobalMiddlewarePersistsAfterFacadeFlush(): void
13+
{
14+
Http::macro('getGlobalMiddleware', fn () => $this->globalMiddleware);
15+
Http::globalRequestMiddleware(fn ($request) => $request->withHeader('User-Agent', 'Example Application/1.0'));
16+
Http::globalRequestMiddleware(fn ($request) => $request->withHeader('User-Agent', 'Example Application/1.0'));
17+
18+
$this->assertCount(2, Http::getGlobalMiddleware());
19+
20+
Facade::clearResolvedInstances();
21+
22+
$this->assertCount(2, Http::getGlobalMiddleware());
23+
}
24+
}

0 commit comments

Comments
 (0)