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

Added config to force scheme for the server request. #354

Open
wants to merge 3 commits into
base: PHP-7.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config/laravels.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@

'laravel_base_path' => env('LARAVEL_BASE_PATH', base_path()),

/*
|--------------------------------------------------------------------------
| HTTP Force SSL
|--------------------------------------------------------------------------
|
| With this set, Swoole Server will place the header "Scheme", used by
| laravel to define routes through the application. This is important if
| you are using Swoole alone (not using nginx/apache proxy).
|
*/
'http_force_ssl' => env('LARAVELS_HTTP_FORCE_SSL', false),

/*
|--------------------------------------------------------------------------
| Inotify Reload
Expand Down
8 changes: 8 additions & 0 deletions src/Swoole/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public function toIlluminateRequest(array $rawServer = [], array $rawEnv = [])
}
}
$server = array_change_key_case($server, CASE_UPPER);

if (
config('laravels.http_force_ssl', false)
&& !isset($server['REQUEST_SCHEME'])
) {
$server['REQUEST_SCHEME'] = 'https';
}

$_SERVER = array_merge($_SERVER, $server);
if (isset($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] === 'https') {
$_SERVER['HTTPS'] = 'on';
Expand Down