Headers   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 18
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 16 5
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
8
class Headers
9
{
10
    public function handle(Request $request, Closure $next)
11
    {
12
        // Check if FORCE_HTTPS is set to true
13
        if (env('FORCE_HTTPS') == 'true') {
14
            \URL::forceScheme('https'); // Force HTTPS
15
            header("Content-Security-Policy: upgrade-insecure-requests");
16
        }
17
18
        // Check if FORCE_ROUTE_HTTPS is set to true
19
        if (env('FORCE_ROUTE_HTTPS') == 'true' && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off')) {
20
            $redirect_url = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
21
            header("Location: $redirect_url");
22
            exit();
23
        }
24
25
        return $next($request);
26
    }
27
}
28