14
14
import warnings
15
15
from http .client import responses
16
16
from logging import Logger
17
- from typing import TYPE_CHECKING , Any , Awaitable , Sequence , cast
17
+ from typing import TYPE_CHECKING , Any , Awaitable , Coroutine , Sequence , cast
18
18
from urllib .parse import urlparse
19
19
20
20
import prometheus_client
@@ -1016,14 +1016,14 @@ def compute_etag(self) -> str | None:
1016
1016
# access is allowed as this class is used to serve static assets on login page
1017
1017
# TODO: create an allow-list of files used on login page and remove this decorator
1018
1018
@allow_unauthenticated
1019
- def get (self , * args , ** kwargs ) -> None :
1020
- return super ().get (* args , ** kwargs )
1019
+ def get (self , path : str , include_body : bool = True ) -> Coroutine [ Any , Any , None ] :
1020
+ return super ().get (path , include_body )
1021
1021
1022
1022
# access is allowed as this class is used to serve static assets on login page
1023
1023
# TODO: create an allow-list of files used on login page and remove this decorator
1024
1024
@allow_unauthenticated
1025
- def head (self , * args , ** kwargs ) -> None :
1026
- return super ().head (* args , ** kwargs )
1025
+ def head (self , path : str ) -> Awaitable [ None ] :
1026
+ return super ().head (path )
1027
1027
1028
1028
@classmethod
1029
1029
def get_absolute_path (cls , roots : Sequence [str ], path : str ) -> str :
@@ -1072,7 +1072,7 @@ class TrailingSlashHandler(web.RequestHandler):
1072
1072
This should be the first, highest priority handler.
1073
1073
"""
1074
1074
1075
- # does not require ` allow_unauthenticated` (inherits from `web.RequestHandler`)
1075
+ @ allow_unauthenticated
1076
1076
def get (self ) -> None :
1077
1077
"""Handle trailing slashes in a get."""
1078
1078
assert self .request .uri is not None
@@ -1136,14 +1136,14 @@ async def get(self, path: str = "") -> None:
1136
1136
1137
1137
1138
1138
class RedirectWithParams (web .RequestHandler ):
1139
- """Sam as web.RedirectHandler, but preserves URL parameters"""
1139
+ """Same as web.RedirectHandler, but preserves URL parameters"""
1140
1140
1141
1141
def initialize (self , url : str , permanent : bool = True ) -> None :
1142
1142
"""Initialize a redirect handler."""
1143
1143
self ._url = url
1144
1144
self ._permanent = permanent
1145
1145
1146
- # does not require ` allow_unauthenticated` (inherits from `web.RequestHandler`)
1146
+ @ allow_unauthenticated
1147
1147
def get (self ) -> None :
1148
1148
"""Get a redirect."""
1149
1149
sep = "&" if "?" in self ._url else "?"
@@ -1166,6 +1166,18 @@ def get(self) -> None:
1166
1166
self .write (prometheus_client .generate_latest (prometheus_client .REGISTRY ))
1167
1167
1168
1168
1169
+ class PublicStaticFileHandler (web .StaticFileHandler ):
1170
+ """Same as web.StaticFileHandler, but decorated to acknowledge that auth is not required."""
1171
+
1172
+ @allow_unauthenticated
1173
+ def head (self , path : str ) -> Awaitable [None ]:
1174
+ return super ().head (path )
1175
+
1176
+ @allow_unauthenticated
1177
+ def get (self , path : str , include_body : bool = True ) -> Coroutine [Any , Any , None ]:
1178
+ return super ().get (path , include_body )
1179
+
1180
+
1169
1181
# -----------------------------------------------------------------------------
1170
1182
# URL pattern fragments for reuse
1171
1183
# -----------------------------------------------------------------------------
@@ -1181,6 +1193,6 @@ def get(self) -> None:
1181
1193
default_handlers = [
1182
1194
(r".*/" , TrailingSlashHandler ),
1183
1195
(r"api" , APIVersionHandler ),
1184
- (r"/(robots\.txt|favicon\.ico)" , web . StaticFileHandler ),
1196
+ (r"/(robots\.txt|favicon\.ico)" , PublicStaticFileHandler ),
1185
1197
(r"/metrics" , PrometheusMetricsHandler ),
1186
1198
]
0 commit comments