Skip to content

Commit

Permalink
# 1.1.0 - 2018-08-17
Browse files Browse the repository at this point in the history
- ADD support for X-Forwarded-Proto request header.
  • Loading branch information
lopadova committed Aug 17, 2018
1 parent 3f89554 commit ef1f273
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

All Notable changes to `laravel-https` will be documented in this file

## 1.1.0 - 2018-08-17

- ADD support for X-Forwarded-Proto request header.

## 1.0.3 - 2018-05-09

- Fix publish config path for unix (case sensitive)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -84,7 +84,7 @@ You can include the HttpsForce in a route groups or on individual routes.

### From Controller File:

You can include the HttpsForce in the contructor of your controller file.
You can include the HttpsForce in the constructor of your controller file.

### Controller File Example:

Expand Down
12 changes: 11 additions & 1 deletion src/Middleware/HttpsForceMiddleware.php
Expand Up @@ -16,7 +16,7 @@ class HttpsForceMiddleware
*/
public function handle(Request $request, Closure $next)
{
if ($request->secure()) {
if ($this->isSecureRequest($request)) {
return $next($request);
}

Expand All @@ -30,4 +30,14 @@ public function handle(Request $request, Closure $next)

return $next($request);
}

/**
* @param Request $request
* @return mixed
*/
public function isSecureRequest(Request $request)
{
$xForwardedProto = strtolower($request->header('X_FORWARDED_PROTO', ''));
return ($request->secure() || $xForwardedProto=='https');
}
}
17 changes: 17 additions & 0 deletions tests/LaravelHttpsTest.php
Expand Up @@ -58,6 +58,23 @@ public function testalways_force_httpsTrue()
$response->assertRedirect(secure_url('/'));
}

/** @test */
public function testIsSecureRequest_no_x_proto()
{
config(['laravel-https.always_force_https' => true]);
$response = $this->get('/');
$response->assertStatus(301);
$response->assertRedirect(secure_url('/'));
}

/** @test */
public function testIsSecureRequest_yes_x_proto()
{
config(['laravel-https.always_force_https' => true]);
$response = $this->get('/', ['X-Forwarded-Proto' => 'https']);
$response->assertStatus(200);
}

/** @test */
public function testEnviromentNotInArray()
{
Expand Down

0 comments on commit ef1f273

Please sign in to comment.