Skip to content

Commit

Permalink
さくらのVPSのSSLに対応
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Oct 22, 2024
1 parent 93e6e07 commit 637f64c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions plugins/baser-core/src/Middleware/BcRequestFilterMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,20 @@ public function process(
*/
if(filter_var(env('TRUST_PROXY', false), FILTER_VALIDATE_BOOLEAN)) {
$request->trustProxy = true;
$request->addDetector('https', ['env' => 'HTTP_X_FORWARDED_SSL', 'options' => [1, 'on']]);
$request->addDetector('https', ['env' => 'HTTP_X_FORWARDED_PROTO', 'options' => [1, 'https']]);
$request->addDetector('https', ['env' => 'HTTP_HTTPS', 'options' => [1, 'on']]);
$request->addDetector('https', function() {
$detectors = [
['env' => 'HTTP_X_FORWARDED_SSL', 'options' => [1, 'on']],
['env' => 'HTTP_X_FORWARDED_PROTO', 'options' => [1, 'https']],
['env' => 'HTTP_HTTPS', 'options' => [1, 'on']]
];
foreach($detectors as $detect) {
$pattern = '/' . implode('|', $detect['options']) . '/i';
if(preg_match($pattern, (string)env($detect['env']))){
return true;
}
}
return false;
});
}

return $handler->handle($request);
Expand Down

0 comments on commit 637f64c

Please sign in to comment.