Permalink
Browse files

Updated cookie demo to list all cookies

  • Loading branch information...
1 parent 2742aca commit d6a020a052a2146ac6cd450ca2c1a5006c104f75 @dreverri dreverri committed Jun 28, 2010
Showing with 21 additions and 19 deletions.
  1. +1 −1 ebin/test.app
  2. +1 −1 priv/dispatch.conf
  3. +19 −0 src/cookie_resource.erl
  4. +0 −17 src/test_resource.erl
View
@@ -7,7 +7,7 @@
test,
test_app,
test_sup,
- test_resource
+ cookie_resource
]},
{registered, []},
{applications, [
View
@@ -1 +1 @@
-{[], test_resource, []}.
+{[], cookie_resource, []}.
View
@@ -0,0 +1,19 @@
+%% @author author <author@example.com>
+%% @copyright YYYY author.
+%% @doc Example webmachine_resource.
+
+-module(cookie_resource).
+-export([init/1, to_html/2]).
+
+-include_lib("webmachine/include/webmachine.hrl").
+
+init([]) -> {ok, undefined}.
+
+to_html(ReqData, State) ->
+ Cookies = wrq:req_cookie(ReqData),
+ Body0 = lists:foldl(fun({Key, Value}, Body) ->
+ Body ++ "<div>" ++ Key ++ ": " ++ Value ++ "</div>"
+ end,
+ "<div><h2>Cookies<h2></div>",
+ Cookies),
+ {"<html><body>" ++ Body0 ++ "</body></html>", ReqData, State}.
View
@@ -1,17 +0,0 @@
-%% @author author <author@example.com>
-%% @copyright YYYY author.
-%% @doc Example webmachine_resource.
-
--module(test_resource).
--export([init/1, to_html/2]).
-
--include_lib("webmachine/include/webmachine.hrl").
-
-init([]) -> {ok, undefined}.
-
-to_html(ReqData, State) ->
- Cookie = case wrq:get_cookie_value("test", ReqData) of
- undefined -> "";
- Value -> Value
- end,
- {"<html><body>Cookie:" ++ Cookie ++ "</body></html>", ReqData, State}.

0 comments on commit d6a020a

Please sign in to comment.