Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,16 @@ public function isNotFound()
return (404 === $this->getStatusCode());
}

/**
* Does the status code indicate the resource is gone?
*
* @return bool
*/
public function isGone()
{
return (410 === $this->getStatusCode());
}

/**
* Do we have a normal, OK response?
*
Expand Down
22 changes: 22 additions & 0 deletions test/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,24 @@ public function test404IsClientErrorAndNotFound()
$this->assertFalse($response->isForbidden(), 'Response is an error, but isForbidden() returned true');
$this->assertFalse($response->isInformational(), 'Response is an error, but isInformational() returned true');
$this->assertTrue($response->isNotFound(), 'Response is an error, but isNotFound() returned false');
$this->assertFalse($response->isGone(), 'Response is an error, but isGone() returned true');
$this->assertFalse($response->isOk(), 'Response is an error, but isOk() returned true');
$this->assertFalse($response->isServerError(), 'Response is an error, but isServerError() returned true');
$this->assertFalse($response->isRedirect(), 'Response is an error, but isRedirect() returned true');
$this->assertFalse($response->isSuccess(), 'Response is an error, but isSuccess() returned true');
}

public function test410IsGone()
{
$response_text = $this->readResponse('response_410');
$response = Response::fromString($response_text);

$this->assertEquals(410, $response->getStatusCode(), 'Response code is expected to be 410, but it\'s not.');
$this->assertTrue($response->isClientError(), 'Response is an error, but isClientError() returned false');
$this->assertFalse($response->isForbidden(), 'Response is an error, but isForbidden() returned true');
$this->assertFalse($response->isInformational(), 'Response is an error, but isInformational() returned true');
$this->assertFalse($response->isNotFound(), 'Response is an error, but isNotFound() returned true');
$this->assertTrue($response->isGone(), 'Response is an error, but isGone() returned false');
$this->assertFalse($response->isOk(), 'Response is an error, but isOk() returned true');
$this->assertFalse($response->isServerError(), 'Response is an error, but isServerError() returned true');
$this->assertFalse($response->isRedirect(), 'Response is an error, but isRedirect() returned true');
Expand All @@ -216,6 +234,7 @@ public function test500isError()
$this->assertFalse($response->isForbidden(), 'Response is an error, but isForbidden() returned true');
$this->assertFalse($response->isInformational(), 'Response is an error, but isInformational() returned true');
$this->assertFalse($response->isNotFound(), 'Response is an error, but isNotFound() returned true');
$this->assertFalse($response->isGone(), 'Response is an error, but isGone() returned true');
$this->assertFalse($response->isOk(), 'Response is an error, but isOk() returned true');
$this->assertTrue($response->isServerError(), 'Response is an error, but isServerError() returned false');
$this->assertFalse($response->isRedirect(), 'Response is an error, but isRedirect() returned true');
Expand Down Expand Up @@ -245,6 +264,7 @@ public function test300isRedirect()
$this->assertFalse($response->isForbidden(), 'Response is an error, but isForbidden() returned true');
$this->assertFalse($response->isInformational(), 'Response is an error, but isInformational() returned true');
$this->assertFalse($response->isNotFound(), 'Response is an error, but isNotFound() returned true');
$this->assertFalse($response->isGone(), 'Response is an error, but isGone() returned true');
$this->assertFalse($response->isOk(), 'Response is an error, but isOk() returned true');
$this->assertFalse($response->isServerError(), 'Response is an error, but isServerError() returned true');
$this->assertTrue($response->isRedirect(), 'Response is an error, but isRedirect() returned false');
Expand All @@ -260,6 +280,7 @@ public function test200Ok()
$this->assertFalse($response->isForbidden(), 'Response is an error, but isForbidden() returned true');
$this->assertFalse($response->isInformational(), 'Response is an error, but isInformational() returned true');
$this->assertFalse($response->isNotFound(), 'Response is an error, but isNotFound() returned true');
$this->assertFalse($response->isGone(), 'Response is an error, but isGone() returned true');
$this->assertTrue($response->isOk(), 'Response is an error, but isOk() returned false');
$this->assertFalse($response->isServerError(), 'Response is an error, but isServerError() returned true');
$this->assertFalse($response->isRedirect(), 'Response is an error, but isRedirect() returned true');
Expand All @@ -283,6 +304,7 @@ public function testAutoMessageSet()
$this->assertTrue($response->isForbidden(), 'Response is an error, but isForbidden() returned false');
$this->assertFalse($response->isInformational(), 'Response is an error, but isInformational() returned true');
$this->assertFalse($response->isNotFound(), 'Response is an error, but isNotFound() returned true');
$this->assertFalse($response->isGone(), 'Response is an error, but isGone() returned true');
$this->assertFalse($response->isOk(), 'Response is an error, but isOk() returned true');
$this->assertFalse($response->isServerError(), 'Response is an error, but isServerError() returned true');
$this->assertFalse($response->isRedirect(), 'Response is an error, but isRedirect() returned true');
Expand Down
19 changes: 19 additions & 0 deletions test/_files/response_410
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
HTTP/1.1 410 Gone
Date: Fri, 17 Nov 2006 22:22:40 GMT
Server: Apache
Content-Length: 272
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>410 Gone</title>
</head><body>
<h1>Gone</h1>
<p>The requested resource /some/wrong/path is no longer available on
this server and there is no forwarding address. Please remove all
references to this resource.</p>
<hr>
<address>Apache Server at localhost Port 80</address>
</body></html>