Skip to content

Commit

Permalink
improve query string handling in LowerCaseQueryStringMiddleware using…
Browse files Browse the repository at this point in the history
… urlencode (#1050)

* improve query string handling in LowerCaseQueryStringMiddleware using urlencode

* fix import order

* update changelog

---------

Co-authored-by: vincentsarago <[email protected]>
  • Loading branch information
pratapvardhan and vincentsarago authored Dec 19, 2024
1 parent e54935e commit 9063d4c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### titiler.core

* Add layer control to map viewer template (author @hrodmn, https://github.com/developmentseed/titiler/pull/1051)
* improve query string handling in LowerCaseQueryStringMiddleware using urlencode (author @pratapvardhan, https://github.com/developmentseed/titiler/pull/1050)

### titiler.application

Expand Down
13 changes: 5 additions & 8 deletions src/titiler/core/titiler/core/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import logging
import re
import time
import urllib.parse
from typing import Optional, Set
from urllib.parse import urlencode

from fastapi.logger import logger
from starlette.datastructures import MutableHeaders
Expand Down Expand Up @@ -156,14 +156,11 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send):
"""Handle call."""
if scope["type"] == "http":
request = Request(scope)

DECODE_FORMAT = "latin-1"

query_string = ""
for k, v in request.query_params.multi_items():
query_string += k.lower() + "=" + urllib.parse.quote(v) + "&"

query_string = query_string[:-1]
query_items = [
(k.lower(), v) for k, v in request.query_params.multi_items()
]
query_string = urlencode(query_items, doseq=True)
request.scope["query_string"] = query_string.encode(DECODE_FORMAT)

await self.app(scope, receive, send)

0 comments on commit 9063d4c

Please sign in to comment.