Skip to content

Return 415 from WSGI for unknown GET encoding - #377

Merged
stefanvanburen merged 2 commits into
mainfrom
svanburen/wsgi-get-encoding-415
Sep 30, 2026
Merged

stefanvanburen merged 2 commits into
mainfrom
svanburen/wsgi-get-encoding-415

Conversation

@stefanvanburen

Copy link
Copy Markdown
Member

For a Connect unary GET whose encoding query parameter is missing or names a codec the server doesn't support, connect-go answers 415 with Accept-Post before running any handler logic: connectHandler.CanHandlePayload maps encoding to a content type, and the handler returns 415 when no protocol accepts it. The ASGI application already does this; the WSGI application instead answered unimplemented after starting the metadata interceptors.

The new test_client_errors cases for an unknown and a missing encoding fail on main for WSGI only.

The WSGI server answered a unary GET whose `encoding` query parameter
named no configured codec with `unimplemented`, after the metadata
interceptors had already started. connect-go and the ASGI server answer
415 with `Accept-Post` before running any interceptors, so resolve the
codec up front in `_handle_unary` the way the ASGI server does.

Signed-off-by: Stefan VanBuren <stefan@vanburen.xyz>
codec = self._codecs.get(codec_name)
if not codec:
raise ConnectError(
Code.UNIMPLEMENTED, f"invalid message encoding: '{codec_name}'"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm wonder how that happened

Comment thread src/connectrpc/_server_sync.py Outdated
)
codec_name = query_params.get("encoding", ("",))[0]
else:
query_params = {}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the singleton unset pattern from async? Or alternatively None and assert is not None in the get path would be fine too

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copied it over in 5365ba8, good idea!

Signed-off-by: Stefan VanBuren <stefan@vanburen.xyz>
@stefanvanburen
stefanvanburen merged commit be4a5e3 into main Sep 30, 2026
23 checks passed
@stefanvanburen
stefanvanburen deleted the svanburen/wsgi-get-encoding-415 branch September 30, 2026 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants