Skip to content

Commit ba80e04

Browse files
committed
prettified and added max-age=0
1 parent f06febd commit ba80e04

File tree

3 files changed

+27
-29
lines changed

3 files changed

+27
-29
lines changed

flight/net/Response.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public function cache($expires): self
288288
{
289289
if ($expires === false) {
290290
$this->headers['Expires'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
291-
$this->headers['Cache-Control'] = 'no-store, no-cache, must-revalidate';
291+
$this->headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
292292
$this->headers['Pragma'] = 'no-cache';
293293
} else {
294294
$expires = \is_int($expires) ? $expires : strtotime($expires);
@@ -432,11 +432,10 @@ public function send(): void
432432
}
433433

434434
if ($this->headersSent() === false) {
435-
436-
// If you haven't set a Cache-Control header, we'll assume you don't want caching
437-
if($this->getHeader('Cache-Control') === null) {
438-
$this->cache(false);
439-
}
435+
// If you haven't set a Cache-Control header, we'll assume you don't want caching
436+
if ($this->getHeader('Cache-Control') === null) {
437+
$this->cache(false);
438+
}
440439

441440
$this->sendHeaders();
442441
}
@@ -446,16 +445,16 @@ public function send(): void
446445
$this->sent = true;
447446
}
448447

449-
/**
450-
* Headers have been sent
451-
*
452-
* @return bool
453-
* @codeCoverageIgnore
454-
*/
455-
public function headersSent(): bool
456-
{
457-
return headers_sent();
458-
}
448+
/**
449+
* Headers have been sent
450+
*
451+
* @return bool
452+
* @codeCoverageIgnore
453+
*/
454+
public function headersSent(): bool
455+
{
456+
return headers_sent();
457+
}
459458

460459
/**
461460
* Adds a callback to process the response body before it's sent. These are processed in the order

tests/FlightTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,7 @@ public function testDoesNotPreserveVarsWhenFlagIsDisabled(
361361
string $output,
362362
array $renderParams,
363363
string $regexp
364-
): void
365-
{
364+
): void {
366365
Flight::view()->preserveVars = false;
367366

368367
$this->expectOutputString($output);

tests/ResponseTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function testCacheFalseExpiresValue()
164164
$response->cache(false);
165165
$this->assertEquals([
166166
'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT',
167-
'Cache-Control' => 'no-store, no-cache, must-revalidate',
167+
'Cache-Control' => 'no-store, no-cache, must-revalidate, max-age=0',
168168
'Pragma' => 'no-cache'
169169
], $response->headers());
170170
}
@@ -235,8 +235,8 @@ public function setRealHeader(string $header_string, bool $replace = true, int $
235235
$this->assertTrue($response->sent());
236236
}
237237

238-
public function testSendWithNoHeadersSent()
239-
{
238+
public function testSendWithNoHeadersSent()
239+
{
240240
$response = new class extends Response {
241241
protected $test_sent_headers = [];
242242

@@ -251,26 +251,26 @@ public function getSentHeaders(): array
251251
return $this->test_sent_headers;
252252
}
253253

254-
public function headersSent(): bool
255-
{
256-
return false;
257-
}
254+
public function headersSent(): bool
255+
{
256+
return false;
257+
}
258258
};
259259
$response->header('Content-Type', 'text/html');
260260
$response->header('X-Test', 'test');
261261
$response->write('Something');
262262

263-
$this->expectOutputString('Something');
263+
$this->expectOutputString('Something');
264264

265265
$response->send();
266266
$sent_headers = $response->getSentHeaders();
267267
$this->assertEquals([
268268
'HTTP/1.1 200 OK',
269269
'Content-Type: text/html',
270270
'X-Test: test',
271-
'Expires: Mon, 26 Jul 1997 05:00:00 GMT',
272-
'Cache-Control: no-store, no-cache, must-revalidate',
273-
'Pragma: no-cache',
271+
'Expires: Mon, 26 Jul 1997 05:00:00 GMT',
272+
'Cache-Control: no-store, no-cache, must-revalidate, max-age=0',
273+
'Pragma: no-cache',
274274
'Content-Length: 9'
275275
], $sent_headers);
276276
}

0 commit comments

Comments
 (0)