1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
<?php declare(strict_types = 1); /** * Abstract output class for HTTP headers. * * @package query-monitor */
abstract class QM_Output_Headers extends QM_Output {
/** * @return void */ public function output() {
$id = $this->collector->id;
foreach ( $this->get_output() as $key => $value ) { if ( ! is_scalar( $value ) ) { $value = json_encode( $value ); }
# Remove illegal characters (Header value may not contain NUL bytes) if ( is_string( $value ) ) { $value = str_replace( chr( 0 ), '', $value ); }
# Remove illegal characters (Header name may not contain underscores) $key = str_replace( '_', '-', $key );
header( sprintf( 'X-QM-%s-%s: %s', $id, $key, $value ) ); }
}
}
|