diff options
author | Christopher Lenz <cmlenz@apache.org> | 2008-05-22 20:30:57 +0000 |
---|---|---|
committer | Christopher Lenz <cmlenz@apache.org> | 2008-05-22 20:30:57 +0000 |
commit | 10c68254aac8647c7bcf2a3d8f9523658eb828f7 (patch) | |
tree | a658b2b8959d523eeae70ab07f8fd0a4b412dfb8 /src/mochiweb/mochiweb_multipart.erl | |
parent | 3a08b41f8c2a97eee0904b6359e559ed76dfc9fd (diff) |
Updated MochiWeb in trunk to r73.
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@659244 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/mochiweb/mochiweb_multipart.erl')
-rw-r--r-- | src/mochiweb/mochiweb_multipart.erl | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/mochiweb/mochiweb_multipart.erl b/src/mochiweb/mochiweb_multipart.erl index cac35a91..9eb4badd 100644 --- a/src/mochiweb/mochiweb_multipart.erl +++ b/src/mochiweb/mochiweb_multipart.erl @@ -6,7 +6,7 @@ -module(mochiweb_multipart). -author('bob@mochimedia.com'). --export([parse_form/2]). +-export([parse_form/1, parse_form/2]). -export([parse_multipart_request/2]). -export([test/0]). @@ -16,6 +16,9 @@ %% TODO: DOCUMENT THIS MODULE. +parse_form(Req) -> + parse_form(Req, fun default_file_handler/2). + parse_form(Req, FileHandler) -> Callback = fun (Next) -> parse_form_outer(Next, FileHandler, []) end, {_, _, Res} = parse_multipart_request(Req, Callback), @@ -56,6 +59,17 @@ parse_form_file({body, Data}, {Name, Handler}, FileHandler, State) -> H1 = Handler(Data), fun (Next) -> parse_form_file(Next, {Name, H1}, FileHandler, State) end. +default_file_handler(Filename, ContentType) -> + default_file_handler_1(Filename, ContentType, []). + +default_file_handler_1(Filename, ContentType, Acc) -> + fun(eof) -> + Value = iolist_to_binary(lists:reverse(Acc)), + {Filename, ContentType, Value}; + (Next) -> + default_file_handler_1(Filename, ContentType, [Next | Acc]) + end. + parse_multipart_request(Req, Callback) -> %% TODO: Support chunked? Length = list_to_integer(Req:get_header_value("content-length")), @@ -295,19 +309,6 @@ test_parse2() -> ok = with_socket_server(ServerFun, ClientFun), ok. -handler_test(Filename, ContentType) -> - fun (Next) -> - handler_test_read(Next, {Filename, ContentType}, []) - end. - -handler_test_read(eof, {Filename, ContentType}, Acc) -> - Value = iolist_to_binary(lists:reverse(Acc)), - {Filename, ContentType, Value}; -handler_test_read(Data, H, Acc) -> - Acc1 = [Data | Acc], - fun (Next) -> handler_test_read(Next, H, Acc1) end. - - test_parse_form() -> ContentType = "multipart/form-data; boundary=AaB03x", "AaB03x" = get_boundary(ContentType), @@ -334,7 +335,7 @@ test_parse_form() -> ClientFun = fun (Socket) -> Req = fake_request(Socket, ContentType, size(BinContent)), - Res = parse_form(Req, fun handler_test/2), + Res = parse_form(Req), [{"submit-name", "Larry"}, {"files", {"file1.txt", {"text/plain",[]}, <<"... contents of file1.txt ...">>} |