Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case insensitive query parameters #321

Merged
merged 10 commits into from
Jun 11, 2021
3 changes: 3 additions & 0 deletions titiler/application/titiler/application/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
CacheControlMiddleware,
LoggerMiddleware,
TotalTimeMiddleware,
CaseInsensitiveMiddleware
)
from titiler.application.routers import cog, mosaic, stac, tms
from titiler.application.settings import ApiSettings
Expand Down Expand Up @@ -67,6 +68,8 @@
exclude_path={r"/healthz"},
)

app.add_middleware(CaseInsensitiveMiddleware)
lorenzori marked this conversation as resolved.
Show resolved Hide resolved

if api_settings.debug:
app.add_middleware(LoggerMiddleware, headers=True, querystrings=True)
app.add_middleware(TotalTimeMiddleware)
Expand Down
15 changes: 15 additions & 0 deletions titiler/application/titiler/application/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,18 @@ async def dispatch(self, request: Request, call_next):

response = await call_next(request)
return response


class CaseInsensitiveMiddleware(BaseHTTPMiddleware):
lorenzori marked this conversation as resolved.
Show resolved Hide resolved
"""Middleware to make URL parameters case-insensitive.
taken from: https://github.com/tiangolo/fastapi/issues/826
"""

async def dispatch(self, request: Request, call_next):
self.DECODE_FORMAT = "latin-1"

raw = request.scope["query_string"].decode(self.DECODE_FORMAT).lower()
request.scope["query_string"] = raw.encode(self.DECODE_FORMAT)

response = await call_next(request)
return response