API post request without an Accept header returns 406

RFC 7231 suggests that a request with a missing Accept header should be treated as */*, but hitting the API POST endpoint for a data explorer query without said header returns 406 Not Acceptable. I’m not sure if this is specific to data explorer or if it applies to other POSTs, too. All the other GETs I’ve used haven’t had this issue.

It so happens that curl and Python’s requests append Accept: */* to all their requests by default, but not all tools do. You can see this behavior by disabling curl’s default with an empty header, e.g.,

curl -X POST "https://discourse.example.com/admin/plugins/explorer/queries/26/run" \
-H "Content-Type: multipart/form-data;" \
-H "Api-Key: <your_all_users_api_key>" \
-H "Api-Username: system" \
-H "Accept:"

Not a major thing, but it might be something that other tools hit, too… and it seems like it could be a simple fix, especially since all other endpoints I’ve used work without it.

2개의 좋아요

이 문제는 Rails 스택에서(Discourse가 아니라) 비롯된 것으로 보이며, 우회하는 것이 매우 복잡할 가능성이 높습니다.

actionpack에서 406 상태 코드와 관련된 몇 가지 어설션(assertions)을 확인할 수 있습니다.

간단한 우회 방법이 있고 Rails의 의도된 동작으로 보이기 때문에, 당분간 #contribute:feature로 카테고리를 변경하겠습니다.

1개의 좋아요