Example #1
0
def test_access_log_header_atoms(request_scope: dict, response: dict) -> None:
    atoms = AccessLogAtoms(request_scope, response, 0)
    assert atoms["{X-Hypercorn}i"] == "Hypercorn"
    assert atoms["{X-HYPERCORN}i"] == "Hypercorn"
    assert atoms["{not-atom}i"] == "-"
    assert atoms["{X-Hypercorn}o"] == "Hypercorn"
    assert atoms["{X-HYPERCORN}o"] == "Hypercorn"
Example #2
0
def test_access_log_header_atoms(request: dict, response: dict) -> None:
    atoms = AccessLogAtoms(request, response, 0)
    assert atoms['{X-Hypercorn}i'] == 'Hypercorn'
    assert atoms['{X-HYPERCORN}i'] == 'Hypercorn'
    assert atoms['{not-atom}i'] == '-'
    assert atoms['{X-Hypercorn}o'] == 'Hypercorn'
    assert atoms['{X-HYPERCORN}o'] == 'Hypercorn'
Example #3
0
def test_access_log_header_atoms(http_scope: HTTPScope, response: ResponseSummary) -> None:
    atoms = AccessLogAtoms(http_scope, response, 0)
    assert atoms["{X-Hypercorn}i"] == "Hypercorn"
    assert atoms["{X-HYPERCORN}i"] == "Hypercorn"
    assert atoms["{not-atom}i"] == "-"
    assert atoms["{X-Hypercorn}o"] == "Hypercorn"
    assert atoms["{X-HYPERCORN}o"] == "Hypercorn"
Example #4
0
def test_access_log_standard_atoms(request: dict, response: dict) -> None:
    atoms = AccessLogAtoms(request, response, 0.000023)
    assert atoms['h'] == '127.0.0.1'
    assert atoms['l'] == '-'
    assert time.strptime(atoms['t'], '[%d/%b/%Y:%H:%M:%S %z]')
    assert int(atoms['s']) == 200
    assert atoms['m'] == 'GET'
    assert atoms['U'] == '/'
    assert atoms['q'] == 'a=b'
    assert atoms['H'] == '2'
    assert int(atoms['b']) == 5
    assert int(atoms['B']) == 5
    assert atoms['f'] == 'hypercorn'
    assert atoms['a'] == 'Hypercorn'
    assert atoms['p'] == f"<{os.getpid()}>"
    assert atoms['not-atom'] == '-'
    assert atoms['T'] == 0
    assert atoms['D'] == 23
    assert atoms['L'] == '0.000023'
Example #5
0
    def info(self, message: str, data: AccessLogAtoms) -> None:

        if data["U"] in {"/health", "/health/"}:
            return

        request_id = data.get("x-request-id", "")

        method = data.get("m")
        duration = data.get("D")
        data = {
            "method": method,
            "status": data.get("s"),
            "path": data.get("U"),
            "query": data.get("q"),
            "duration": duration,
            "request_id": request_id,
        }

        self.logger.info(f'{data["method"]} {data["path"]} - {data["status"]}',
                         extra=data)
Example #6
0
def test_access_log_environ_atoms(request: dict, response: dict) -> None:
    os.environ['Random'] = 'Environ'
    atoms = AccessLogAtoms(request, response, 0)
    assert atoms['{random}e'] == 'Environ'
Example #7
0
def test_access_no_log_header_atoms(request_scope: dict) -> None:
    atoms = AccessLogAtoms(request_scope, {"status": 200}, 0)
    assert atoms["{X-Hypercorn}i"] == "Hypercorn"
    assert atoms["{X-HYPERCORN}i"] == "Hypercorn"
    assert atoms["{not-atom}i"] == "-"
    assert not any(key.startswith("{") and key.endswith("}o") for key in atoms.keys())
Example #8
0
def test_access_log_environ_atoms(request_scope: dict, response: dict) -> None:
    os.environ["Random"] = "Environ"
    atoms = AccessLogAtoms(request_scope, response, 0)
    assert atoms["{random}e"] == "Environ"
Example #9
0
def test_nonstandard_status_code(http_scope: HTTPScope) -> None:
    atoms = AccessLogAtoms(http_scope, {"status": 441, "headers": []}, 0)
    assert atoms["st"] == "<???441???>"
Example #10
0
def test_access_log_environ_atoms(http_scope: HTTPScope, response: ResponseSummary) -> None:
    os.environ["Random"] = "Environ"
    atoms = AccessLogAtoms(http_scope, response, 0)
    assert atoms["{random}e"] == "Environ"