summaryrefslogtreecommitdiffstats
path: root/_build/static/archives/extend/2014-February/000325.html
diff options
context:
space:
mode:
Diffstat (limited to '_build/static/archives/extend/2014-February/000325.html')
-rw-r--r--_build/static/archives/extend/2014-February/000325.html134
1 files changed, 134 insertions, 0 deletions
diff --git a/_build/static/archives/extend/2014-February/000325.html b/_build/static/archives/extend/2014-February/000325.html
new file mode 100644
index 00000000..784e1a10
--- /dev/null
+++ b/_build/static/archives/extend/2014-February/000325.html
@@ -0,0 +1,134 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<HTML>
+ <HEAD>
+ <TITLE> [99s-extend] Accept header in POST request
+ </TITLE>
+ <LINK REL="Index" HREF="index.html" >
+ <LINK REL="made" HREF="mailto:extend%40lists.ninenines.eu?Subject=Re%3A%20%5B99s-extend%5D%20Accept%20header%20in%20POST%20request&In-Reply-To=%3C52EFDEA4.6050004%40ninenines.eu%3E">
+ <META NAME="robots" CONTENT="index,nofollow">
+ <style type="text/css">
+ pre {
+ white-space: pre-wrap; /* css-2.1, curent FF, Opera, Safari */
+ }
+ </style>
+ <META http-equiv="Content-Type" content="text/html; charset=us-ascii">
+ <LINK REL="Previous" HREF="000324.html">
+ <LINK REL="Next" HREF="000326.html">
+ </HEAD>
+ <BODY BGCOLOR="#ffffff">
+ <H1>[99s-extend] Accept header in POST request</H1>
+ <B>Lo&#239;c Hoguin</B>
+ <A HREF="mailto:extend%40lists.ninenines.eu?Subject=Re%3A%20%5B99s-extend%5D%20Accept%20header%20in%20POST%20request&In-Reply-To=%3C52EFDEA4.6050004%40ninenines.eu%3E"
+ TITLE="[99s-extend] Accept header in POST request">essen at ninenines.eu
+ </A><BR>
+ <I>Mon Feb 3 19:23:32 CET 2014</I>
+ <P><UL>
+ <LI>Previous message: <A HREF="000324.html">[99s-extend] Accept header in POST request
+</A></li>
+ <LI>Next message: <A HREF="000326.html">[99s-extend] Accept header in POST request
+</A></li>
+ <LI> <B>Messages sorted by:</B>
+ <a href="date.html#325">[ date ]</a>
+ <a href="thread.html#325">[ thread ]</a>
+ <a href="subject.html#325">[ subject ]</a>
+ <a href="author.html#325">[ author ]</a>
+ </LI>
+ </UL>
+ <HR>
+<!--beginarticle-->
+<PRE>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.
+
+I notice that the documentation is incorrect about the relevant methods
+for this callback, I will open a ticket to fix it soon.
+
+On 02/03/2014 07:13 PM, &#321;ukasz Biedrycki wrote:
+&gt;<i> Hi,
+</I>&gt;<i> I have a rest handler that accepts POST and PUT requests with
+</I>&gt;<i> &#8220;application/json&#8221; content type.
+</I>&gt;<i>
+</I>&gt;<i> I have content_types_accepted function defined as follows:
+</I>&gt;<i>
+</I>&gt;<i> content_types_accepted(Req, State) -&gt;
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i> {[{&#8216;application/json', from_json}], Req, State}.
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i> The problem I have is within a request that has two headers:
+</I>&gt;<i>
+</I>&gt;<i> *Content-type*: application/json
+</I>&gt;<i> *Accept*: application/json
+</I>&gt;<i>
+</I>&gt;<i> With this combination I receive *406*.
+</I>&gt;<i>
+</I>&gt;<i> You can repeat it with test:
+</I>&gt;<i>
+</I>&gt;<i> http_SUITE.erl:
+</I>&gt;<i> 1072 rest_postonly(Config) -&gt;
+</I>&gt;<i> 1073 Client = ?config(client, Config),
+</I>&gt;<i> 1074 Headers = [
+</I>&gt;<i> 1075 {&lt;&lt;&quot;content-type&quot;&gt;&gt;, &lt;&lt;&quot;text/plain&quot;&gt;&gt;},
+</I>&gt;<i> 1076 {&lt;&lt;&quot;accept&quot;&gt;&gt;, &lt;&lt;&quot;text/plain&quot;&gt;&gt;}
+</I>&gt;<i> 1077 ],
+</I>&gt;<i> 1078 {ok, Client2} = cowboy_client:request(&lt;&lt;&quot;POST&quot;&gt;&gt;,
+</I>&gt;<i> 1079 build_url(&quot;/postonly&quot;, Config), Headers, &quot;12345&quot;, Client),
+</I>&gt;<i> 1080 {ok, 204, _, _} = cowboy_client:response(Client2).
+</I>&gt;<i>
+</I>&gt;<i> My solution to that was to add a content_types_provided function:
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i> content_types_provided(Req, State) -&gt;
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i> ContentTypes = [{{&lt;&lt;&quot;application&quot;&gt;&gt;, &lt;&lt;&quot;json&quot;&gt;&gt;, '*'}, to_json}],
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i> {ContentTypes, Req, State}.
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i> But it is useless as *to_json* callback registered is not called anyhow.
+</I>&gt;<i>
+</I>&gt;<i> Adding *content_types_provided* function is a correct solution in this case?
+</I>&gt;<i> Or I am missing something here?
+</I>&gt;<i> &#8220;Accept&#8221; header is not relevant only in case of GET requests?
+</I>&gt;<i>
+</I>&gt;<i> Thank for help,
+</I>&gt;<i> &#321;ukasz Biedrycki
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i> _______________________________________________
+</I>&gt;<i> Extend mailing list
+</I>&gt;<i> <A HREF="https://lists.ninenines.eu/listinfo/extend">Extend at lists.ninenines.eu</A>
+</I>&gt;<i> <A HREF="https://lists.ninenines.eu/listinfo/extend">https://lists.ninenines.eu/listinfo/extend</A>
+</I>&gt;<i>
+</I>
+--
+Lo&#239;c Hoguin
+<A HREF="http://ninenines.eu">http://ninenines.eu</A>
+
+</PRE>
+
+<!--endarticle-->
+ <HR>
+ <P><UL>
+ <!--threads-->
+ <LI>Previous message: <A HREF="000324.html">[99s-extend] Accept header in POST request
+</A></li>
+ <LI>Next message: <A HREF="000326.html">[99s-extend] Accept header in POST request
+</A></li>
+ <LI> <B>Messages sorted by:</B>
+ <a href="date.html#325">[ date ]</a>
+ <a href="thread.html#325">[ thread ]</a>
+ <a href="subject.html#325">[ subject ]</a>
+ <a href="author.html#325">[ author ]</a>
+ </LI>
+ </UL>
+
+<hr>
+<a href="https://lists.ninenines.eu/listinfo/extend">More information about the Extend
+mailing list</a><br>
+</body></html>