diff --git a/CHANGES/12321.misc.rst b/CHANGES/12321.misc.rst new file mode 100644 index 00000000000..71f9db77675 --- /dev/null +++ b/CHANGES/12321.misc.rst @@ -0,0 +1,2 @@ +Added ``cdef`` type declarations and inlined the upgrade check in the HTTP parser +-- by :user:`bdraco`. diff --git a/aiohttp/_http_parser.pyx b/aiohttp/_http_parser.pyx index 9a444be66fc..932baa661f2 100644 --- a/aiohttp/_http_parser.pyx +++ b/aiohttp/_http_parser.pyx @@ -446,6 +446,9 @@ cdef class HttpParser: self._has_value = True cdef _on_headers_complete(self): + cdef str h_upg + cdef str enc + self._process_header() should_close = not cparser.llhttp_should_keep_alive(self._cparser) @@ -457,8 +460,7 @@ cdef class HttpParser: if self._cparser.type == cparser.HTTP_REQUEST: h_upg = headers.get("upgrade", "") - allowed = upgrade and h_upg.isascii() and h_upg.lower() in ALLOWED_UPGRADES - if allowed or self._cparser.method == cparser.HTTP_CONNECT: + if (upgrade and h_upg.isascii() and h_upg.lower() in ALLOWED_UPGRADES) or self._cparser.method == cparser.HTTP_CONNECT: self._upgraded = True else: if upgrade and self._cparser.status_code == 101: