from asyncio import Future # noqa: F401
import unittest # noqa: F401
+ # This can be done unconditionally in the base class of HTTPHeaders
+ # after we drop support for Python 3.8.
+ StrMutableMapping = collections.abc.MutableMapping[str, str]
+else:
+ StrMutableMapping = collections.abc.MutableMapping
+
# To be used with str.strip() and related methods.
HTTP_WHITESPACE = " \t"
return "-".join([w.capitalize() for w in name.split("-")])
-class HTTPHeaders(collections.abc.MutableMapping):
+class HTTPHeaders(StrMutableMapping):
"""A dictionary that maintains ``Http-Header-Case`` for all keys.
Supports multiple values per key via a pair of new methods,
# information please see
# http://www.djangoproject.com/weblog/2011/feb/08/security/
# http://weblog.rubyonrails.org/2011/2/8/csrf-protection-bypass-in-ruby-on-rails
- token = (
+ input_token = (
self.get_argument("_xsrf", None)
or self.request.headers.get("X-Xsrftoken")
or self.request.headers.get("X-Csrftoken")
)
- if not token:
+ if not input_token:
raise HTTPError(403, "'_xsrf' argument missing from POST")
- _, token, _ = self._decode_xsrf_token(token)
+ _, token, _ = self._decode_xsrf_token(input_token)
_, expected_token, _ = self._get_raw_xsrf_token()
if not token:
raise HTTPError(403, "'_xsrf' argument has invalid format")
{
"Upgrade": "websocket",
"Connection": "Upgrade",
- "Sec-WebSocket-Key": self.key,
+ "Sec-WebSocket-Key": to_unicode(self.key),
"Sec-WebSocket-Version": "13",
}
)