public
Description: A new revision of Fuzed, the Erlang-based frontend for web apps. Check out the mailing list at http://groups.google.com/group/fuzed
Clone URL: git://github.com/KirinDave/fuzed.git
Search Repo:
Splitting out the core of a responder to responder_base.

Now we can define responders as permutations of that code, 
allowing for custom dispatch routines on a per-app basis!
KirinDave (author)
Sun May 11 19:41:14 -0700 2008
commit  fc71cc0e7fcfd4e09c6114963835356a9922bc64
tree    f78117c92088cf779c1c37f83f54e432382e29fb
parent  eec6db84255ed74431ac2ecd1b7629306a697273
...
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
...
1
 
 
 
2
3
4
5
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,97 +1,7 @@
0
 -module(frontend_responder).
0
--include("yaws_api.hrl").
0
--include("yaws.hrl").
0
--include("fuzed.hrl").
0
+-include("responder_base.erl").
0
 -compile(export_all).
0
 
0
 provide_pool(_A) ->
0
   resource_fountain:best_pool_for_details_match(details()).
0
-
0
-out404(A, _GC, SC) ->
0
- Parameters = [{request, {struct, parse_arg(A, SC)}}],
0
- io:format("Param restructure:~n~p~n", [Parameters]),
0
- Pool = provide_pool(A),
0
- case node_api:safely_send_call_to_pool_no_lookup(handle_request,
0
- Parameters,
0
- pure,
0
- Pool) of
0
- {result, R} ->
0
- convert_response(R);
0
- {error, R} ->
0
- error_logger:info_msg("500 Internal Server Error: ~p~n", [R]),
0
- [{status, 500}, {html, "Sumpin fucked."}]
0
- end.
0
-
0
-parse_arg(Request, ServerOptions) ->
0
- Headers = Request#arg.headers,
0
- [convert_method(Request),
0
- convert_version(Request),
0
- convert_querypath(Request),
0
- {querydata, prep(Request#arg.querydata)},
0
- {servername, prep(ServerOptions#sconf.servername)},
0
- {headers, {struct, convert_headers(Request#arg.headers)}},
0
- {cookies, {array, lists:map(fun(X) -> prep(X) end, Headers#headers.cookie)}},
0
- {pathinfo, prep(ServerOptions#sconf.docroot)},
0
- {postdata, Request#arg.clidata}].
0
-
0
-
0
-convert_method(Request) ->
0
- R = Request#arg.req,
0
- {http_request,Method,{_Type,_Path},_} = R,
0
- {method, Method}.
0
-
0
-convert_querypath(Request) ->
0
- R = Request#arg.req,
0
- {http_request,_Method,{_Type,Path},_} = R,
0
- {querypath, prep(Path)}.
0
-
0
-convert_version(Request) ->
0
- R = Request#arg.req,
0
- {http_request,_Method,{_Type,_Path},Version} = R,
0
- {http_version, {array, tuple_to_list(Version)}}.
0
-
0
-convert_req(R) ->
0
- {http_request,Method,{_Type,Path},_} = R,
0
- {Method, prep(Path)}.
0
-
0
-convert_headers(A) ->
0
- NormalHeaders = [{connection, prep(A#headers.connection)},
0
- {accept, prep(A#headers.accept)},
0
- {host, prep(A#headers.host)},
0
- {if_modified_since, prep(A#headers.if_modified_since)},
0
- {if_match, prep(A#headers.if_match)},
0
- {if_none_match, prep(A#headers.if_none_match)},
0
- {if_range, prep(A#headers.if_range)},
0
- {if_unmodified_since, prep(A#headers.if_unmodified_since)},
0
- {range, prep(A#headers.range)},
0
- {referer, prep(A#headers.referer)},
0
- {user_agent, prep(A#headers.user_agent)},
0
- {accept_ranges, prep(A#headers.accept_ranges)},
0
- {keep_alive, prep(A#headers.keep_alive)},
0
- {location, prep(A#headers.location)},
0
- {content_length, prep(A#headers.content_length)},
0
- {content_type, prep(A#headers.content_type)},
0
- {content_encoding, prep(A#headers.content_encoding)},
0
- {authorization, prep(A#headers.authorization)},
0
- {transfer_encoding, prep(A#headers.transfer_encoding)}],
0
- SpecialHeaders =
0
- lists:map(fun({http_header, _Len, Name, _, Value}) -> {prep(Name), prep(Value)} end,
0
- A#headers.other),
0
- [{Name, Res} || {Name, Res} <- NormalHeaders, Res /= undefined] ++ SpecialHeaders.
0
-
0
-convert_response({response, EhtmlTuple}) ->
0
- {Status, AllHeaders, Html} = EhtmlTuple,
0
- {allheaders, HeaderList} = AllHeaders,
0
- ProcessedHeaderList = lists:map(fun({header, Name, Value}) -> {header, [binary_to_list(Name) ++ ":", binary_to_list(Value)]} end,
0
- tuple_to_list(HeaderList)),
0
- {html, RawResult} = Html,
0
- [Status, {allheaders, ProcessedHeaderList}, {html, binary_to_list(RawResult)}].
0
-
0
-prep(A) when is_list(A) -> list_to_binary(A);
0
-prep(A) -> A.
0
-
0
-details() ->
0
- {ok, Details} =
0
- application:get_env(fuzed_frontend, details),
0
- Details.
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
0
@@ -1 +1,93 @@
0
+-include("yaws_api.hrl").
0
+-include("yaws.hrl").
0
+-include("fuzed.hrl").
0
+-export([out404/3]).
0
+
0
+out404(A, _GC, SC) ->
0
+ Parameters = [{request, {struct, parse_arg(A, SC)}}],
0
+ io:format("Param restructure:~n~p~n", [Parameters]),
0
+ Pool = provide_pool(A),
0
+ case node_api:safely_send_call_to_pool_no_lookup(handle_request,
0
+ Parameters,
0
+ pure,
0
+ Pool) of
0
+ {result, R} ->
0
+ convert_response(R);
0
+ {error, R} ->
0
+ error_logger:info_msg("500 Internal Server Error: ~p~n", [R]),
0
+ [{status, 500}, {html, "Sumpin fucked."}]
0
+ end.
0
+
0
+parse_arg(Request, ServerOptions) ->
0
+ Headers = Request#arg.headers,
0
+ [convert_method(Request),
0
+ convert_version(Request),
0
+ convert_querypath(Request),
0
+ {querydata, prep(Request#arg.querydata)},
0
+ {servername, prep(ServerOptions#sconf.servername)},
0
+ {headers, {struct, convert_headers(Request#arg.headers)}},
0
+ {cookies, {array, lists:map(fun(X) -> prep(X) end, Headers#headers.cookie)}},
0
+ {pathinfo, prep(ServerOptions#sconf.docroot)},
0
+ {postdata, Request#arg.clidata}].
0
+
0
+
0
+convert_method(Request) ->
0
+ R = Request#arg.req,
0
+ {http_request,Method,{_Type,_Path},_} = R,
0
+ {method, Method}.
0
+
0
+convert_querypath(Request) ->
0
+ R = Request#arg.req,
0
+ {http_request,_Method,{_Type,Path},_} = R,
0
+ {querypath, prep(Path)}.
0
+
0
+convert_version(Request) ->
0
+ R = Request#arg.req,
0
+ {http_request,_Method,{_Type,_Path},Version} = R,
0
+ {http_version, {array, tuple_to_list(Version)}}.
0
+
0
+convert_req(R) ->
0
+ {http_request,Method,{_Type,Path},_} = R,
0
+ {Method, prep(Path)}.
0
+
0
+convert_headers(A) ->
0
+ NormalHeaders = [{connection, prep(A#headers.connection)},
0
+ {accept, prep(A#headers.accept)},
0
+ {host, prep(A#headers.host)},
0
+ {if_modified_since, prep(A#headers.if_modified_since)},
0
+ {if_match, prep(A#headers.if_match)},
0
+ {if_none_match, prep(A#headers.if_none_match)},
0
+ {if_range, prep(A#headers.if_range)},
0
+ {if_unmodified_since, prep(A#headers.if_unmodified_since)},
0
+ {range, prep(A#headers.range)},
0
+ {referer, prep(A#headers.referer)},
0
+ {user_agent, prep(A#headers.user_agent)},
0
+ {accept_ranges, prep(A#headers.accept_ranges)},
0
+ {keep_alive, prep(A#headers.keep_alive)},
0
+ {location, prep(A#headers.location)},
0
+ {content_length, prep(A#headers.content_length)},
0
+ {content_type, prep(A#headers.content_type)},
0
+ {content_encoding, prep(A#headers.content_encoding)},
0
+ {authorization, prep(A#headers.authorization)},
0
+ {transfer_encoding, prep(A#headers.transfer_encoding)}],
0
+ SpecialHeaders =
0
+ lists:map(fun({http_header, _Len, Name, _, Value}) -> {prep(Name), prep(Value)} end,
0
+ A#headers.other),
0
+ [{Name, Res} || {Name, Res} <- NormalHeaders, Res /= undefined] ++ SpecialHeaders.
0
+
0
+convert_response({response, EhtmlTuple}) ->
0
+ {Status, AllHeaders, Html} = EhtmlTuple,
0
+ {allheaders, HeaderList} = AllHeaders,
0
+ ProcessedHeaderList = lists:map(fun({header, Name, Value}) -> {header, [binary_to_list(Name) ++ ":", binary_to_list(Value)]} end,
0
+ tuple_to_list(HeaderList)),
0
+ {html, RawResult} = Html,
0
+ [Status, {allheaders, ProcessedHeaderList}, {html, binary_to_list(RawResult)}].
0
+
0
+prep(A) when is_list(A) -> list_to_binary(A);
0
+prep(A) -> A.
0
+
0
+details() ->
0
+ {ok, Details} =
0
+ application:get_env(fuzed_frontend, details),
0
+ Details.

Comments

    No one has commented yet.