INNER CODE UNIT · Python
_SecurityHeadersMiddleware
MakazhanAlpamys/Soup · src/soup_cli/ui/app.py:138
class _SecurityHeadersMiddleware:
"""Add the response headers in ``SECURITY_HEADERS`` to every HTTP response.
Pure ASGI: it rewrites only the ``http.response.start`` message and forwards
every body message as it arrives, so streamed responses (the training log
event stream) are not buffered. A header the endpoint already set is kept.
"""
def __init__(
self,
app,
headers: Mapping[str, str] = SECURITY_HEADERS,
policy_exempt_paths: frozenset = frozenset(),
) -> None:
self._app = app
self._headers = tuple(
(name.lower().encode("latin-1"), value.encode("latin-1"))
for name, value in headers.items()