diff --git a/CHANGES.md b/CHANGES.md index f90e9790..f6593d9e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/src/titiler/core/titiler/core/middleware.py b/src/titiler/core/titiler/core/middleware.py index 0d19eb68..821d7491 100644 --- a/src/titiler/core/titiler/core/middleware.py +++ b/src/titiler/core/titiler/core/middleware.py @@ -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 @@ -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)