[ewgi commit] r73 - branches/RB-0.2/lib/ewgi/priv/examples/src

0 views
Skip to first unread message

codesite...@google.com

unread,
Oct 10, 2008, 2:50:49 PM10/10/08
to ewgi...@googlegroups.com
Author: huntermorris
Date: Fri Oct 10 11:42:53 2008
New Revision: 73

Modified:
branches/RB-0.2/lib/ewgi/priv/examples/src/ewgi_fv.erl

Log:
Modified ewgi_fv

TODO: Implement reading from client body for POST


Modified: branches/RB-0.2/lib/ewgi/priv/examples/src/ewgi_fv.erl
==============================================================================
--- branches/RB-0.2/lib/ewgi/priv/examples/src/ewgi_fv.erl (original)
+++ branches/RB-0.2/lib/ewgi/priv/examples/src/ewgi_fv.erl Fri Oct 10
11:42:53 2008
@@ -27,7 +27,7 @@
-include_lib("ewgi/include/ewgi.hrl").

%% API
--export([handle_req/2,
+-export([handle_req/1,
validate/2,
required/0,
integer/0,
@@ -35,29 +35,32 @@
regexp/1,
email/0]).

-
%%--------------------------------------------------------------------
-%% @spec handle_req(Env, StartResp) -> io_list()
+%% @spec handle_req(Ctx) -> Ctx1
%%
%% @doc Check for required values. Returns a closure of two
%% arguments (Key and Data). When called the closure check if Key
%% is present and not empty.
%% @end
%%--------------------------------------------------------------------
-handle_req(Env, StartResp) ->
- Data = case ewgi_api:method(Env) of
- 'GET' -> ewgi_api:parse_qs(ewgi_api:qs(Env));
- _ ->
ewgi_api:parse_post(ewgi_api:get_value(content_body, Env))
+handle_req(Ctx) ->
+ Data = case ewgi_api:method(Ctx) of
+ 'GET' -> ewgi_api:parse_qs(ewgi_api:qs(Ctx));
+ _ -> ewgi_api:parse_post(read_all_data(Ctx))
end,
- Rules = ewgi_api:get_data("ewgi_fw.rules", Env),
+ Rules = ewgi_api:get_data("ewgi_fw.rules", Ctx),
case validate(Data, Rules) of
- ok -> [];
+ ok ->
+ ewgi_api:set_response(#ewgi_response{status={200, "OK"},
headers=[], message_body=[]}, Ctx);
{error, Errors} ->
%% redirect to the referer page adding error messsages
- Ref = ewgi_api:get_header(referer, Env),
- StartResp("303", [{location,
Ref++"?"++ewgi_api:urlencode(Errors)}]),
- []
+ Ref = ewgi_api:get_header(referer, Ctx),
+ ewgi_api:set_response(#ewgi_response{status={303, "See
Other"}, headers=[{location, Ref++"?"++ewgi_api:urlencode(Errors)}],
message_body=[]}, Ctx)
end.
+
+%% TODO: Implement this!
+read_all_data(_Ctx) ->
+ [].


%%--------------------------------------------------------------------

Reply all
Reply to author
Forward
0 new messages