Skip to content

JSON API: Does not support Content-Type: application/json; charset=utf-8 #2384

@king7532

Description

@king7532

The main branch of Datasette 1.0a does NOT support Content-Type: application/json; charset=utf-8:

Actual Result:

POST /db/messages/-/insert HTTP/1.1
Content-Type: application/json; charset=utf-8
Content-Length: 117
Host: 10.0.2.2:8001
Connection: Keep-Alive
Accept-Encoding: gzip
User-Agent: okhttp/4.12.0

{"row":{"body":"my feedback","body_format":"T","from_email":"bk@bk.com","from_name":"BK","title":"Contact Feedback"}}
-----
HTTP/1.1 400 Bad Request
date: Tue, 06 Aug 2024 04:24:45 GMT
server: uvicorn
content-type: application/json; charset=utf-8
Transfer-Encoding: chunked

{"ok": false, "errors": ["Invalid content-type, must be application/json"]}

Expected Result:

POST /db/messages/-/insert HTTP/1.1
Content-Type: application/json
Content-Length: 117
Host: 10.0.2.2:8001
Connection: Keep-Alive
Accept-Encoding: gzip
User-Agent: okhttp/4.12.0

{"row":{"body":"my feedback","body_format":"T","from_email":"bk@bk.com","from_name":"BK","title":"Contact Feedback"}}
------
HTTP/1.1 201 Created
date: Tue, 06 Aug 2024 04:32:57 GMT
server: uvicorn
content-type: application/json; charset=utf-8
Transfer-Encoding: chunked

{"ok": true, "rows": [{"id": 13, "from_user_id": null, "from_name": "BK", "from_email": "bk@bk.com", "to_user_id": null, "title": "Contact Feedback", "body": "my feedback", "body_format": "T", "sent_on_utc": "2024-08-06 04:32:58"}]}

The bug is on the line:

if request.headers.get("content-type") != "application/json":

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions