-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
292 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Mapping | ||
|
||
from tornado import httputil | ||
from tornado.httputil import HTTPHeaders | ||
|
||
from frontik import request_context | ||
from frontik.version import version as frontik_version | ||
|
||
|
||
class FrontikResponse: | ||
def __init__( | ||
self, | ||
status_code: int, | ||
headers: dict[str, str] | None | HTTPHeaders = None, | ||
body: bytes = b'', | ||
): | ||
self.headers = HTTPHeaders(get_default_headers()) # type: ignore | ||
if headers is not None: | ||
self.headers.update(headers) | ||
self.status_code = status_code | ||
self.body = body | ||
self.data_written = False | ||
|
||
@property | ||
def reason(self) -> str: | ||
return httputil.responses.get(self.status_code, 'Unknown') | ||
|
||
|
||
def get_default_headers() -> Mapping[str, str | None]: | ||
request_id = request_context.get_request_id() or '' | ||
return { | ||
'Server': f'Frontik/{frontik_version}', | ||
'X-Request-Id': request_id, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.