-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Description
If Content-Type is missing from the request, Twirpy returns a 500 response code instead of gracefully handling the error.
Make any request without a Content-Type. This error will be raised.
Error: got non-twirp exception while processing request
Trace:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/twirp/asgi.py", line 62, in __call__
encoder, decoder = self._get_encoder_decoder(endpoint, headers)
File "/usr/local/lib/python3.10/site-packages/twirp/base.py", line 104, in _get_encoder_decoder
message="unexpected Content-Type: " + ctype
TypeError: can only concatenate str (not "NoneType") to str
See the code below. ctype = headers.get('content-type', None) sets ctype to None then attempts to concatenate the None type to a string in message="unexpected Content-Type: " + ctype while building the BadRoute error.
Lines 93 to 106 in 6940030
| def _get_encoder_decoder(self, endpoint, headers): | |
| ctype = headers.get('content-type', None) | |
| if "application/json" == ctype: | |
| decoder = functools.partial(self.json_decoder, data_obj=endpoint.input) | |
| encoder = functools.partial(self.json_encoder, data_obj=endpoint.output) | |
| elif "application/protobuf" == ctype: | |
| decoder = functools.partial(self.proto_decoder, data_obj=endpoint.input) | |
| encoder = functools.partial(self.proto_encoder, data_obj=endpoint.output) | |
| else: | |
| raise exceptions.TwirpServerException( | |
| code=errors.Errors.BadRoute, | |
| message="unexpected Content-Type: " + ctype | |
| ) | |
| return encoder, decoder |
Metadata
Metadata
Assignees
Labels
No labels