Skip to content

Commit

Permalink
optimize unquote
Browse files Browse the repository at this point in the history
  • Loading branch information
nggit committed Dec 8, 2023
1 parent 198758d commit 14d60ef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
7 changes: 4 additions & 3 deletions tremolo/asgi_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio

from http import HTTPStatus
from urllib.parse import unquote
from urllib.parse import unquote_to_bytes

from .exceptions import (
InternalServerError,
Expand Down Expand Up @@ -63,8 +63,9 @@ async def _handle_http(self):
async def headers_received(self):
self._scope = {
'asgi': {'version': '3.0'},
'http_version': self.request.version.decode('utf-8'),
'path': unquote(self.request.path.decode('utf-8'), 'utf-8'),
'http_version': self.request.version.decode('latin-1'),
'path': unquote_to_bytes(
bytes(self.request.path)).decode('latin-1'),
'raw_path': self.request.path,
'query_string': self.request.query_string,
'root_path': self.options['_root_path'],
Expand Down
5 changes: 2 additions & 3 deletions tremolo/lib/http_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import asyncio

from urllib.parse import quote, unquote
from urllib.parse import quote_from_bytes, unquote_to_bytes

from .h1parser import ParseHeader
from .http_exception import (
Expand Down Expand Up @@ -181,8 +181,7 @@ async def handle_exception(self, exc):
return

self.print_exception(
exc,
quote(unquote(self.request.path.decode('latin-1')))
exc, quote_from_bytes(unquote_to_bytes(bytes(self.request.path)))
)

if isinstance(exc, WebSocketException):
Expand Down

0 comments on commit 14d60ef

Please sign in to comment.