diff options
Diffstat (limited to 'archives/extend/attachments/20140203/2982cff3/attachment.html')
-rw-r--r-- | archives/extend/attachments/20140203/2982cff3/attachment.html | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/archives/extend/attachments/20140203/2982cff3/attachment.html b/archives/extend/attachments/20140203/2982cff3/attachment.html new file mode 100644 index 00000000..b011e41e --- /dev/null +++ b/archives/extend/attachments/20140203/2982cff3/attachment.html @@ -0,0 +1,82 @@ +<tt> +<div dir="ltr">My application sends both headers: “Content-type” and “Accept” header using POST method.<div><br><div>For POST rest handler do I have to specify both: content_types_accepted and content_types_provided to manage this kind of request?</div><br> +<br> +</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Feb 3, 2014 at 7:23 PM, Loïc Hoguin <span dir="ltr"><<a href="mailto:[email protected]" target="_blank">[email protected]</a>></span> wrote:<br><br> +<br> +<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The content-type provided is relevant for any response, not just responses to GET requests. It defaults to text/html. If your client doesn't send that content-type, you have to define the callback.<br><br> +<br> +<br> +<br><br> +I notice that the documentation is incorrect about the relevant methods for this callback, I will open a ticket to fix it soon.<div class="im"><br><br> +<br><br> +On 02/03/2014 07:13 PM, Łukasz Biedrycki wrote:<br><br> +</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br> +Hi,<br><br> +I have a rest handler that accepts POST and PUT requests with<br><br> +“application/json” content type.<br><br> +<br><br> +I have content_types_accepted function defined as follows:<br><br> +<br><br> +content_types_accepted(Req, State) -><br><br> +<br><br> +<br><br> +{[{‘application/json', from_json}], Req, State}.<br><br> +<br><br> +<br><br> +<br><br> +The problem I have is within a request that has two headers:<br><br> +<br></div><br> +*Content-type*: application/json<br><br> +*Accept*: application/json<br><br> +<br><br> +With this combination I receive *406*.<div class="im"><br><br> +<br><br> +You can repeat it with test:<br><br> +<br><br> +http_SUITE.erl:<br><br> +1072 rest_postonly(Config) -><br><br> +1073 Client = ?config(client, Config),<br><br> +1074 Headers = [<br><br> +1075 {<<"content-type">>, <<"text/plain">>},<br><br> +1076 {<<"accept">>, <<"text/plain">>}<br><br> +1077 ],<br><br> +1078 {ok, Client2} = cowboy_client:request(<<"POST"<u></u>>>,<br><br> +1079 build_url("/postonly", Config), Headers, "12345", Client),<br><br> +1080 {ok, 204, _, _} = cowboy_client:response(<u></u>Client2).<br><br> +<br><br> +My solution to that was to add a content_types_provided function:<br><br> +<br><br> +<br><br> +content_types_provided(Req, State) -><br><br> +<br><br> +<br><br> +ContentTypes = [{{<<"application">>, <<"json">>, '*'}, to_json}],<br><br> +<br><br> +<br><br> +{ContentTypes, Req, State}.<br><br> +<br><br> +<br><br> +<br></div><br> +But it is useless as *to_json* callback registered is not called anyhow.<br><br> +<br><br> +Adding *content_types_provided* function is a correct solution in this case?<div class="im"><br><br> +Or I am missing something here?<br><br> +“Accept” header is not relevant only in case of GET requests?<br><br> +<br><br> +Thank for help,<br><br> +Łukasz Biedrycki<br><br> +<br><br> +<br></div><br> +______________________________<u></u>_________________<br><br> +Extend mailing list<br><br> +<a href="mailto:[email protected]" target="_blank">[email protected]</a><br><br> +<a href="https://lists.ninenines.eu/listinfo/extend" target="_blank">https://lists.ninenines.eu/<u></u>listinfo/extend</a><br><br> +<br><span class="HOEnZb"><font color="#888888"><br> +</font></span></blockquote><span class="HOEnZb"><font color="#888888"><br> +<br><br> +-- <br><br> +Loïc Hoguin<br><br> +<a href="http://ninenines.eu" target="_blank">http://ninenines.eu</a><br><br> +</font></span></blockquote></div><br></div><br> + +</tt> |