CaseInsensitiveQueryMiddleware¶
- class safir.middleware.ivoa.CaseInsensitiveQueryMiddleware(app: Callable[[MutableMapping[str, Any], Callable[[], Awaitable[MutableMapping[str, Any]]], Callable[[MutableMapping[str, Any]], Awaitable[None]]], Awaitable[None]], dispatch: Optional[Callable[[Request, Callable[[Request], Awaitable[Response]]], Awaitable[Response]]] = None)¶
Bases:
BaseHTTPMiddleware
Make query parameter keys all lowercase.
Unfortunately, several IVOA standards require that query parameters be case-insensitive, which is not supported by modern HTTP web frameworks. This middleware attempts to work around this by lowercasing the query parameter keys before the request is processed, allowing normal FastAPI query parsing to then work without regard for case. This, in turn, permits FastAPI to perform input validation on GET parameters, which would otherwise only happen if the case used in the request happened to match the case used in the function signature.
This unfortunately doesn’t handle POST, so routes that accept POST will need to parse the POST data case-insensitively in the handler or a dependency.
Based on fastapi#826.
Methods Summary
dispatch
(request, call_next)Methods Documentation