<commit_before><?php

class CspReport
{
    public function process($post)
    {
        $report = json_decode($post);

        if ($report) {
            $report->{'user-agent'} = $_SERVER['HTTP_USER_AGENT'];

            $data = json_encode(
                $report,
                JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
            );

            $this->log($data);
        }
    }

    private function log($data)
    {
        $logfile = dirname(__DIR__) . '/csp-report.log';
        file_put_contents($logfile, $data . "\n", LOCK_EX | FILE_APPEND);
    }
}
<commit_msg>Add date and request headers in CSP report log<commit_after><?php

class CspReport
{
    public function process($post)
    {
        $report = json_decode($post);

        if ($report) {
            $report->date = date("Y-m-d H:i:s");

            foreach (getallheaders() as $name => $value) {
                $report->headers[$name] = $value;
            }

            $data = json_encode(
                $report,
                JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
            );

            $this->log($data);
        }
    }

    private function log($data)
    {
        $logfile = dirname(__DIR__) . '/csp-report.log';
        file_put_contents($logfile, $data . "\n", LOCK_EX | FILE_APPEND);
    }
}

{'fraction_non_alphanumeric': 0.13758647194465795, 'fraction_numerical': 0.0, 'mean_word_length': 1.7584745762711864, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5065800', 'n_tokens_mistral': 425, 'n_tokens_neox': 408, 'n_words': 74}