-
Notifications
You must be signed in to change notification settings - Fork 9
Ignore content type parameters when matching it #235
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -213,7 +213,7 @@ async def __call__( | |
| codec_name = protocol.codec_name_from_content_type( | ||
| headers.get("content-type", ""), stream=not is_unary | ||
| ) | ||
| codec = self._codecs.get(codec_name.lower()) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also noticed a couple of spots of random lowercasing and consolidated them, with some cleanup to WSGI |
||
| codec = self._codecs.get(codec_name) | ||
| if not codec: | ||
| raise HTTPException( | ||
| HTTPStatus.UNSUPPORTED_MEDIA_TYPE, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
| from pyqwest import Client, SyncClient | ||
| from pyqwest.testing import ASGITransport, WSGITransport | ||
|
|
||
| from .haberdasher_connect import ( | ||
| Haberdasher, | ||
| HaberdasherASGIApplication, | ||
| HaberdasherSync, | ||
| HaberdasherWSGIApplication, | ||
| ) | ||
| from .haberdasher_pb2 import Hat | ||
|
|
||
| _charset_content_type_cases = [ | ||
| "application/json", | ||
| "application/json; charset=utf-8", | ||
| "application/json; charset=UTF-8", | ||
| "application/json;charset=utf-8", | ||
| "application/json; charset=utf-8", | ||
| "application/json; charset=utf-8; version=1", | ||
| "application/JSON", | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("header", _charset_content_type_cases) | ||
| def test_json_charset_content_type(header: str) -> None: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it also be good to flex streaming in these tests? I see we have |
||
| class HeadersHaberdasherSync(HaberdasherSync): | ||
| def make_hat(self, request, ctx): | ||
| return Hat(size=2) | ||
|
|
||
| transport = WSGITransport(HaberdasherWSGIApplication(HeadersHaberdasherSync())) | ||
|
|
||
| client = SyncClient(transport=transport) | ||
|
|
||
| res = client.post( | ||
| "http://localhost/connectrpc.example.Haberdasher/MakeHat", | ||
| content=b"{}", | ||
| headers={"content-type": header}, | ||
| ) | ||
| assert res.status == 200 | ||
| assert res.json() == {"size": 2} | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| @pytest.mark.parametrize("header", _charset_content_type_cases) | ||
| async def test_json_charset_content_type_async(header: str) -> None: | ||
| class HeadersHaberdasher(Haberdasher): | ||
| async def make_hat(self, request, ctx): | ||
| return Hat(size=2) | ||
|
|
||
| transport = ASGITransport(HaberdasherASGIApplication(HeadersHaberdasher())) | ||
|
|
||
| client = Client(transport=transport) | ||
|
|
||
| res = await client.post( | ||
| "http://localhost/connectrpc.example.Haberdasher/MakeHat", | ||
| content=b"{}", | ||
| headers={"content-type": header}, | ||
| ) | ||
| assert res.status == 200 | ||
| assert res.json() == {"size": 2} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit that we're double-normalizing the content type between here and
codec_name_from_content_typebelow, but no real suggestions on a refactor — probably fine to leave.