Skip to content

Commit

Permalink
HH-199730 little speed-up for set_status
Browse files Browse the repository at this point in the history
  • Loading branch information
bokshitsky committed Nov 25, 2023
1 parent 2bcaf24 commit 5a0d4cb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
6 changes: 1 addition & 5 deletions frontik/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
from frontik.integrations.statsd import StatsDClient, StatsDClientStub


def _fallback_status_code(status_code: int) -> int:
return status_code if status_code in ALLOWED_STATUSES else http.client.SERVICE_UNAVAILABLE


class FinishWithPostprocessors(Exception):
def __init__(self, wait_finish_group: bool = False) -> None:
self.wait_finish_group = wait_finish_group
Expand Down Expand Up @@ -292,7 +288,7 @@ def _get_request_mime_type(self, request: HTTPServerRequest) -> str:
return re.split(MEDIA_TYPE_PARAMETERS_SEPARATOR_RE, content_type)[0]

def set_status(self, status_code: int, reason: str | None = None) -> None:
status_code = _fallback_status_code(status_code)
status_code = status_code if status_code in ALLOWED_STATUSES else http.client.SERVICE_UNAVAILABLE
super().set_status(status_code, reason=reason)

def redirect(self, url, *args, allow_protocol_relative=False, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion frontik/http_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

CLIENT_CLOSED_REQUEST = 499
NON_CRITICAL_BAD_GATEWAY = 569
ALLOWED_STATUSES = [*list(http.client.responses.keys()), CLIENT_CLOSED_REQUEST, NON_CRITICAL_BAD_GATEWAY]
ALLOWED_STATUSES = {*http.client.responses.keys(), CLIENT_CLOSED_REQUEST, NON_CRITICAL_BAD_GATEWAY}

0 comments on commit 5a0d4cb

Please sign in to comment.