Created
December 9, 2015 00:02
-
-
Save geggleto/a0ff2451fbf9d6e388ef to your computer and use it in GitHub Desktop.
Slim 3 Middleware - Force HTTPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$app->add(function (Request $request, Response $response, $next) { | |
if ($request->getUri()->getScheme() !== 'https') { | |
$uri = $request->getUri()->withScheme("https")->withPort(null); | |
return $response->withRedirect( (string)$uri ); | |
} else { | |
return $next($request, $response); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
Request
type hint undestands itself under current namespace, if not “use-statemented” otherwise. So you possibly forgot ause
statement in your script, like this: