Skip to content

Commit

Permalink
Fix handling of the 410 Gone status
Browse files Browse the repository at this point in the history
  • Loading branch information
riasvdv committed May 3, 2021
1 parent d717405 commit d177101
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## 1.4.4 (2021-05-03)
### What's Fixed
- Fix handling of the 410 Gone status

## 1.4.3 (2021-03-10)
### What's Fixed
- Fixed an issue where query parameters were ignored
Expand Down
4 changes: 4 additions & 0 deletions src/Http/Middleware/HandleNotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public function handle(Request $request, Closure $next)
$this->markErrorHandled($error, $redirect->destination());
}

if ((string) $redirect->type() === (string) 410) {
return response()->noContent(410);
}

return redirect($redirect->destination(), $redirect->type());
} catch (\Exception $e) {
/*
Expand Down
37 changes: 37 additions & 0 deletions tests/Feature/Middleware/HandleNotFoundTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ public function it_redirects_and_sets_handled_if_a_redirect_is_found()
$this->assertTrue($response->isRedirect(url('/def')));
}

/** @test * */
public function it_handles_401_redirects()
{
Redirect::make()
->source('/abc')
->destination('/def')
->type(410)
->save();

$response = $this->middleware->handle(Request::create('/abc'), function () {
return (new Response('', 404));
});

$this->assertEquals(1, Error::query()->count());
$this->assertEquals('/abc', Error::query()->first()->url());
$this->assertEquals(true, Error::query()->first()->handled());

$this->assertEquals(410, $response->getStatusCode());
$this->assertEquals('', $response->content());
}

/** @test * */
public function it_handles_query_parameters()
{
Expand Down Expand Up @@ -117,6 +138,22 @@ public function it_can_redirect_to_external_urls()
$this->assertTrue($response->isRedirect('https://google.com?s=a'));
}

/** @test * */
public function it_can_redirect_the_homepage()
{
Redirect::make()
->source('/')
->destination('/blog')
->matchType(MatchTypeEnum::EXACT)
->save();

$response = $this->middleware->handle(Request::create('/'), function () {
return (new Response('', 404));
});

$this->assertTrue($response->isRedirect(url('/blog')));
}

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

0 comments on commit d177101

Please sign in to comment.