Form Content-Type parameters cause requests to fail with HTTP 500
🐛 Bug
Form clients that add a charset parameter to Content-Type receive HTTP 500 instead of reaching decode_request. The same body succeeds when the parameter is removed.
On current main 68c4943, BaseRequestHandler._prepare_request compares the entire header with application/x-www-form-urlencoded, so a parameterized header falls through to request.json() and raises JSONDecodeError. Starlette's Request.form() parses that same request successfully.
To Reproduce
Local CPU reproduction; no Lightning Studio or external model required.
from fastapi.testclient import TestClient
from litserve import LitAPI, LitServer
from litserve.utils import wrap_litserve_start
class FormAPI(LitAPI):
def setup(self, device):
pass
def decode_request(self, request):
return float(request["input"])
def predict(self, x):
return x * x
def encode_response(self, output):
return {"output": output}
if __name__ == "__main__":
server = LitServer(FormAPI(), accelerator="cpu", devices=1)
with wrap_litserve_start(server), TestClient(
server.app, raise_server_exceptions=False
) as client:
for content_type in (
"application/x-www-form-urlencoded",
"application/x-www-form-urlencoded; charset=UTF-8",
):
response = client.post(
"/predict", content="input=4",
headers={"Content-Type": content_type},
)
print(content_type, response.status_code, response.text)
Actual: the first request returns 200 / {"output":16.0}; the second returns 500 / {"detail":"Internal server error"}.
Expected behavior
Both requests should use the form parser. Routing should compare the media type independently of its parameters and casing, while leaving the original header intact for multipart boundaries and decoding. See RFC 9110 §8.3.1.
Environment
- LitServe 0.2.20, editable install at
68c4943 - Python 3.11.15, macOS arm64, CPU / native ZeroMQ transport
- FastAPI 0.162.4, Starlette 1.10.0, python-multipart 0.0.33
- No Torch, GPU or provider calls required
Additional context
This is a focused form-routing bug, separate from the raw binary-body API in #732 / #763. Closed #733 contained media-type normalization alongside broader binary-body behavior; #763's inspected patch leaves the form comparison unchanged. A focused implementation is proposed in PR #802.
Investigated and reproduced with Codex on behalf of austinchennn; no independent human technical review is claimed.
Implementation and acceptance evidence
Proposed implementation: https://github.com/Lightning-AI/LitServe/pull/802 (submitted, not merged).
- [x] Parameterized and mixed-case URL-encoded form requests reach the form parser: real HTTP/CPU worker regression with both native ZeroMQ and multiprocessing queues.
- [x] Mixed-case multipart media type works without changing the case-sensitive boundary value.
- [x] Existing JSON/default, typed/Pydantic, schema and upload checks pass.
- [x] Original-source subset: 7 failed / 10 passed; after fix: 22 passed / 2 existing warnings. Applicable pre-commit hooks and git diff --check pass.
- [ ] Maintainer review and merge.