1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE> [99s-extend] cowboy_rest, POST and redirect
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:extend%40lists.ninenines.eu?Subject=Re%3A%20%5B99s-extend%5D%20cowboy_rest%2C%20POST%20and%20redirect&In-Reply-To=%3CCE953B4E.76B1%25rolph.deruiter%40spilgames.com%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="000285.html">
<LINK REL="Next" HREF="000287.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[99s-extend] cowboy_rest, POST and redirect</H1>
<B>Rolph de Ruiter</B>
<A HREF="mailto:extend%40lists.ninenines.eu?Subject=Re%3A%20%5B99s-extend%5D%20cowboy_rest%2C%20POST%20and%20redirect&In-Reply-To=%3CCE953B4E.76B1%25rolph.deruiter%40spilgames.com%3E"
TITLE="[99s-extend] cowboy_rest, POST and redirect">Rolph.deRuiter at spilgames.com
</A><BR>
<I>Tue Oct 29 10:16:15 CET 2013</I>
<P><UL>
<LI>Previous message: <A HREF="000285.html">[99s-extend] cowboy_rest, POST and redirect
</A></li>
<LI>Next message: <A HREF="000287.html">[99s-extend] REST handler failure
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#286">[ date ]</a>
<a href="thread.html#286">[ thread ]</a>
<a href="subject.html#286">[ subject ]</a>
<a href="author.html#286">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>(forgot to include the list)
On 10/29/13 10:14 AM, "Rolph de Ruiter" <<A HREF="https://lists.ninenines.eu/listinfo/extend">Rolph.deRuiter at spilgames.com</A>>
wrote:
><i>Thanks!
</I>><i>
</I>><i>{halt, NewReq, State} worked like a charm :)
</I>><i>
</I>><i>Cheers,
</I>><i>Rolph
</I>><i>
</I>><i>On 10/29/13 10:09 AM, "Loïc Hoguin" <<A HREF="https://lists.ninenines.eu/listinfo/extend">essen at ninenines.eu</A>> wrote:
</I>><i>
</I>>><i>On 10/29/2013 10:00 AM, Rolph de Ruiter wrote:
</I>>>><i> Hi,
</I>>>><i>
</I>>>><i> I'm using cowboy_rest for a part of our api to handle POST requests.
</I>>>><i> Under certain conditions, I would like to redirect to a new location
</I>>>><i> (based on availability of the redirect qs parameter).
</I>>>><i> I was unable to get the moved_temporarily/2 callback to work (was not
</I>>>><i> invoked at al). So I just do the 302 myself, using cowboy_req:reply/4.
</I>>>><i> This works, however, every time it produces an error in the emulator
</I>>>><i> process:
</I>>>><i> [error] emulator Error in process <0.509.0> on node '<A HREF="https://lists.ninenines.eu/listinfo/extend">api at dev.loc</A>'
</I>>>><i>with
</I>>>><i> exit value: {function_clause,[{cowboy_req,reply,[204,[],<<0
</I>>>><i> bytes>>,{http_req,#Port<0.14491>,ranch_tcp,keepalive,<0.509.0>,<<4
</I>>>><i> bytes>>,'HTTP/1.1',{{10,10,10,1},62197},<<15
</I>>>><i>bytes>>,undefined,8000,<<26
</I>>>><i> bytes>>,undefined,<<14 bytes>>,[{<<8 bytes>>,<<5 bytes>>}],[{method,<<5
</I>>>><i> bytes>>}],[{<<4 bytes>>,<<20 bytes>>},{<<10 bytes>>,<<10 bytes>>},{<<14
</I>>>><i> bytes>>,<<2 bytes>>},{<<6 bytes>>,<<74 bytes>>},{<<6 bytes>>,<<27
</I>>>><i> bytes>>},{<<10 bytes>>,<<120 bytes>>},{<<12 bytes>>,<<33 bytes>>},{<<7
</I>>>><i> bytes>>,<<54 bytes>>},{<<15 bytes>>,<<17 bytes>>},{<<15 bytes>>,<<14
</I>>>><i> bytes>>},{<<6 bytes>>,<<245 bytes>>}],[{<<14 bytes>>,34},{<<6
</I>>>><i> bytes>>,undefined},{<<14 bytes>>,34},{<<12 bytes>>,{<<11 bytes>>,<<21
</I>>>><i> bytes>>,[]}},{<<17 bytes>>,undefined},{<<13 bytes>>,...
</I>>>><i>
</I>>>><i> Can you point me out how to (ideally) make use of moved_temporarily/2
</I>>>><i>or
</I>>>><i> how I can prevent cowboy_rest from wanting to reply with 204 in this
</I>>>><i>case?
</I>>><i>
</I>>><i>moved_temporarily is only called if the resource previously existed.
</I>>><i>
</I>>><i>As for calling reply yourself, you just need to return {halt, NewReq,
</I>>><i>State} afterwards.
</I>>><i>
</I>>><i>--
</I>>><i>Loïc Hoguin
</I>>><i>Erlang Cowboy
</I>>><i>Nine Nines
</I>>><i><A HREF="http://ninenines.eu">http://ninenines.eu</A>
</I>><i>
</I>
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI>Previous message: <A HREF="000285.html">[99s-extend] cowboy_rest, POST and redirect
</A></li>
<LI>Next message: <A HREF="000287.html">[99s-extend] REST handler failure
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#286">[ date ]</a>
<a href="thread.html#286">[ thread ]</a>
<a href="subject.html#286">[ subject ]</a>
<a href="author.html#286">[ author ]</a>
</LI>
</UL>
<hr>
<a href="https://lists.ninenines.eu/listinfo/extend">More information about the Extend
mailing list</a><br>
</body></html>
|