-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
content_types_provided should be allowed to return the empty list when no Accept header is specified #1640
Comments
If you don't provide content then doing a GET request will always fail, so I'm not sure what you are trying to say. What is the expected response? Cowboy does handle the case where accept isn't defined when content is provided. https://github.com/ninenines/cowboy/blob/master/src/cowboy_rest.erl#L476-L486 Content negotiation is also useful for other methods. For example if you return a body following a POST request, it can tell you which content type to use. The only cases where we don't care about content negotiation is when the resource never returns a body. In that case simply do not implement |
Imagine an endpoint where: allowed_methods(Req, State) ->
{[<<"OPTIONS">>, <<"HEAD">>, <<"GET">>, <<"POST">>, <<"DELETE">>], Req, State}. and where only the content_types_provided(#{method := <<"GET">>} = Req, State) ->
{[
{<<"application/json">>, to_json}
], Req, State};
content_types_provided(Req, State) ->
{[], Req, State}. However, this doesn't work, because the current |
You don't need to go that far, you can just do: content_types_provided(Req, State) ->
{[
{<<"application/json">>, to_json}
], Req, State}. |
I still think that implementing The current implementation handles (1) as reject all requests with 406, whereas (2) only returns I suggest changing the implementation such as (1) and (2) are equivalent. Effectively handling the case where the client doesn't send any |
They can't be equivalent because when the callback is not implemented it is equivalent to returning If you need to have the equivalent you need to return this and not just |
The implementation today unconditionally returns a 406 if the
content_types_provided
callback forcowboy_rest
:I think that it should take into account the situation where the client doesn't specify any
Accept
header, in which case it should skip the content negotiation.The text was updated successfully, but these errors were encountered: