Skip to content

Commit ece34f1

Browse files
authored
Add notModified method to HTTP client (#48379)
1 parent 5f78beb commit ece34f1

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ public function found()
6565
return $this->status() === 302;
6666
}
6767

68+
/**
69+
* Determine if the response code was a 304 "Not Modified" response.
70+
*
71+
* @return bool
72+
*/
73+
public function notModified()
74+
{
75+
return $this->status() === 304;
76+
}
77+
6878
/**
6979
* Determine if the response was a 400 "Bad Request" response.
7080
*

tests/Http/HttpClientTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ protected function setUp(): void
5252
protected function tearDown(): void
5353
{
5454
m::close();
55+
56+
parent::tearDown();
5557
}
5658

5759
public function testStubbedResponsesAreReturnedAfterFaking()
@@ -133,6 +135,20 @@ public function testFoundRequest()
133135
$this->assertFalse($response->found());
134136
}
135137

138+
public function testNotModifiedRequest(): void
139+
{
140+
$this->factory->fake([
141+
'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_NOT_MODIFIED),
142+
'forge.laravel.com' => $this->factory::response('', HttpResponse::HTTP_OK),
143+
]);
144+
145+
$response = $this->factory->post('https://vapor.laravel.com');
146+
$this->assertTrue($response->notModified());
147+
148+
$response = $this->factory->post('https://forge.laravel.com');
149+
$this->assertFalse($response->notModified());
150+
}
151+
136152
public function testBadRequestRequest()
137153
{
138154
$this->factory->fake([

0 commit comments

Comments
 (0)