Skip to content

Commit c514cf1

Browse files
committed
Capture status code and header
1 parent a600e4c commit c514cf1

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/drop-in/advanced-cache.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,35 @@
1212
*/
1313

1414
class StaticDeployPageCache {
15+
private int $status_code;
16+
private string $status_header;
17+
1518
public function capture_response(): void {
19+
add_filter(
20+
'status_header',
21+
[ $this, 'filter_status_header' ],
22+
10,
23+
2
24+
);
1625

1726
$buffering = ob_start( [ $this, 'receive_output' ] );
1827
if ( $buffering === false ) {
1928
error_log( 'Output buffering failed' );
2029
}
2130
}
2231

32+
/*
33+
* https://developer.wordpress.org/reference/hooks/status_header/
34+
*/
35+
public function filter_status_header(
36+
string $status_header,
37+
int $code
38+
): string {
39+
$this->status_code = $code;
40+
$this->status_header = $status_header;
41+
return $status_header;
42+
}
43+
2344
/**
2445
* Receives the PHP output, which should be the body
2546
* of an HTTP response, and caches it.

0 commit comments

Comments
 (0)