Skip to content

Commit

Permalink
Allows to disable redirect to favicon.ico logic (#121)
Browse files Browse the repository at this point in the history
* Allows to disable `redirect_favicon_ico`

* Update RedirectStaticAssets.php

* Update RedirectStaticAssetsTest.php

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
nunomaduro and taylorotwell authored Feb 14, 2022
1 parent c558f64 commit 517704a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Runtime/Http/Middleware/RedirectStaticAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RedirectStaticAssets
*/
public function handle($request, $next)
{
if ($request->path() === 'favicon.ico') {
if (config('vapor.redirect_favicon', true) && $request->path() === 'favicon.ico') {
return new RedirectResponse($_ENV['ASSET_URL'].'/favicon.ico', 302, [
'Cache-Control' => 'public, max-age=3600',
]);
Expand Down
40 changes: 40 additions & 0 deletions tests/Feature/RedirectStaticAssetsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Laravel\Vapor\Tests\Feature;

use Illuminate\Support\Facades\Route;
use Laravel\Vapor\Runtime\Http\Middleware\RedirectStaticAssets;
use Laravel\Vapor\VaporServiceProvider;
use Orchestra\Testbench\TestCase;

class RedirectStaticAssetsTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();

$_ENV['ASSET_URL'] = 'https://asset-url.com';

Route::get('/favicon.ico', function () {
return 'My own favicon.';
})->middleware(RedirectStaticAssets::class);
}

protected function getPackageProviders($app): array
{
return [
VaporServiceProvider::class,
];
}

public function test_redirects_to_favicon_ico()
{
$response = $this->get('/favicon.ico');
$response->assertStatus(302)->assertRedirect('https://asset-url.com/favicon.ico');

config()->set('vapor.redirect_favicon', false);

$response = $this->get('/favicon.ico');
$response->assertStatus(200)->assertSee('My own favicon.');
}
}

0 comments on commit 517704a

Please sign in to comment.