Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Mitigate errors when receiving requests with empty HTTP request bodies #10

Merged
merged 1 commit into from
Feb 4, 2022

Conversation

amotl
Copy link
Contributor

@amotl amotl commented Feb 4, 2022

Hi there,

at #9 (comment), we discovered that there is an issue with Simple JSON Datasource sending HTTP requests with empty HTTP request bodies, but still having the Content-Type: application/json HTTP header present. Those requests will make Flask croak like:

$ echo "" | http localhost:3003 Content-Type:application/json
HTTP/1.0 400 BAD REQUEST

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)</p>

This patch fixes the problem, like @ThiefMaster suggested at pallets/flask#1940 (comment):

You can catch the exception or use silent=True.

In this manner, it will also resolve #7.

With kind regards,
Andreas.

/cc @byteptr, @MichielKE

$ echo "" | http localhost:3003 Content-Type:application/json
HTTP/1.0 400 BAD REQUEST

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)</p>
@amotl amotl merged commit d90d45f into main Feb 4, 2022
@amotl amotl deleted the amo/fix-test-datasource branch February 4, 2022 14:37
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't run your example: Error 400 bad request
1 participant