Subversion Repositories SE.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12 7u83 1
-module(mochiweb_http_tests).
2
 
3
-include_lib("eunit/include/eunit.hrl").
4
 
5
-ifdef(gen_tcp_r15b_workaround).
6
 
7
-define(SHOULD_HAVE_BUG, true).
8
 
9
-else.
10
 
11
-define(SHOULD_HAVE_BUG, false).
12
 
13
-endif.
14
 
15
has_acceptor_bug_test_() ->
16
    {setup, fun start_server/0, fun mochiweb_http:stop/1,
17
     fun has_acceptor_bug_tests/1}.
18
 
19
start_server() ->
20
    application:start(inets),
21
    {ok, Pid} = mochiweb_http:start_link([{port, 0},
22
					  {loop, fun responder/1}]),
23
    Pid.
24
 
25
has_acceptor_bug_tests(Server) ->
26
    Port = mochiweb_socket_server:get(Server, port),
27
    [{"1000 should be fine even with the bug",
28
      ?_assertEqual(false, (has_bug(Port, 1000)))},
29
     {"10000 should trigger the bug if present",
30
      ?_assertEqual((?SHOULD_HAVE_BUG),
31
		    (has_bug(Port, 10000)))}].
32
 
33
responder(Req) ->
34
    mochiweb_request:respond({200,
35
			      [{"Content-Type", "text/html"}],
36
			      ["<html><body>Hello</body></html>"]},
37
			     Req).
38
 
39
has_bug(Port, Len) ->
40
    case httpc:request(get,
41
		       {"http://127.0.0.1:" ++ integer_to_list(Port) ++ "/",
42
			[{"X-Random", lists:duplicate(Len, $a)}]},
43
		       [], [])
44
	of
45
      {error, socket_closed_remotely} -> true;
46
      {ok,
47
       {{"HTTP/1.1", 200, "OK"}, _,
48
	"<html><body>Hello</body></html>"}} ->
49
	  false;
50
      {ok, {{"HTTP/1.1", 400, "Bad Request"}, _, []}} -> false
51
    end.