Http\Concerns\InteractsWithContentType expectJson check fails for multiple accept options #33389
-
I'm trying to build a GraphQL client interface using Apollo-GraphQL and rebing/graphql-laravel. I am running into an issue where I (by accident) send the Accept header containing multiple options: "Accept: /, application/json" Anyway: "Accept: /, application/json" is by itself a valid, although slightly confusing header. A less confusing, but valid header would be "Accept: text/html, application/json", which will trigger this issue as well. Http\Concerns\InteractsWithContentType only checks the first entry in the accepted headers list. In order to get your Laravel back-end to recognise that this response expects JSON (or could expect JSON), you need to force the */json content type as the first content type. Expected behaviour: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
expectsJson
specifically checks ifapplication/json
is the FIRST requested content-type. However, theacceptsJson
method sounds more like what you want. It determines if JSON is accepted at all.