Skip to content

Commit

Permalink
[10.x] Fix Http global middleware for queue, octane, and dependecy in…
Browse files Browse the repository at this point in the history
…jection (#47915)

* Ensure global middleware is shared across Octane requests and queued jobs

* Rename import

* Update FoundationServiceProvider.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
timacdonald and taylorotwell authored Aug 1, 2023
1 parent 872b086 commit 4e0716b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,6 +42,7 @@ class FoundationServiceProvider extends AggregateServiceProvider
* @var array
*/
public $singletons = [
HttpFactory::class => HttpFactory::class,
Vite::class => Vite::class,
];

Expand Down
24 changes: 24 additions & 0 deletions tests/Integration/Http/HttpClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Illuminate\Tests\Integration\Http;

use Illuminate\Http\Client\Factory;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Facades\Http;
use Orchestra\Testbench\TestCase;

class HttpClientTest extends TestCase
{
public function testGlobalMiddlewarePersistsAfterFacadeFlush(): void
{
Http::macro('getGlobalMiddleware', fn () => $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());
}
}

0 comments on commit 4e0716b

Please sign in to comment.