Skip to content

Commit 1d1c6d7

Browse files
authored
Merge pull request #221 from ndm2/issue/unauthenticated-redirect-code
Use `302` instead of `301` for redirecting unauthenticated requests.
2 parents 3dd76f4 + f200e0c commit 1d1c6d7

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Middleware/AuthenticationMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
125125
$url = $this->getRedirectUrl($target, $request);
126126

127127
return $response
128-
->withStatus(301)
128+
->withStatus(302)
129129
->withHeader('Location', $url);
130130
}
131131
throw $e;

tests/TestCase/Middleware/AuthenticationMiddlewareTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ public function testUnauthenticatedRedirect()
438438
};
439439

440440
$response = $middleware($request, $response, $next);
441-
$this->assertSame(301, $response->getStatusCode());
441+
$this->assertSame(302, $response->getStatusCode());
442442
$this->assertSame('/users/login', $response->getHeaderLine('Location'));
443443
$this->assertSame('', $response->getBody() . '');
444444
}
@@ -467,7 +467,7 @@ public function testUnauthenticatedRedirectWithQuery()
467467
};
468468

469469
$response = $middleware($request, $response, $next);
470-
$this->assertSame(301, $response->getStatusCode());
470+
$this->assertSame(302, $response->getStatusCode());
471471
$this->assertSame('/users/login?redirect=http%3A%2F%2Flocalhost%2Ftestpath', $response->getHeaderLine('Location'));
472472
$this->assertSame('', $response->getBody() . '');
473473
}
@@ -496,7 +496,7 @@ public function testUnauthenticatedRedirectWithExistingQuery()
496496
};
497497

498498
$response = $middleware($request, $response, $next);
499-
$this->assertSame(301, $response->getStatusCode());
499+
$this->assertSame(302, $response->getStatusCode());
500500
$this->assertSame('/users/login?hello=world&redirect=http%3A%2F%2Flocalhost%2Ftestpath', $response->getHeaderLine('Location'));
501501
$this->assertSame('', $response->getBody() . '');
502502
}

0 commit comments

Comments
 (0)