mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-24 06:24:18 +02:00
Normalize media type for dispatch, use OpenAPI serialization for cookies
- Strip content-type parameters (e.g. "; charset=utf-8") and lowercase
before matching, so variants like "Multipart/Form-Data" match correctly
- Use _query_scalar_to_str for cookie values (true/false not True/False)
- Add boolean cookie test
🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ea1439a009
commit
ba8db8ccc3
2 changed files with 22 additions and 8 deletions
|
|
@ -75,14 +75,19 @@ class RequestDirector:
|
|||
json_body: dict[str, Any] | list[Any] | None = None
|
||||
content: str | bytes | None = None
|
||||
|
||||
# Step 5: Determine the declared content type from the OpenAPI spec
|
||||
# Step 5: Determine the declared content type from the OpenAPI spec.
|
||||
# Strip parameters (e.g. "; charset=utf-8") for dispatch matching.
|
||||
declared_content_type: str | None = None
|
||||
if route.request_body and route.request_body.content_schema:
|
||||
declared_content_type = next(iter(route.request_body.content_schema))
|
||||
raw_ct = next(iter(route.request_body.content_schema))
|
||||
declared_content_type = raw_ct.split(";")[0].strip().lower()
|
||||
|
||||
# httpx requires cookie values to be strings
|
||||
# httpx requires cookie values to be strings; use OpenAPI-style
|
||||
# serialization (e.g. true/false for booleans, not True/False)
|
||||
cookies = (
|
||||
{k: str(v) for k, v in cookie_params.items()} if cookie_params else None
|
||||
{k: _query_scalar_to_str(v) for k, v in cookie_params.items()}
|
||||
if cookie_params
|
||||
else None
|
||||
)
|
||||
|
||||
# Step 6: Handle request body — dispatch on declared content type.
|
||||
|
|
|
|||
|
|
@ -1403,7 +1403,7 @@ class TestCookieParameters:
|
|||
assert "xyz789" in request.headers.get("cookie", "")
|
||||
|
||||
def test_cookie_non_string_value_stringified(self, director):
|
||||
"""Non-string cookie values (e.g. int) must be stringified for httpx."""
|
||||
"""Non-string cookie values (e.g. int, bool) use OpenAPI serialization."""
|
||||
route = HTTPRoute(
|
||||
path="/api",
|
||||
method="GET",
|
||||
|
|
@ -1415,11 +1415,20 @@ class TestCookieParameters:
|
|||
required=True,
|
||||
schema={"type": "integer"},
|
||||
),
|
||||
ParameterInfo(
|
||||
name="debug",
|
||||
location="cookie",
|
||||
required=False,
|
||||
schema={"type": "boolean"},
|
||||
),
|
||||
],
|
||||
parameter_map={
|
||||
"version": {"location": "cookie", "openapi_name": "version"},
|
||||
"debug": {"location": "cookie", "openapi_name": "debug"},
|
||||
},
|
||||
)
|
||||
request = director.build(route, {"version": 3})
|
||||
assert "version" in request.headers.get("cookie", "")
|
||||
assert "3" in request.headers.get("cookie", "")
|
||||
request = director.build(route, {"version": 3, "debug": True})
|
||||
cookie = request.headers.get("cookie", "")
|
||||
assert "version=3" in cookie
|
||||
# Booleans use OpenAPI convention (true/false, not True/False)
|
||||
assert "debug=true" in cookie
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue