<commit_before><?php

use Aerys\{ Host, Request, Response, Router, function root };

/* --- Global server options -------------------------------------------------------------------- */

const AERYS_OPTIONS = [
    "keepAliveTimeout" => 60,
    "deflateMinimumLength" => 0,
];

/* --- http://localhost:1337/ ------------------------------------------------------------------- */

$router = (new Router)
    ->get("/", function(Request $req, Response $res) {
        $res->send("<html><body><h1>Hello, world.</h1></body></html>");
    })
    ->post("/", function(Request $req, Response $res) {
        $res->send("<html><body><h1>Hello, world (POST).</h1></body></html>");
    })
    ->get("error1", function(Request $req, Response $res) {
        // ^ the router normalizes the leading forward slash in your URIs
        $nonexistent->methodCall();
    })
    ->get("/error2", function(Request $req, Response $res) {
        throw new Exception("wooooooooo!");
    })
    ->get("/directory/?", function(Request $req, Response $res) {
        // The trailing "/?" in the URI allows this route to match /directory OR /directory/
        $res->send("<html><body><h1>Dual directory match</h1></body></html>");
    })
    ->get("/long-poll", function(Request $req, Response $res) {
        while (true) {
            $res->stream("hello!<br/>")->flush();
            yield new Amp\Pause(1000);
        }
    })
    ->post("/body1", function(Request $req, Response $res) {
        $body = yield $req->body;
        $res->send("<html><body><h1>Buffer Body Echo:</h1><pre>{$body}</pre></body></html>");
    })
    ->post("/body2", function(Request $req, Response $res) {
        $body = "";
        foreach ($req->body->stream() as $bodyPart) {
            $body .= yield $bodyPart;
        }
        $res->send("<html><body><h1>Stream Body Echo:</h1><pre>{$body}</pre></body></html>");
    })
;

// If none of our routes match try to serve a static file
$root = root($docrootPath = __DIR__);

// If no static files match fallback to this
$fallback = function(Request $req, Response $res) {
    $res->send("<html><body><h1>Fallback \o/</h1></body></html>");<commit_msg>My favicon.ico brings all the boys to the yard<commit_after><?php

use Aerys\{ Host, Request, Response, Router, function root };

/* --- Global server options -------------------------------------------------------------------- */

const AERYS_OPTIONS = [
    "keepAliveTimeout" => 60,
    "deflateMinimumLength" => 0,
];

/* --- http://localhost:1337/ ------------------------------------------------------------------- */

$router = (new Router)
    ->get("/", function(Request $req, Response $res) {
        $res->send("<html><body><h1>Hello, world.</h1></body></html>");
    })
    ->post("/", function(Request $req, Response $res) {
        $res->send("<html><body><h1>Hello, world (POST).</h1></body></html>");
    })
    ->get("error1", function(Request $req, Response $res) {
        // ^ the router normalizes the leading forward slash in your URIs
        $nonexistent->methodCall();
    })
    ->get("/error2", function(Request $req, Response $res) {
        throw new Exception("wooooooooo!");
    })
    ->get("/directory/?", function(Request $req, Response $res) {
        // The trailing "/?" in the URI allows this route to match /directory OR /directory/
        $res->send("<html><body><h1>Dual directory match</h1></body></html>");
    })
    ->get("/long-poll", function(Request $req, Response $res) {
        while (true) {
            $res->stream("hello!<br/>")->flush();
            yield new Amp\Pause(1000);
        }
    })
    ->post("/body1", function(Request $req, Response $res) {
        $body = yield $req->body;
        $res->send("<html><body><h1>Buffer Body Echo:</h1><pre>{$body}</pre></body></html>");
    })
    ->post("/body2", function(Request $req, Response $res) {
        $body = "";
        foreach ($req->body->stream() as $bodyPart) {
            $body .= yield $bodyPart;
        }
        $res->send("<html><body><h1>Stream Body Echo:</h1><pre>{$body}</pre></body></html>");
    })
    ->get("/favicon.ico", function(Request $req, Response $res) {
        $res->setStatus(404);
        $res->setHeader("Aerys-Generic-Response", "enable");
        $res->end();
    })
;

// If none of our routes match try to serve a static file
$root = root($docrootPath = __DIR__);

// If no static files match fallback to this
$fallback = function(Request $req, Response $res) {
    $res->send("<html><body><h1>Fallback \o/</h1></body></html>");
{'fraction_non_alphanumeric': 0.25903083700440527, 'fraction_numerical': 0.012555066079295154, 'mean_word_length': 2.312180889861415, 'pattern_counts': {'":': 0, '<': 87, '<?xml version=': 0, '>': 133, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '5744893', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1361, 'n_words': 316}