Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] Except URIs from CheckForMaintenanceMode middleware #24740

Conversation

thannaske
Copy link
Contributor

Feature
Like in the VerfiyCsrfToken middleware you should be able to specify URIs that are excluded from the handling of the CheckForMaintenanceMode middleware by adding them to a $except array. URIs that are matching are handled by the application even when maintenance mode is currently active.

Type
I consider this a minor feature.

Background & Use Case
Check the old pull request (#24731) that was designed to extend the artisan down command and the original feature proposal (laravel/ideas#1242) for a deeper description of the use case.

Usage
Same procedure as in the VerifyCsrfToken middleware:

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware;

class CheckForMaintenanceMode extends Middleware
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        '/legal',
        '/privacy',
        '/terms',
        '/even/wildcards/are/okay/*
    ];
}

Breaking Changes
None. The middleware keeps its usual behavior unless the $except array gets redefined in a child middleware that extends the CheckForMaintenanceMode middleware.

Copy link
Contributor

@m1guelpf m1guelpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests?

@thannaske
Copy link
Contributor Author

thannaske commented Jul 5, 2018

@m1guelpf The integrated function is the same as in the VerifyCsrfToken middleware, which is tested in tests/Integration/Http/Middleware/VerifyCsrfTokenExceptTest.

Edit
All right, all right. Thumbs down. I'll provide the test to satisfy your silent criticism.

@taylorotwell taylorotwell merged commit e535b30 into laravel:5.6 Jul 10, 2018
@thannaske thannaske deleted the feature-maintenance-middleware-except-array branch July 10, 2018 19:35
@tetrahedronix
Copy link

tetrahedronix commented Jul 28, 2018

Will this feature work with package development? I tried to extend CheckForMaintenanceMode class and register it in the Service Provider but it doesn't work. I'm using Laravel Framework 5.6.28.

Edit: OK, using the prependMiddleware method it works fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants