couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject [4/8] git commit: updated refs/heads/master to d751a39
Date Wed, 24 Apr 2013 22:18:35 GMT
COUCHDB-1696 import mochiweb from tag v2.4.2


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/cbb8a550
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/cbb8a550
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/cbb8a550

Branch: refs/heads/master
Commit: cbb8a55082a19897e8d1350db5351bf41689185d
Parents: ae6f1eb
Author: Dave Cottlehuber <dch@apache.org>
Authored: Tue Mar 12 20:11:08 2013 +0100
Committer: Dave Cottlehuber <dch@apache.org>
Committed: Thu Apr 25 00:13:20 2013 +0200

----------------------------------------------------------------------
 src/mochiweb/mochifmt.erl               |    2 +-
 src/mochiweb/mochifmt_records.erl       |   14 +-
 src/mochiweb/mochifmt_std.erl           |   19 +-
 src/mochiweb/mochiglobal.erl            |    4 +-
 src/mochiweb/mochihex.erl               |    5 +-
 src/mochiweb/mochijson.erl              |    4 +-
 src/mochiweb/mochijson2.erl             |   64 +-
 src/mochiweb/mochilists.erl             |    2 +-
 src/mochiweb/mochilogfile2.erl          |    2 +-
 src/mochiweb/mochinum.erl               |    2 +-
 src/mochiweb/mochitemp.erl              |    3 +-
 src/mochiweb/mochiutf8.erl              |    7 +-
 src/mochiweb/mochiweb.app.src           |    6 +-
 src/mochiweb/mochiweb.erl               |   46 +-
 src/mochiweb/mochiweb_acceptor.erl      |   11 +-
 src/mochiweb/mochiweb_charref.erl       | 2387 +++++++++++++++++++++++---
 src/mochiweb/mochiweb_cookies.erl       |   42 +-
 src/mochiweb/mochiweb_cover.erl         |    2 +-
 src/mochiweb/mochiweb_echo.erl          |   15 +-
 src/mochiweb/mochiweb_headers.erl       |  129 ++-
 src/mochiweb/mochiweb_html.erl          |  132 ++-
 src/mochiweb/mochiweb_http.erl          |  108 +-
 src/mochiweb/mochiweb_io.erl            |    5 +-
 src/mochiweb/mochiweb_mime.erl          |  399 ++++-
 src/mochiweb/mochiweb_multipart.erl     |   98 +-
 src/mochiweb/mochiweb_request.erl       |  477 +++---
 src/mochiweb/mochiweb_request_tests.erl |  121 ++-
 src/mochiweb/mochiweb_response.erl      |   44 +-
 src/mochiweb/mochiweb_socket.erl        |   15 +-
 src/mochiweb/mochiweb_socket_server.erl |   80 +-
 src/mochiweb/mochiweb_util.erl          |   16 +-
 src/mochiweb/reloader.erl               |    4 +-
 32 files changed, 3460 insertions(+), 805 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/cbb8a550/src/mochiweb/mochifmt.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/mochifmt.erl b/src/mochiweb/mochifmt.erl
index 5bc6b9c..fc95e4f 100644
--- a/src/mochiweb/mochifmt.erl
+++ b/src/mochiweb/mochifmt.erl
@@ -369,8 +369,8 @@ parse_std_conversion([Type], Acc) ->
 %%
 %% Tests
 %%
--include_lib("eunit/include/eunit.hrl").
 -ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
 
 tokenize_test() ->
     {?MODULE, [{raw, "ABC"}]} = tokenize("ABC"),

http://git-wip-us.apache.org/repos/asf/couchdb/blob/cbb8a550/src/mochiweb/mochifmt_records.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/mochifmt_records.erl b/src/mochiweb/mochifmt_records.erl
index 2326d1d..7d166ff 100644
--- a/src/mochiweb/mochifmt_records.erl
+++ b/src/mochiweb/mochifmt_records.erl
@@ -9,11 +9,15 @@
 %%    M:format("{0.bar}", [#rec{bar=foo}]).
 %%    foo
 
--module(mochifmt_records, [Recs]).
+-module(mochifmt_records).
 -author('bob@mochimedia.com').
--export([get_value/2]).
+-export([new/1, get_value/3]).
 
-get_value(Key, Rec) when is_tuple(Rec) and is_atom(element(1, Rec)) ->
+new([{_Rec, RecFields}]=Recs) when is_list(RecFields) ->
+    {?MODULE, Recs}.
+
+get_value(Key, Rec, {?MODULE, Recs})
+  when is_tuple(Rec) and is_atom(element(1, Rec)) ->
     try begin
             Atom = list_to_existing_atom(Key),
             {_, Fields} = proplists:lookup(element(1, Rec), Recs),
@@ -21,7 +25,7 @@ get_value(Key, Rec) when is_tuple(Rec) and is_atom(element(1, Rec)) ->
         end
     catch error:_ -> mochifmt:get_value(Key, Rec)
     end;
-get_value(Key, Args) ->
+get_value(Key, Args, {?MODULE, _Recs}) ->
     mochifmt:get_value(Key, Args).
 
 get_rec_index(Atom, [Atom | _], Index) ->
@@ -33,6 +37,6 @@ get_rec_index(Atom, [_ | Rest], Index) ->
 %%
 %% Tests
 %%
--include_lib("eunit/include/eunit.hrl").
 -ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
 -endif.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/cbb8a550/src/mochiweb/mochifmt_std.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/mochifmt_std.erl b/src/mochiweb/mochifmt_std.erl
index d4d74f6..ea68c4a 100644
--- a/src/mochiweb/mochifmt_std.erl
+++ b/src/mochiweb/mochifmt_std.erl
@@ -3,28 +3,31 @@
 
 %% @doc Template module for a mochifmt formatter.
 
--module(mochifmt_std, []).
+-module(mochifmt_std).
 -author('bob@mochimedia.com').
--export([format/2, get_value/2, format_field/2, get_field/2, convert_field/2]).
+-export([new/0, format/3, get_value/3, format_field/3, get_field/3, convert_field/3]).
 
-format(Format, Args) ->
+new() ->
+    {?MODULE}.
+
+format(Format, Args, {?MODULE}=THIS) ->
     mochifmt:format(Format, Args, THIS).
 
-get_field(Key, Args) ->
+get_field(Key, Args, {?MODULE}=THIS) ->
     mochifmt:get_field(Key, Args, THIS).
 
-convert_field(Key, Args) ->
+convert_field(Key, Args, {?MODULE}) ->
     mochifmt:convert_field(Key, Args).
 
-get_value(Key, Args) ->
+get_value(Key, Args, {?MODULE}) ->
     mochifmt:get_value(Key, Args).
 
-format_field(Arg, Format) ->
+format_field(Arg, Format, {?MODULE}=THIS) ->
     mochifmt:format_field(Arg, Format, THIS).
 
 %%
 %% Tests
 %%
--include_lib("eunit/include/eunit.hrl").
 -ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
 -endif.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/cbb8a550/src/mochiweb/mochiglobal.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/mochiglobal.erl b/src/mochiweb/mochiglobal.erl
index c740b87..ea645b0 100644
--- a/src/mochiweb/mochiglobal.erl
+++ b/src/mochiweb/mochiglobal.erl
@@ -30,7 +30,7 @@ put(K, V) ->
 put(_K, V, Mod) ->
     Bin = compile(Mod, V),
     code:purge(Mod),
-    code:load_binary(Mod, atom_to_list(Mod) ++ ".erl", Bin),
+    {module, Mod} = code:load_binary(Mod, atom_to_list(Mod) ++ ".erl", Bin),
     ok.
 
 -spec delete(atom()) -> boolean().
@@ -77,8 +77,8 @@ term_to_abstract(Module, Getter, T) ->
 %%
 %% Tests
 %%
--include_lib("eunit/include/eunit.hrl").
 -ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
 get_put_delete_test() ->
     K = '$$test$$mochiglobal',
     delete(K),

http://git-wip-us.apache.org/repos/asf/couchdb/blob/cbb8a550/src/mochiweb/mochihex.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/mochihex.erl b/src/mochiweb/mochihex.erl
index 44a2aa7..796f3ad 100644
--- a/src/mochiweb/mochihex.erl
+++ b/src/mochiweb/mochihex.erl
@@ -8,9 +8,6 @@
 
 -export([to_hex/1, to_bin/1, to_int/1, dehex/1, hexdigit/1]).
 
-%% @type iolist() = [char() | binary() | iolist()]
-%% @type iodata() = iolist() | binary()
-
 %% @spec to_hex(integer | iolist()) -> string()
 %% @doc Convert an iolist to a hexadecimal string.
 to_hex(0) ->
@@ -68,8 +65,8 @@ to_bin([C1, C2 | Rest], Acc) ->
 %%
 %% Tests
 %%
--include_lib("eunit/include/eunit.hrl").
 -ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
 
 to_hex_test() ->
     "ff000ff1" = to_hex([255, 0, 15, 241]),

http://git-wip-us.apache.org/repos/asf/couchdb/blob/cbb8a550/src/mochiweb/mochijson.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/mochijson.erl b/src/mochiweb/mochijson.erl
index 2e3d145..d283189 100644
--- a/src/mochiweb/mochijson.erl
+++ b/src/mochiweb/mochijson.erl
@@ -15,8 +15,6 @@
 -define(INC_COL(S), S#decoder{column=1+S#decoder.column}).
 -define(INC_LINE(S), S#decoder{column=1, line=1+S#decoder.line}).
 
-%% @type iolist() = [char() | binary() | iolist()]
-%% @type iodata() = iolist() | binary()
 %% @type json_string() = atom | string() | binary()
 %% @type json_number() = integer() | float()
 %% @type json_array() = {array, [json_term()]}
@@ -406,8 +404,8 @@ tokenize(L=[C | _], S) when C >= $0, C =< $9; C == $- ->
 %%
 %% Tests
 %%
--include_lib("eunit/include/eunit.hrl").
 -ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
 
 %% testing constructs borrowed from the Yaws JSON implementation.
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/cbb8a550/src/mochiweb/mochijson2.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/mochijson2.erl b/src/mochiweb/mochijson2.erl
index bdf6d77..2b8d16e 100644
--- a/src/mochiweb/mochijson2.erl
+++ b/src/mochiweb/mochijson2.erl
@@ -40,9 +40,9 @@
 -module(mochijson2).
 -author('bob@mochimedia.com').
 -export([encoder/1, encode/1]).
--export([decoder/1, decode/1]).
+-export([decoder/1, decode/1, decode/2]).
 
-% This is a macro to placate syntax highlighters..
+%% This is a macro to placate syntax highlighters..
 -define(Q, $\").
 -define(ADV_COL(S, N), S#decoder{offset=N+S#decoder.offset,
                                  column=N+S#decoder.column}).
@@ -64,15 +64,14 @@
 -define(IS_WHITESPACE(C),
         (C =:= $\s orelse C =:= $\t orelse C =:= $\r orelse C =:= $\n)).
 
-%% @type iolist() = [char() | binary() | iolist()]
-%% @type iodata() = iolist() | binary()
 %% @type json_string() = atom | binary()
 %% @type json_number() = integer() | float()
 %% @type json_array() = [json_term()]
 %% @type json_object() = {struct, [{json_string(), json_term()}]}
+%% @type json_eep18_object() = {[{json_string(), json_term()}]}
 %% @type json_iolist() = {json, iolist()}
 %% @type json_term() = json_string() | json_number() | json_array() |
-%%                     json_object() | json_iolist()
+%%                     json_object() | json_eep18_object() | json_iolist()
 
 -record(encoder, {handler=null,
                   utf8=false}).
@@ -102,6 +101,14 @@ decoder(Options) ->
     State = parse_decoder_options(Options, #decoder{}),
     fun (O) -> json_decode(O, State) end.
 
+%% @spec decode(iolist(), [{format, proplist | eep18 | struct}]) -> json_term()
+%% @doc Decode the given iolist to Erlang terms using the given object format
+%%      for decoding, where proplist returns JSON objects as [{binary(), json_term()}]
+%%      proplists, eep18 returns JSON objects as {[binary(), json_term()]}, and struct
+%%      returns them as-is.
+decode(S, Options) ->
+    json_decode(S, parse_decoder_options(Options, #decoder{})).
+
 %% @spec decode(iolist()) -> json_term()
 %% @doc Decode the given iolist to Erlang terms.
 decode(S) ->
@@ -119,7 +126,10 @@ parse_encoder_options([{utf8, Switch} | Rest], State) ->
 parse_decoder_options([], State) ->
     State;
 parse_decoder_options([{object_hook, Hook} | Rest], State) ->
-    parse_decoder_options(Rest, State#decoder{object_hook=Hook}).
+    parse_decoder_options(Rest, State#decoder{object_hook=Hook});
+parse_decoder_options([{format, Format} | Rest], State)
+  when Format =:= struct orelse Format =:= eep18 orelse Format =:= proplist ->
+    parse_decoder_options(Rest, State#decoder{object_hook=Format}).
 
 json_encode(true, _State) ->
     <<"true">>;
@@ -139,6 +149,10 @@ json_encode([{K, _}|_] = Props, State) when (K =/= struct andalso
     json_encode_proplist(Props, State);
 json_encode({struct, Props}, State) when is_list(Props) ->
     json_encode_proplist(Props, State);
+json_encode({Props}, State) when is_list(Props) ->
+    json_encode_proplist(Props, State);
+json_encode({}, State) ->
+    json_encode_proplist([], State);
 json_encode(Array, State) when is_list(Array) ->
     json_encode_array(Array, State);
 json_encode({array, Array}, State) when is_list(Array) ->
@@ -318,8 +332,12 @@ decode1(B, S=#decoder{state=null}) ->
             decode_object(B, S1)
     end.
 
-make_object(V, #decoder{object_hook=null}) ->
+make_object(V, #decoder{object_hook=N}) when N =:= null orelse N =:= struct ->
     V;
+make_object({struct, P}, #decoder{object_hook=eep18}) ->
+    {P};
+make_object({struct, P}, #decoder{object_hook=proplist}) ->
+    P;
 make_object(V, #decoder{object_hook=Hook}) ->
     Hook(V).
 
@@ -559,8 +577,8 @@ tokenize(B, S=#decoder{offset=O}) ->
 %%
 %% Tests
 %%
--include_lib("eunit/include/eunit.hrl").
 -ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
 
 
 %% testing constructs borrowed from the Yaws JSON implementation.
@@ -838,12 +856,34 @@ float_test() ->
 
 handler_test() ->
     ?assertEqual(
-       {'EXIT',{json_encode,{bad_term,{}}}},
-       catch encode({})),
-    F = fun ({}) -> [] end,
+       {'EXIT',{json_encode,{bad_term,{x,y}}}},
+       catch encode({x,y})),
+    F = fun ({x,y}) -> [] end,
     ?assertEqual(
        <<"[]">>,
-       iolist_to_binary((encoder([{handler, F}]))({}))),
+       iolist_to_binary((encoder([{handler, F}]))({x, y}))),
     ok.
 
+encode_empty_test_() ->
+    [{A, ?_assertEqual(<<"{}">>, iolist_to_binary(encode(B)))}
+     || {A, B} <- [{"eep18 {}", {}},
+                   {"eep18 {[]}", {[]}},
+                   {"{struct, []}", {struct, []}}]].
+
+encode_test_() ->
+    P = [{<<"k">>, <<"v">>}],
+    JSON = iolist_to_binary(encode({struct, P})),
+    [{atom_to_list(F),
+      ?_assertEqual(JSON, iolist_to_binary(encode(decode(JSON, [{format, F}]))))}
+     || F <- [struct, eep18, proplist]].
+
+format_test_() ->
+    P = [{<<"k">>, <<"v">>}],
+    JSON = iolist_to_binary(encode({struct, P})),
+    [{atom_to_list(F),
+      ?_assertEqual(A, decode(JSON, [{format, F}]))}
+     || {F, A} <- [{struct, {struct, P}},
+                   {eep18, {P}},
+                   {proplist, P}]].
+
 -endif.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/cbb8a550/src/mochiweb/mochilists.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/mochilists.erl b/src/mochiweb/mochilists.erl
index 8981e7b..d93b241 100644
--- a/src/mochiweb/mochilists.erl
+++ b/src/mochiweb/mochilists.erl
@@ -55,8 +55,8 @@ get_value(Key, Proplist, Default) ->
 %%
 %% Tests
 %%
--include_lib("eunit/include/eunit.hrl").
 -ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
 
 set_defaults_test() ->
     ?assertEqual(

http://git-wip-us.apache.org/repos/asf/couchdb/blob/cbb8a550/src/mochiweb/mochilogfile2.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/mochilogfile2.erl b/src/mochiweb/mochilogfile2.erl
index c34ee73..b4a7e3c 100644
--- a/src/mochiweb/mochilogfile2.erl
+++ b/src/mochiweb/mochilogfile2.erl
@@ -57,8 +57,8 @@ find_last_newline(FD, Location) ->
 %%
 %% Tests
 %%
--include_lib("eunit/include/eunit.hrl").
 -ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
 name_test() ->
     D = mochitemp:mkdtemp(),
     FileName = filename:join(D, "open_close_test.log"),

http://git-wip-us.apache.org/repos/asf/couchdb/blob/cbb8a550/src/mochiweb/mochinum.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/mochinum.erl b/src/mochiweb/mochinum.erl
index 3c96b13..c52b15c 100644
--- a/src/mochiweb/mochinum.erl
+++ b/src/mochiweb/mochinum.erl
@@ -243,8 +243,8 @@ frexp_int(F) ->
 %%
 %% Tests
 %%
--include_lib("eunit/include/eunit.hrl").
 -ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
 
 int_ceil_test() ->
     ?assertEqual(1, int_ceil(0.0001)),

http://git-wip-us.apache.org/repos/asf/couchdb/blob/cbb8a550/src/mochiweb/mochitemp.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/mochitemp.erl b/src/mochiweb/mochitemp.erl
index bb23d2a..dda7863 100644
--- a/src/mochiweb/mochitemp.erl
+++ b/src/mochiweb/mochitemp.erl
@@ -135,8 +135,9 @@ normalize_dir(L) ->
 %%
 %% Tests
 %%
--include_lib("eunit/include/eunit.hrl").
 -ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
+
 pushenv(L) ->
     [{K, os:getenv(K)} || K <- L].
 popenv(L) ->

http://git-wip-us.apache.org/repos/asf/couchdb/blob/cbb8a550/src/mochiweb/mochiutf8.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/mochiutf8.erl b/src/mochiweb/mochiutf8.erl
index 206e118..28f28c1 100644
--- a/src/mochiweb/mochiutf8.erl
+++ b/src/mochiweb/mochiutf8.erl
@@ -5,8 +5,9 @@
 %%      invalid bytes.
 
 -module(mochiutf8).
--export([valid_utf8_bytes/1, codepoint_to_bytes/1, bytes_to_codepoints/1]).
--export([bytes_foldl/3, codepoint_foldl/3, read_codepoint/1, len/1]).
+-export([valid_utf8_bytes/1, codepoint_to_bytes/1, codepoints_to_bytes/1]).
+-export([bytes_to_codepoints/1, bytes_foldl/3, codepoint_foldl/3]).
+-export([read_codepoint/1, len/1]).
 
 %% External API
 
@@ -192,8 +193,8 @@ invalid_utf8_indexes(<<>>, _N, Acc) ->
 %%
 %% Tests
 %%
--include_lib("eunit/include/eunit.hrl").
 -ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
 
 binary_skip_bytes_test() ->
     ?assertEqual(<<"foo">>,

http://git-wip-us.apache.org/repos/asf/couchdb/blob/cbb8a550/src/mochiweb/mochiweb.app.src
----------------------------------------------------------------------
diff --git a/src/mochiweb/mochiweb.app.src b/src/mochiweb/mochiweb.app.src
index 37a21fb..baced90 100644
--- a/src/mochiweb/mochiweb.app.src
+++ b/src/mochiweb/mochiweb.app.src
@@ -1,9 +1,9 @@
 %% This is generated from src/mochiweb.app.src
 {application, mochiweb,
  [{description, "MochiMedia Web Server"},
-  {vsn, "1.4.1"},
+  {vsn, "2.4.2"},
   {modules, []},
   {registered, []},
-  {mod, {mochiweb_app, []}},
   {env, []},
-  {applications, [kernel, stdlib, crypto, inets]}]}.
+  {applications, [kernel, stdlib, crypto, inets, ssl, xmerl,
+                  compiler, syntax_tools]}]}.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/cbb8a550/src/mochiweb/mochiweb.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/mochiweb.erl b/src/mochiweb/mochiweb.erl
index 3118028..250beb5 100644
--- a/src/mochiweb/mochiweb.erl
+++ b/src/mochiweb/mochiweb.erl
@@ -6,22 +6,9 @@
 -module(mochiweb).
 -author('bob@mochimedia.com').
 
--export([start/0, stop/0]).
 -export([new_request/1, new_response/1]).
 -export([all_loaded/0, all_loaded/1, reload/0]).
-
-%% @spec start() -> ok
-%% @doc Start the MochiWeb server.
-start() ->
-    ensure_started(crypto),
-    application:start(mochiweb).
-
-%% @spec stop() -> ok
-%% @doc Stop the MochiWeb server.
-stop() ->
-    Res = application:stop(mochiweb),
-    application:stop(crypto),
-    Res.
+-export([ensure_started/1]).
 
 reload() ->
     [c:l(Module) || Module <- all_loaded()].
@@ -78,8 +65,8 @@ new_response({Request, Code, Headers}) ->
                           Code,
                           mochiweb_headers:make(Headers)).
 
-%% Internal API
-
+%% @spec ensure_started(App::atom()) -> ok
+%% @doc Start the given App if it has not been started already.
 ensure_started(App) ->
     case application:start(App) of
         ok ->
@@ -88,12 +75,11 @@ ensure_started(App) ->
             ok
     end.
 
-
 %%
 %% Tests
 %%
--include_lib("eunit/include/eunit.hrl").
 -ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
 
 -record(treq, {path, body= <<>>, xreply= <<>>}).
 
@@ -112,7 +98,7 @@ with_server(Transport, ServerFun, ClientFun) ->
         ssl ->
             ServerOpts0 ++ [{ssl, true}, {ssl_opts, ssl_cert_opts()}]
     end,
-    {ok, Server} = mochiweb_http:start(ServerOpts),
+    {ok, Server} = mochiweb_http:start_link(ServerOpts),
     Port = mochiweb_socket_server:get(Server, port),
     Res = (catch ClientFun(Transport, Port)),
     mochiweb_http:stop(Server),
@@ -123,6 +109,8 @@ request_test() ->
     "/foo/bar/baz wibble quux" = R:get(path),
     ok.
 
+-define(LARGE_TIMEOUT, 60).
+
 single_http_GET_test() ->
     do_GET(plain, 1).
 
@@ -135,11 +123,13 @@ multiple_http_GET_test() ->
 multiple_https_GET_test() ->
     do_GET(ssl, 3).
 
-hundred_http_GET_test() ->
-    do_GET(plain, 100).
+hundred_http_GET_test_() -> % note the underscore
+    {timeout, ?LARGE_TIMEOUT,
+     fun() -> ?assertEqual(ok, do_GET(plain,100)) end}.
 
-hundred_https_GET_test() ->
-    do_GET(ssl, 100).
+hundred_https_GET_test_() -> % note the underscore
+    {timeout, ?LARGE_TIMEOUT,
+     fun() -> ?assertEqual(ok, do_GET(ssl,100)) end}.
 
 single_128_http_POST_test() ->
     do_POST(plain, 128, 1).
@@ -165,11 +155,13 @@ multiple_100k_http_POST_test() ->
 multiple_100K_https_POST_test() ->
     do_POST(ssl, 102400, 3).
 
-hundred_128_http_POST_test() ->
-    do_POST(plain, 128, 100).
+hundred_128_http_POST_test_() -> % note the underscore
+    {timeout, ?LARGE_TIMEOUT,
+     fun() -> ?assertEqual(ok, do_POST(plain, 128, 100)) end}.
 
-hundred_128_https_POST_test() ->
-    do_POST(ssl, 128, 100).
+hundred_128_https_POST_test_() -> % note the underscore
+    {timeout, ?LARGE_TIMEOUT,
+     fun() -> ?assertEqual(ok, do_POST(ssl, 128, 100)) end}.
 
 do_GET(Transport, Times) ->
     PathPrefix = "/whatever/",

http://git-wip-us.apache.org/repos/asf/couchdb/blob/cbb8a550/src/mochiweb/mochiweb_acceptor.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/mochiweb_acceptor.erl b/src/mochiweb/mochiweb_acceptor.erl
index 893f99b..efedfbd 100644
--- a/src/mochiweb/mochiweb_acceptor.erl
+++ b/src/mochiweb/mochiweb_acceptor.erl
@@ -18,14 +18,13 @@ init(Server, Listen, Loop) ->
     case catch mochiweb_socket:accept(Listen) of
         {ok, Socket} ->
             gen_server:cast(Server, {accepted, self(), timer:now_diff(now(), T1)}),
-            case mochiweb_socket:after_accept(Socket) of
-                ok -> call_loop(Loop, Socket);
-                {error, _} -> exit(normal)
-            end;
+            call_loop(Loop, Socket);
         {error, closed} ->
             exit(normal);
         {error, timeout} ->
             init(Server, Listen, Loop);
+        {error, esslaccept} ->
+            exit(normal);
         Other ->
             error_logger:error_report(
               [{application, mochiweb},
@@ -36,6 +35,8 @@ init(Server, Listen, Loop) ->
 
 call_loop({M, F}, Socket) ->
     M:F(Socket);
+call_loop({M, F, [A1]}, Socket) ->
+    M:F(Socket, A1);
 call_loop({M, F, A}, Socket) ->
     erlang:apply(M, F, [Socket | A]);
 call_loop(Loop, Socket) ->
@@ -44,6 +45,6 @@ call_loop(Loop, Socket) ->
 %%
 %% Tests
 %%
--include_lib("eunit/include/eunit.hrl").
 -ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
 -endif.


Mime
View raw message