Skip to content
This repository
Newer
Older
100644 876 lines (787 sloc) 33.892 kb
a919ac12 »
2008-12-27 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
1 -module(app_test).
2 -include("../include/tftest.hrl").
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
3 -include_lib("ibrowse/include/ibrowse.hrl").
a919ac12 »
2008-12-27 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
4 -compile(export_all).
5
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
6
7 %% Way to invoke just one test
8 start([F]) ->
9 ?line {ok, _} = ibrowse:start_link(),
9e12baf8 » vinoski
2009-12-20 proper handling of "/" appmod with excluded paths (patch from wde)
10 apply(app_test, F, []),
11 ibrowse:stop().
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
12
a919ac12 »
2008-12-27 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
13 start() ->
c74a92e8 » capflam
2012-04-25 Add options to configure deflate compression behaviour
14 io:format("\n ==== MAIN TESTS ==== \n\n", []),
1a7f0028 »
2008-12-27 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
15 ?line {ok, _} = ibrowse:start_link(),
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
16 test_server_options(),
a919ac12 »
2008-12-27 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
17 test1(),
18 test2(),
b1b7abe2 » vinoski
2009-01-03 add test for "OPTIONS *" request to app_test.erl
19 test3(),
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
20 test_appmod(),
21 test_streamcontent(),
9e12baf8 » vinoski
2009-12-20 proper handling of "/" appmod with excluded paths (patch from wde)
22 sendfile_get(),
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
23 test_json(),
24 test_post(),
25 test_flush(),
26 test_expires(),
27 test_reentrant(),
28 test_cgi_redirect(),
29 test_php_handler(),
30 test_arg_rewrite(),
31 test_shaper(),
32 test_sslaccept_timeout(),
33 test_throw(),
34 test_too_many_headers(),
35 test_index_files(),
36 test_websocket(),
37 test_embedded_id_dir(),
9e12baf8 » vinoski
2009-12-20 proper handling of "/" appmod with excluded paths (patch from wde)
38 ibrowse:stop().
a919ac12 »
2008-12-27 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
39
40
41 test1() ->
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
42 io:format("test1\n",[]),
977c1238 » vinoski
2009-08-02 1. Fix redirect bug reported by James Lee.
43 L = lists:seq(1, 100),
3bd8b6fe »
2009-01-18 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
44 SELF = self(),
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
45 Pids = lists:map(fun(I) ->
3bd8b6fe »
2009-01-18 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
46 spawn(fun() -> slow_client(I, SELF) end)
47 end, L),
48 ?line ok = allow_connects(Pids, 5),
49 ?line ok = collect_pids(Pids).
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
50
3bd8b6fe »
2009-01-18 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
51
52 collect_pids([]) ->
53 ok;
54 collect_pids(Pids) ->
55 receive
56 {Pid, done} ->
57 collect_pids(lists:delete(Pid, Pids))
58 end.
59
60
61 %% max 5 connectors at a time
62 allow_connects([], _) ->
9e12baf8 » vinoski
2009-12-20 proper handling of "/" appmod with excluded paths (patch from wde)
63 io:format(" test1: all pids connected \n",[]);
3bd8b6fe »
2009-01-18 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
64 allow_connects(Pids, 0) ->
65 receive
66 {Pid, connected} ->
67 allow_connects(lists:delete(Pid, Pids), 1)
68 end;
69 allow_connects(Pids, I) ->
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
70 receive
3bd8b6fe »
2009-01-18 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
71 {Pid, allow} ->
72 Pid ! allow,
73 allow_connects(Pids, I-1);
74 {Pid, connected} ->
75 allow_connects(lists:delete(Pid, Pids), I+1)
76 end.
77
78
79
80 slow_client(I, Top) ->
81 Top ! {self(), allow},
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
82 receive
3bd8b6fe »
2009-01-18 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
83 allow ->
84 ok
85 end,
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
86 ?line {ok, C} = gen_tcp:connect(localhost, 8000, [{active, false},
3bd8b6fe »
2009-01-18 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
87 {packet, http}]),
88 Top ! {self(), connected},
977c1238 » vinoski
2009-08-02 1. Fix redirect bug reported by James Lee.
89 ?line ok = gen_tcp:send(C, "GET /1000.txt HTTP/1.1\r\n"
90 "Host: localhost:8000\r\n\r\n"),
3bd8b6fe »
2009-01-18 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
91 ?line {ok, Sz} = get_cont_len(C),
92 ?line ok = inet:setopts(C, [binary,{packet, 0}]),
93 read_loop(C, I, Sz),
94 Top ! {self(), done}.
95
96 read_loop(C, _I, Sz) when Sz - 200000 < 0 ->
97 ?line ok = gen_tcp:close(C),
98 ok;
99 read_loop(C, I, Sz) ->
100 ?line {ok, B} = gen_tcp:recv(C, 0),
101 %%io:format("(I=~p Sz=~p) ", [I, size(B)]),
102 timer:sleep(2),
103 read_loop(C, I, Sz - size(B)).
104
105
106 get_cont_len(C) ->
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
107 ?line {value, {http_header, _,_,_, LenStr}} =
3bd8b6fe »
2009-01-18 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
108 lists:keysearch('Content-Length', 3, tftest:get_headers(C)),
109 {ok, list_to_integer(LenStr)}.
110
111
112
a919ac12 »
2008-12-27 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
113
114 test2() ->
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
115 io:format("test2\n",[]),
977c1238 » vinoski
2009-08-02 1. Fix redirect bug reported by James Lee.
116 blkget(10).
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
117
118
119 blkget(0) ->
120 ok;
121 blkget(I) ->
122 spawn(fun() ->
123 {ok, C} = gen_tcp:connect(localhost, 8000, [{active, false}]),
977c1238 » vinoski
2009-08-02 1. Fix redirect bug reported by James Lee.
124 gen_tcp:send(C, "GET /2000.txt HTTP/1.1\r\n"
125 "Host: localhost:8000\r\n\r\n"),
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
126 gen_tcp:recv(C, 200),
127 timer:sleep(5000),
128 exit(normal)
129 end),
130 blkget(I-1).
131
132
133
a919ac12 »
2008-12-27 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
134
135 test3() ->
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
136 io:format("test3\n",[]),
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
137 ?line {ok, "200", _Headers, []} = ibrowse:send_req("http://localhost:8000",
138 [], head),
1a7f0028 »
2008-12-27 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
139 ok.
140
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
141 test_server_options() ->
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
142 io:format("server_options_test\n",[]),
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
143 {ok, S} = gen_tcp:connect("localhost", 8000, [{packet, raw}, list,
144 {active, false}]),
b1b7abe2 » vinoski
2009-01-03 add test for "OPTIONS *" request to app_test.erl
145 ok = gen_tcp:send(S, "OPTIONS * HTTP/1.1\r\nHost: localhost\r\n\r\n"),
146 inet:setopts(S, [{packet, http}]),
147 ?line ok = server_options_recv(S),
148 gen_tcp:close(S).
149
150 server_options_recv(S) ->
151 do_server_options_recv(S, []).
152 server_options_recv(_S, [http_eoh|_]) ->
153 ok;
154 server_options_recv(S, [{http_response,{1,1},200,"OK"}|_]=Hdrs) ->
155 do_server_options_recv(S, Hdrs);
156 server_options_recv(S, [{http_header,_,'Server',_,_}|_]=Hdrs) ->
157 do_server_options_recv(S, Hdrs);
158 server_options_recv(S, [{http_header,_,'Allow',_,"GET, HEAD, OPTIONS, PUT, POST, DELETE"}|_]=Hdrs) ->
159 do_server_options_recv(S, Hdrs);
160 server_options_recv(S, [{http_header,_,'Content-Length',_,"0"}|_]=Hdrs) ->
161 do_server_options_recv(S, Hdrs);
977c1238 » vinoski
2009-08-02 1. Fix redirect bug reported by James Lee.
162 server_options_recv(S, [{http_header,_,'Date',_,_}|_]=Hdrs) ->
163 do_server_options_recv(S, Hdrs);
164 server_options_recv(_S, [Hdr|_Hdrs]) ->
165 io:format("unexpected server options HTTP header: ~p~n", [Hdr]),
b1b7abe2 » vinoski
2009-01-03 add test for "OPTIONS *" request to app_test.erl
166 error.
167 do_server_options_recv(S, Hdrs) ->
977c1238 » vinoski
2009-08-02 1. Fix redirect bug reported by James Lee.
168 {ok, Hdr} = gen_tcp:recv(S, 0, 5000),
b1b7abe2 » vinoski
2009-01-03 add test for "OPTIONS *" request to app_test.erl
169 server_options_recv(S, [Hdr|Hdrs]).
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
170
8c7d18db » vinoski
2009-01-18 add longer timeout for sendfile_get test
171 -define(SENDFILE_GET_TIMEOUT, 120000).
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
172
173 sendfile_get() ->
174 io:format("sendfile_get\n",[]),
2e6b7f4b » vinoski
2009-09-08 reduce loop to 5 for sendfile_get test
175 L = lists:seq(1, 5),
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
176 SELF = self(),
177 K1 = lists:map(
178 fun(_) ->
179 spawn(fun() ->
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
180 ?line {ok, "200", _Headers, _} =
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
181 ibrowse:send_req(
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
182 "http://localhost:8000/1000.txt",
8c7d18db » vinoski
2009-01-18 add longer timeout for sendfile_get test
183 [], get, [], [], ?SENDFILE_GET_TIMEOUT),
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
184 SELF ! {self(), k1, done}
185 end)
186 end, L),
187
188 K2 = lists:map(
189 fun(_) ->
190 spawn(fun() ->
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
191 ?line {ok, "200", _Headers, _} =
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
192 ibrowse:send_req(
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
193 "http://localhost:8000/2000.txt",
8c7d18db » vinoski
2009-01-18 add longer timeout for sendfile_get test
194 [], get, [], [], ?SENDFILE_GET_TIMEOUT),
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
195 SELF ! {self(), k2, done}
196 end)
197 end, L),
198
977c1238 » vinoski
2009-08-02 1. Fix redirect bug reported by James Lee.
199 K3 = lists:map(
200 fun(_) ->
201 spawn(fun() ->
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
202 ?line {ok, "200", _Headers, _} =
977c1238 » vinoski
2009-08-02 1. Fix redirect bug reported by James Lee.
203 ibrowse:send_req(
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
204 "http://localhost:8000/3000.txt",
977c1238 » vinoski
2009-08-02 1. Fix redirect bug reported by James Lee.
205 [], get, [], [], ?SENDFILE_GET_TIMEOUT),
206 SELF ! {self(), k3, done}
207 end)
208 end, L),
5e1d1ec9 »
2009-05-28 prepare for 1.82
209
210
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
211 collect(K1, 1, k1),
212 collect(K2, 1, k2),
977c1238 » vinoski
2009-08-02 1. Fix redirect bug reported by James Lee.
213 collect(K3, 1, k3),
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
214 io:format("\n",[]),
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
215 ok.
216
217 collect([], _, _) ->
218 ok;
219 collect(L, Count, Tag) ->
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
220 receive
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
221 {Pid, Tag, done} ->
222 io:format("(~p ~p)", [Tag, Count]),
223 collect(lists:delete(Pid, L), Count+1, Tag)
8c7d18db » vinoski
2009-01-18 add longer timeout for sendfile_get test
224 after ?SENDFILE_GET_TIMEOUT ->
c91e8979 »
2009-01-14 git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
225 io:format("TIMEOUT ~p\n~p~n",[process_info(self()), L]),
226 ?line exit(timeout)
227 end.
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
228
9e12baf8 » vinoski
2009-12-20 proper handling of "/" appmod with excluded paths (patch from wde)
229 -define(APPMOD_HEADER, "Appmod-Called").
230
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
231 test_appmod() ->
9e12baf8 » vinoski
2009-12-20 proper handling of "/" appmod with excluded paths (patch from wde)
232 io:format("appmod_test\n",[]),
233 Uri1 = "http://localhost:8002/",
234 ?line {ok, "200", Headers1, _} = ibrowse:send_req(Uri1, [], get),
235 ?line "true" = proplists:get_value(?APPMOD_HEADER, Headers1),
236 Uri2 = "http://localhost:8003/",
237 ?line {ok, "200", Headers2, _} = ibrowse:send_req(Uri2, [], get),
238 ?line "true" = proplists:get_value(?APPMOD_HEADER, Headers2),
239 Uri3 = "http://localhost:8003/icons/layout.gif",
240 ?line {ok, "200", Headers3, _} = ibrowse:send_req(Uri3, [], get),
241 ?line false = proplists:get_value(?APPMOD_HEADER, Headers3, false),
242 Uri4 = "http://localhost:8004/non_root_appmod",
243 ?line {ok, "200", Headers4, _} = ibrowse:send_req(Uri4, [], get),
244 ?line "true" = proplists:get_value(?APPMOD_HEADER, Headers4),
245 ok.
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
246
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
247 test_streamcontent() ->
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
248 io:format("streamcontent_test\n",[]),
5da72a3b » vinoski
2010-05-12 Allow "stream processes" to close the client socket
249 Uri1 = "http://localhost:8000/streamtest/1",
250 ?line {ok, "200", Headers1, Body1} = ibrowse:send_req(Uri1, [], get),
251 ?line "chunked" = proplists:get_value("Transfer-Encoding", Headers1),
252 ?line Body1 = "this is an iolist",
253
254 %% The following test attempts to ensure that Yaws doesn't report the
255 %% following problem due to the application closing the socket and then
256 %% handing it back to Yaws via stream_process_end.
257 %%
258 %% =ERROR REPORT==== 12-May-2010::00:27:05 ===
259 %% Yaws process died: {{badmatch,{error,einval}},
260 %% [{yaws,setopts,3},
261 %% {yaws,http_recv_request,2},
262 %% {yaws,do_http_get_headers,2},
263 %% {yaws,http_get_headers,2},
264 %% {yaws_server,aloop,3},
265 %% {yaws_server,acceptor0,2},
266 %% {proc_lib,init_p_do_apply,3}]}
267 %%
268 %% The test uses plain sockets because closing the remote end makes
269 %% ibrowse unhappy. Unfortunately the only way to currently check that
270 %% the above message doesn't appear is to turn on traffic tracing in
271 %% yaws.conf and then visually check the file logs/report.log.
272 %%
273 Path = "/streamtest/2",
274 {ok, Sock} = gen_tcp:connect("localhost", 8000, [binary, {active, false}]),
275 gen_tcp:send(Sock, "GET " ++ Path ++ " HTTP/1.1\r\nHost: localhost\r\n\r\n"),
276 inet:setopts(Sock, [{packet, http}]),
277 {ok, Len} = recv_hdrs(Sock),
278 inet:setopts(Sock, [{packet, raw}, {active, false}]),
279 {ok, <<"closing the socket">>} = gen_tcp:recv(Sock, Len),
280 timer:sleep(10000),
281 gen_tcp:close(Sock),
913aff8e » vinoski
2009-09-19 Use iolists instead of binaries for streamcontent_from_pid data, and
282 ok.
9e12baf8 » vinoski
2009-12-20 proper handling of "/" appmod with excluded paths (patch from wde)
283
183ec82c » vinoski
2011-06-01 restore removed jsonrpc:call/3
284 -define(JSON_URI, "http://localhost:8005/jsontest").
285
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
286 test_json() ->
15454bcd » vinoski
2011-05-01 JSON-RPC 2.0 support
287 io:format("json_test\n",[]),
288 io:format(" param array1\n", []),
289 ?line ok = do_json({struct, [{"jsonrpc", "2.0"},
290 {"method", "subtract"},
291 {"params", {array, [42, 23]}},
292 {"id", 1}]},
293 {struct, [{"jsonrpc", "2.0"},
294 {"result", 19},
295 {"id", 1}]}),
296 io:format(" param array2\n", []),
297 ?line ok = do_json({struct, [{"jsonrpc", "2.0"},
298 {"method", "subtract"},
299 {"params", {array, [23, 42]}},
300 {"id", 2}]},
301 {struct, [{"jsonrpc", "2.0"},
302 {"result", -19},
303 {"id", 2}]}),
183ec82c » vinoski
2011-06-01 restore removed jsonrpc:call/3
304 inets:start(),
305 io:format(" encode/decode\n", []),
306 ?line {ok,{response,[19]}} = jsonrpc:call(?JSON_URI, [],
307 {call, "subtract", [42, 23]}),
15454bcd » vinoski
2011-05-01 JSON-RPC 2.0 support
308 io:format(" param obj1\n", []),
309 ?line ok = do_json({struct, [{"jsonrpc", "2.0"},
310 {"method", "subtract"},
311 {"params", {struct, [{"subtrahend", 23},
312 {"minuend", 42}]}},
313 {"id", 3}]},
314 {struct, [{"jsonrpc", "2.0"},
315 {"result", 19},
316 {"id", 3}]}),
317 io:format(" param obj2\n", []),
318 ?line ok = do_json({struct, [{"jsonrpc", "2.0"},
319 {"method", "subtract"},
320 {"params", {struct, [{"minuend", 42},
321 {"subtrahend", 23}]}},
322 {"id", 4}]},
323 {struct, [{"jsonrpc", "2.0"},
324 {"result", 19},
325 {"id", 4}]}),
326 io:format(" notif1\n", []),
327 ?line ok = do_json({struct, [{"jsonrpc", "2.0"},
328 {"method", "update"},
329 {"params", {array, [1,2,3,4,5]}}]},
330 notification),
331 io:format(" notif2\n", []),
332 ?line ok = do_json({struct, [{"jsonrpc", "2.0"},
333 {"method", "foobar"}]},
334 notification),
335 io:format(" missing method\n", []),
336 ?line ok = do_json({struct, [{"jsonrpc", "2.0"},
337 {"method", "foobar"},
338 {"id", "1"}]},
339 {struct, [{"jsonrpc", "2.0"},
340 {"id", "1"},
341 {"error", {struct,
342 [{"code", -32601},
343 {"message", "method not found"}]}
344 }]}),
345 io:format(" invalid json\n", []),
346 InvalidJson = "{\"jsonrpc\": \"2.0\", \"method\": \"foobar,"
347 "\"params\": \"bar\", \"baz]",
348 ?line ok = do_json(InvalidJson,
349 {struct, [{"jsonrpc", "2.0"},
350 {"id", null},
351 {"error", {struct,
352 [{"code", -32700},
353 {"message", "parse error"}]}
354 }]},
355 no_encode),
356 io:format(" invalid req1\n", []),
357 InvalidReq1 = "{\"jsonrpc\": \"2.0\", \"method\": 1, \"params\": \"bar\"}",
358 ?line ok = do_json(InvalidReq1,
359 {struct, [{"jsonrpc", "2.0"},
360 {"id", null},
361 {"error", {struct,
362 [{"code", -32600},
363 {"message", "invalid request"}]}
364 }]},
365 no_encode),
366 io:format(" invalid params\n", []),
367 InvalidReq2 = "{\"jsonrpc\": \"2.0\", \"method\": \"x\","
368 "\"params\": \"bar\"}",
369 ?line ok = do_json(InvalidReq2,
370 {struct, [{"jsonrpc", "2.0"},
371 {"id", null},
372 {"error", {struct,
373 [{"code", -32602},
374 {"message", "invalid params"}]}
375 }]},
376 no_encode),
377 io:format(" invalid batch json\n", []),
378 InvalidJsonBatch = "[ {\"jsonrpc\": \"2.0\", \"method\": \"sum\","
379 "\"params\": [1,2,4],\"id\": \"1\"},{\"jsonrpc\": \"2.0\", \"method\" ]",
380 ?line ok = do_json(InvalidJsonBatch,
381 {struct, [{"jsonrpc", "2.0"},
382 {"id", null},
383 {"error", {struct,
384 [{"code", -32700},
385 {"message", "parse error"}]}
386 }]},
387 no_encode),
388 io:format(" empty batch\n", []),
389 EmptyBatch = "[]",
390 ?line ok = do_json(EmptyBatch,
391 {struct, [{"jsonrpc", "2.0"},
392 {"id", null},
393 {"error", {struct,
394 [{"code", -32600},
395 {"message", "invalid request"}]}
396 }]},
397 no_encode),
398 io:format(" invalid batch1\n", []),
399 BogusBatch1 = "[1]",
400 ?line ok = do_json(BogusBatch1,
401 {array,
402 [{struct, [{"jsonrpc", "2.0"},
403 {"id", null},
404 {"error", {struct,
405 [{"code", -32600},
406 {"message", "invalid request"}]}
407 }]}]},
408 no_encode),
409 io:format(" invalid batch2\n", []),
410 BogusBatch2 = "[1,2,3]",
411 ?line ok = do_json(BogusBatch2,
412 {array,
413 [{struct, [{"jsonrpc", "2.0"},
414 {"id", null},
415 {"error", {struct,
416 [{"code", -32600},
417 {"message", "invalid request"}]}
418 }]},
419 {struct, [{"jsonrpc", "2.0"},
420 {"id", null},
421 {"error", {struct,
422 [{"code", -32600},
423 {"message", "invalid request"}]}
424 }]},
425 {struct, [{"jsonrpc", "2.0"},
426 {"id", null},
427 {"error", {struct,
428 [{"code", -32600},
429 {"message", "invalid request"}]}
430 }]}]},
431 no_encode),
432 io:format(" mixed batch\n", []),
433 MixedBatch = "
434 [{\"jsonrpc\":\"2.0\",\"method\":\"sum\",\"params\": [1,2,4], \"id\": \"1\"},
435 {\"jsonrpc\":\"2.0\",\"method\":\"notify_hello\", \"params\": [7]},
436 {\"jsonrpc\":\"2.0\",\"method\":\"subtract\",\"params\":[42,23],
437 \"id\":\"2\"},
438 {\"foo\": \"boo\"},
439 {\"jsonrpc\":\"2.0\",\"method\":\"foo.get\",
440 \"params\":{\"name\": \"myself\"}, \"id\": \"5\"},
441 {\"jsonrpc\": \"2.0\", \"method\": \"get_data\", \"id\": \"9\"}]",
442 ?line ok = do_json(MixedBatch,
443 {array,
444 [{struct,[{"jsonrpc","2.0"},
445 {"result",7},
446 {"id","1"}]},
447 {struct,[{"jsonrpc","2.0"},
448 {"result",19},{"id","2"}]},
449 {struct,[{"jsonrpc","2.0"},
450 {"error",
451 {struct,[{"code",-32600},
452 {"message","invalid request"}]}},
453 {"id",null}]},
454 {struct,[{"jsonrpc","2.0"},
455 {"error",
456 {struct,[{"code",-32601},
457 {"message","method not found"}]}},
458 {"id","5"}]},
459 {struct,[{"jsonrpc","2.0"},
460 {"result",{array,["hello",5]}},
461 {"id","9"}]}]},
462 no_encode),
463 io:format(" all-notification batch\n", []),
464 NotifBatch = "[
465 {\"jsonrpc\": \"2.0\", \"method\": \"notify_sum\", \"params\": [1,2,4]},
466 {\"jsonrpc\": \"2.0\", \"method\": \"notify_hello\", \"params\": [7]}]",
467 ?line ok = do_json(NotifBatch, notification, no_encode),
468 ok.
469
470 do_json(Req, Expected) ->
471 do_json(Req, Expected, encode).
472 do_json(Req, notification, NeedEncode) ->
473 ?line {ok, "200", Headers, Body} = json_send(Req, NeedEncode),
474 ?line "application/json" = proplists:get_value("Content-Type", Headers),
475 ?line [] = Body,
476 ok;
477 do_json(Req, {struct, _}=Expected, NeedEncode) ->
478 ?line {ok, "200", Headers, Body} = json_send(Req, NeedEncode),
479 ?line "application/json" = proplists:get_value("Content-Type", Headers),
480 check_json(Expected, Body, true);
481 do_json(Req, {array, Array}, NeedEncode) ->
482 ?line {ok, "200", Headers, Body} = json_send(Req, NeedEncode),
483 ?line "application/json" = proplists:get_value("Content-Type", Headers),
484 ?line {ok, {array, GotArray}} = json2:decode_string(Body),
485 lists:map(fun({Obj, Got}) ->
486 ?line ok = check_json(Obj, Got, false)
487 end, lists:zip(Array, GotArray)),
488 ok.
489
490 check_json({struct, _}=Exp, Body, true) ->
491 ?line {ok, DecodedBody} = json2:decode_string(Body),
492 check_json(Exp, DecodedBody);
493 check_json({struct, _}=Exp, Body, false) ->
494 check_json(Exp, Body).
495 check_json({struct, Members}, DecodedBody) ->
496 lists:foreach(fun({Key, Val}) ->
497 ?line Val = jsonrpc:s(DecodedBody, Key)
498 end, Members),
499 ok.
500
501 json_send(Req) ->
502 json_send(Req, encode).
503 json_send(Req, encode) ->
504 json_send(json2:encode(Req), no_encode);
505 json_send(Req, no_encode) ->
183ec82c » vinoski
2011-06-01 restore removed jsonrpc:call/3
506 Uri = ?JSON_URI,
15454bcd » vinoski
2011-05-01 JSON-RPC 2.0 support
507 ReqHdrs = [{content_type, "application/json"}],
508 ibrowse:send_req(Uri, ReqHdrs, post, Req).
509
5da72a3b » vinoski
2010-05-12 Allow "stream processes" to close the client socket
510 recv_hdrs(Sock) ->
511 recv_hdrs(Sock, 0).
512 recv_hdrs(Sock, Len) ->
513 inet:setopts(Sock, [{active, once}]),
514 receive
515 {http, Sock, http_eoh} ->
516 {ok, Len};
517 {http, Sock, {http_error, Error}} ->
518 {error, Error};
519 {http, Sock, {http_header, _, 'Content-Length', _, LenStr}} ->
520 recv_hdrs(Sock, list_to_integer(LenStr));
521 {http, Sock, {http_header, _, _, _, _}} ->
522 recv_hdrs(Sock, Len);
523 {http, Sock, {http_response, _, 200, "OK"}} ->
524 recv_hdrs(Sock, Len);
525 Other ->
526 {error, {"unexpected message", Other}}
527 end.
528
4f3545f4 » capflam
2011-05-27 add tests for post and chunked transfer-encoding requests
529
530 %% partial_post_size = 2048000
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
531 test_post() ->
4f3545f4 » capflam
2011-05-27 add tests for post and chunked transfer-encoding requests
532 io:format("post_test\n",[]),
533 small_post(),
534 large_post(),
535 small_chunked_post(),
536 large_chunked_post(),
537 ok.
538
539 small_post() ->
540 io:format(" small post\n",[]),
541 {ok, Bin} = file:read_file("../../www/1000.txt"),
542 Sz = size(Bin),
543 Uri = "http://localhost:8006/posttest/" ++ integer_to_list(Sz),
544 Hdrs = [{content_length, Sz}, {content_type, "binary/octet-stream"}],
545 ?line {ok, "200", _, _} = ibrowse:send_req(Uri, Hdrs, post, Bin, []),
546 ok.
547
548 large_post() ->
549 io:format(" large post\n",[]),
550 {ok, Bin} = file:read_file("../../www/10000.txt"),
551 Sz = size(Bin),
552 Uri = "http://localhost:8006/posttest/" ++ integer_to_list(Sz),
553 Hdrs = [{content_length, Sz}, {content_type, "binary/octet-stream"}],
554 ?line {ok, "200", _, _} = ibrowse:send_req(Uri, Hdrs, post, Bin, []),
555 ok.
556
557 small_chunked_post() ->
558 io:format(" small chunked post\n",[]),
559 {ok, Bin} = file:read_file("../../www/3000.txt"),
560 Sz = size(Bin),
561 Uri = "http://localhost:8006/posttest/chunked/" ++ integer_to_list(Sz),
562 Hdrs = [{content_type, "binary/octet-stream"}],
563 Opts = [{transfer_encoding, {chunked, 1000*1000}}],
564 ?line {ok, "200", _, _} = ibrowse:send_req(Uri, Hdrs, post, Bin, Opts),
565 ok.
566
567 large_chunked_post() ->
568 io:format(" large chunked post\n",[]),
569 {ok, Bin} = file:read_file("../../www/10000.txt"),
570 Sz = size(Bin),
571 Uri = "http://localhost:8006/posttest/chunked/" ++ integer_to_list(Sz),
572 Hdrs = [{content_type, "binary/octet-stream"}],
573
574 %% size of chunk _IS_NOT_ a multiple of partial_post_size
575 Opts1 = [{transfer_encoding, {chunked, 4000*1000}}],
576 ?line {ok, "200", _, _} = ibrowse:send_req(Uri, Hdrs, post, Bin, Opts1),
577
578 %% size of chunk _IS_ a multiple of partial_post_size
579 Opts2 = [{transfer_encoding, {chunked, 4000*1024}}],
580 ?line {ok, "200", _, _} = ibrowse:send_req(Uri, Hdrs, post, Bin, Opts2),
581 ok.
582
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
583 test_flush() ->
9730337a » capflam
2012-01-06 Add tests for flush mechanisms
584 io:format("flush_test\n",[]),
585 flush_small_post(),
586 flush_large_post(),
587 flush_chunked_post(),
588 flush_small_get(),
589 flush_large_get(),
590 flush_chunked_get(),
591 ok.
592
593 flush_small_post() ->
594 io:format(" flush small post\n",[]),
595 {ok, Bin} = file:read_file("../../www/1000.txt"),
596 Sz = size(Bin),
597 Uri1 = "http://localhost:8006/flushtest/" ++ integer_to_list(Sz),
598 Uri2 = "http://localhost:8006/hello.txt",
599 Hdrs = [{content_length, Sz}, {content_type, "binary/octet-stream"}],
600 {ok, ConnPid} = ibrowse:spawn_worker_process("localhost", 8006),
601 ?line {ok, "200", _, _} = ibrowse:send_req_direct(ConnPid, Uri1, Hdrs, post, Bin, []),
602 ?line {ok, "200", _, _} = ibrowse:send_req_direct(ConnPid, Uri2, [], get, [], []),
603 ibrowse:stop_worker_process(ConnPid),
604 ok.
605
606 flush_large_post() ->
607 io:format(" flush large post\n",[]),
608 {ok, Bin} = file:read_file("../../www/10000.txt"),
609 Sz = size(Bin),
610 Uri1 = "http://localhost:8006/flushtest/" ++ integer_to_list(Sz),
611 Uri2 = "http://localhost:8006/hello.txt",
612 Hdrs = [{content_length, Sz}, {content_type, "binary/octet-stream"}],
613 {ok, ConnPid} = ibrowse:spawn_worker_process("localhost", 8006),
614 ?line {ok, "200", _, _} = ibrowse:send_req_direct(ConnPid, Uri1, Hdrs, post, Bin, []),
615 ?line {ok, "200", _, _} = ibrowse:send_req_direct(ConnPid, Uri2, [], get, [], []),
616 ibrowse:stop_worker_process(ConnPid),
617 ok.
618
619 flush_chunked_post() ->
620 io:format(" flush chunked post\n",[]),
621 {ok, Bin} = file:read_file("../../www/10000.txt"),
622 Sz = size(Bin),
623 Uri1 = "http://localhost:8006/flushtest/chunked/" ++ integer_to_list(Sz),
624 Uri2 = "http://localhost:8006/hello.txt",
625 Hdrs = [{content_type, "binary/octet-stream"}],
626 Opts = [{transfer_encoding, {chunked, 4000*1000}}],
627 {ok, ConnPid} = ibrowse:spawn_worker_process("localhost", 8006),
628 ?line {ok, "200", _, _} = ibrowse:send_req_direct(ConnPid, Uri1, Hdrs, post, Bin, Opts),
629 ?line {ok, "200", _, _} = ibrowse:send_req_direct(ConnPid, Uri2, [], get, [], []),
630 ibrowse:stop_worker_process(ConnPid),
631 ok.
632
633 flush_small_get() ->
634 io:format(" flush small get\n",[]),
635 {ok, Bin} = file:read_file("../../www/1000.txt"),
636 Sz = size(Bin),
637 Uri = "http://localhost:8006/hello.txt",
638 Hdrs = [{content_length, Sz}, {content_type, "binary/octet-stream"}],
639 {ok, ConnPid} = ibrowse:spawn_worker_process("localhost", 8006),
640 ?line {ok, "200", _, _} = ibrowse:send_req_direct(ConnPid, Uri, Hdrs, get, Bin, []),
641 ?line {ok, "200", _, _} = ibrowse:send_req_direct(ConnPid, Uri, [], get, [], []),
642 ibrowse:stop_worker_process(ConnPid),
643 ok.
644
645 flush_large_get() ->
646 io:format(" flush large get\n",[]),
647 {ok, Bin} = file:read_file("../../www/10000.txt"),
648 Sz = size(Bin),
649 Uri = "http://localhost:8006/hello.txt",
650 Hdrs = [{content_length, Sz}, {content_type, "binary/octet-stream"}],
651 {ok, ConnPid} = ibrowse:spawn_worker_process("localhost", 8006),
652 ?line {ok, "200", _, _} = ibrowse:send_req_direct(ConnPid, Uri, Hdrs, get, Bin, []),
653 ?line {ok, "200", _, _} = ibrowse:send_req_direct(ConnPid, Uri, [], get, [], []),
654 ibrowse:stop_worker_process(ConnPid),
655 ok.
656
657 flush_chunked_get() ->
658 io:format(" flush chunked post\n",[]),
659 {ok, Bin} = file:read_file("../../www/10000.txt"),
660 Uri = "http://localhost:8006/hello.txt",
661 Hdrs = [{content_type, "binary/octet-stream"}],
662 Opts = [{transfer_encoding, {chunked, 4000*1000}}],
663 {ok, ConnPid} = ibrowse:spawn_worker_process("localhost", 8006),
664 ?line {ok, "200", _, _} = ibrowse:send_req(Uri, Hdrs, get, Bin, Opts),
665 ?line {ok, "200", _, _} = ibrowse:send_req(Uri, [], get, [], []),
666 ibrowse:stop_worker_process(ConnPid),
667 ok.
668
4f3545f4 » capflam
2011-05-27 add tests for post and chunked transfer-encoding requests
669
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
670 test_expires() ->
aab5243b » capflam
2011-05-27 add a test for the 'expires' directive
671 io:format("expires_test\n", []),
bf30d1a3 » vinoski
2011-10-19 move some test files
672 Uri = "http://localhost:8006/hello.txt",
aab5243b » capflam
2011-05-27 add a test for the 'expires' directive
673 ?line {ok, "200", Hdrs, _} = ibrowse:send_req(Uri, [], get),
674
675 %% Retrieve max-age value to test Expires header
676 ?line "max-age=" ++ Rest = proplists:get_value("Cache-Control", Hdrs),
677 ?line Secs = list_to_integer(Rest),
678
679 %% Convert Date and Expires into datetime()
680 ?line Date = proplists:get_value("Date", Hdrs),
681 ?line Expires = proplists:get_value("Expires", Hdrs),
682 Date_DT = httpd_util:convert_request_date(Date),
683 Expires_DT = httpd_util:convert_request_date(Expires),
684
685 %% Check if Expires value is equal to "Date + max-age"
686 Val1 = calendar:datetime_to_gregorian_seconds(Date_DT) + Secs,
687 Val2 = calendar:datetime_to_gregorian_seconds(Expires_DT),
688 ?line Val1 = Val2,
689 ok.
690
52e8852b » capflam
2011-05-27 add tests for reentrant requests (scripts returning {page, P})
691
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
692 test_reentrant() ->
52e8852b » capflam
2011-05-27 add tests for reentrant requests (scripts returning {page, P})
693 io:format("reentrant_test\n", []),
694 reentrant_test_status(),
695 reentrant_test_delayed_headers(),
696 ok.
697
698 reentrant_test_status() ->
699 io:format(" status code\n", []),
700 Uri = "http://localhost:8006/reentranttest/status",
701 ?line {ok, "201", _, _} = ibrowse:send_req(Uri, [], post, <<"blob">>, []),
702 ok.
703
704 reentrant_test_delayed_headers() ->
705 io:format(" delayed headers\n", []),
706 Uri = "http://localhost:8006/reentranttest/delayed_headers",
707 ?line {ok, "200", Hdrs, _} = ibrowse:send_req(Uri, [], get),
708 ?line "no-cache" = proplists:get_value("Cache-Control", Hdrs),
709 ?line "static-tag" = proplists:get_value("Etag", Hdrs),
710 ?line "true" = proplists:get_value("X-Delayed-Header", Hdrs),
711 ok.
712
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
713 test_cgi_redirect() ->
96dd91e0 » vinoski
2011-10-19 fix CGI redirect HTTP status bug
714 io:format("cgi_redirect_test\n", []),
715 Uri = "http://localhost:8008/cgi-bin/redirect_test.cgi",
716 ?line {ok, "302", Hdrs, _} = ibrowse:send_req(Uri, [], get),
717 ?line true = lists:any(fun({"Location", _}) -> true; (_) -> false end, Hdrs),
718 ok.
52e8852b » capflam
2011-05-27 add tests for reentrant requests (scripts returning {page, P})
719
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
720 test_php_handler() ->
61181690 » capflam
2011-05-27 add a test for external interpretation of php scripts
721 io:format("php_handler_test\n", []),
722 Uri = "http://localhost:8006/test.php",
bf30d1a3 » vinoski
2011-10-19 move some test files
723 {ok, Binary} = file:read_file("./www/test.php"),
61181690 » capflam
2011-05-27 add a test for external interpretation of php scripts
724 Content = binary_to_list(Binary),
725 ?line {ok, "200", _, Content} = ibrowse:send_req(Uri, [], get),
726 ok.
727
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
728 test_arg_rewrite() ->
de9ca043 » capflam
2011-05-27 add tests for argument rewriting
729 io:format("arg_rewrite_test\n", []),
730 arg_rewrite_test_rewrite(),
731 arg_rewrite_test_redirect(),
732 arg_rewrite_test_response(),
733 ok.
734
735 arg_rewrite_test_rewrite() ->
736 io:format(" rewrite\n", []),
737 Uri = "http://localhost:8006/rewrite",
738 ?line {ok, "200", Hdrs, _} = ibrowse:send_req(Uri, [], get),
bf30d1a3 » vinoski
2011-10-19 move some test files
739 ?line "text/plain" = proplists:get_value("Content-Type", Hdrs),
740 {ok, FI} = file:read_file_info("./www/hello.txt"),
de9ca043 » capflam
2011-05-27 add tests for argument rewriting
741 Etag = yaws:make_etag(FI),
742 ?line Etag = proplists:get_value("Etag", Hdrs),
743 ok.
744
745 arg_rewrite_test_redirect() ->
746 io:format(" redirect\n", []),
747 Uri = "http://localhost:8006/redirect",
748 ?line {ok, "301", Hdrs, _} = ibrowse:send_req(Uri, [], get),
749 ?line "http://www.yakaz.com" = proplists:get_value("Location", Hdrs),
750 ok.
751
752
753 arg_rewrite_test_response() ->
754 io:format(" response\n", []),
755 Uri = "http://localhost:8006/response",
756 ?line {ok, "200", Hdrs, Content} = ibrowse:send_req(Uri, [], get),
757 ?line "text/plain" = proplists:get_value("Content-Type", Hdrs),
bf30d1a3 » vinoski
2011-10-19 move some test files
758 ?line "Goodbye, Cruel World!" = Content,
de9ca043 » capflam
2011-05-27 add tests for argument rewriting
759 ok.
760
761
ba8e4dfa » capflam
2011-05-27 add a test for request shaping
762
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
763 test_shaper() ->
ba8e4dfa » capflam
2011-05-27 add a test for request shaping
764 io:format("shaper_test\n", []),
765 Uri = "http://localhost:8007/",
766 ?line {ok, "200", _, _} = ibrowse:send_req(Uri, [], get),
767 ?line {ok, "200", _, _} = ibrowse:send_req(Uri, [], get),
768 ?line {ok, "200", _, _} = ibrowse:send_req(Uri, [], get),
769 ?line {ok, "503", _, _} = ibrowse:send_req(Uri, [], get),
770 ok.
771
772
6b56d419 » capflam
2012-01-09 Update the testsuite accordingly
773
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
774 test_sslaccept_timeout() ->
6b56d419 » capflam
2012-01-09 Update the testsuite accordingly
775 io:format("sslaccept_tout_test\n", []),
776 {ok, Sock} = gen_tcp:connect("localhost", 8443, [binary, {active, true}]),
777 ?line ok = receive
778 {tcp_closed, Sock} -> ok
779 after
780 %% keepalive_timeout is set to 10 secs. So, wait 15 secs
781 %% before returning an error
782 15000 -> error
783 end,
784 gen_tcp:close(Sock),
785 ok.
786
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
787 test_throw() ->
6b526651 » vinoski
2012-05-04 report uncaught exception as server error 500
788 io:format("throw test\n", []),
789 Uri = "http://localhost:8009/",
790 ?line {ok, "500", _, _} = ibrowse:send_req(Uri, [], get),
791 ok.
6b56d419 » capflam
2012-01-09 Update the testsuite accordingly
792
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
793 test_too_many_headers() ->
563c7efe » vinoski
2012-05-11 add new HTTP status codes from RFC 6585
794 io:format("too many request headers test\n", []),
795 Uri = "http://localhost:8009/",
796 Hdrs = [{link, "<compact.css>; rel=\"stylesheet\"; title=\"compact\""} || _ <- lists:seq(0, 1001)],
797 ?line {ok, "431", _, _} = ibrowse:send_req(Uri, Hdrs, get),
798 ok.
6b56d419 » capflam
2012-01-09 Update the testsuite accordingly
799
6c6f62fa » capflam
2012-07-11 Add index_files directive into the server part configuration
800
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
801 test_index_files() ->
6c6f62fa » capflam
2012-07-11 Add index_files directive into the server part configuration
802 io:format("index_files test\n", []),
803 %% "/" should be redirected to "/testdir", then to "/testdir/" and finally
804 %% get "/testdir/index.html"
805 Uri0 = "http://localhost:8010/",
806 ?line {ok, Bin} = file:read_file("../../www/testdir/index.html"),
807 Content = binary_to_list(Bin),
808 ?line {ok, "302", Hdrs1, _} = ibrowse:send_req(Uri0, [], get),
809 ?line Uri1 = proplists:get_value("Location", Hdrs1),
810 ?line "http://localhost:8010/testdir" = Uri1,
811 ?line {ok, "302", Hdrs2, _} = ibrowse:send_req(Uri1, [], get),
812 ?line Uri2 = proplists:get_value("Location", Hdrs2),
813 ?line "http://localhost:8010/testdir/" = Uri2,
814 ?line {ok, "200", _, Content} = ibrowse:send_req(Uri2, [], get),
815 ok.
816
940ea3a4 » jbothma
2012-07-31 Add basic websocket test.
817 %% Do handshake, then send "hello" in a text frame
818 %% and check that "hello" is echoed back.
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
819 test_websocket() ->
940ea3a4 » jbothma
2012-07-31 Add basic websocket test.
820 OpenHeads = "GET /websockets_example_endpoint.yaws HTTP/1.1\r\n"
821 "Host: localhost\r\n"
822 "Upgrade: websocket\r\n"
823 "Connection: Upgrade\r\n"
824 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"
825 "Origin: http://localhost\r\n"
826 "Sec-WebSocket-Version: 13\r\n\r\n",
827 Opts = [{send_timeout, 2000},
828 binary,
829 {packet, 0},
830 {active, false}],
831 {ok, Sock} = gen_tcp:connect(localhost, 8000, Opts),
832 ok = gen_tcp:send(Sock, OpenHeads),
833 {ok, Packet} = gen_tcp:recv(Sock, 0, 2000),
834 AcceptLines = re:split(Packet, "[\r\n]+", [{return, list}, trim]),
835 %% Check that exactly the expected lines are there, in any order
836 4 = length(AcceptLines),
837 true = lists:member("HTTP/1.1 101 Switching Protocols", AcceptLines),
838 true = lists:member("Upgrade: websocket", AcceptLines),
839 true = lists:member("Connection: Upgrade", AcceptLines),
840 true = lists:member("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=",
841 AcceptLines),
842
843 %% Text frame "hello" with mask "aaaa"
844 Frame =
845 <<129, 133, "aaaa", 38722669838:5/integer-unit:8>>,
846 ok = gen_tcp:send(Sock, Frame),
847 ExpectFrame = <<129, 5, "hello">>,
848 {ok, ExpectFrame} = gen_tcp:recv(Sock, 0, 2000).
849
66f50e67 » vinoski
2012-08-24 make sure "rebar eunit" passes
850 test_embedded_id_dir() ->
851 Id = "id_dir_test",
852 GconfList = [{id, Id},
853 {logdir, "./logs"},
854 {ebin_dir, ["./ebin"]}],
855 Docroot = yaws:tmpdir(),
856 SconfList = [{port, 9999},
857 {servername, Id},
858 {listen, {127,0,0,1}},
859 {docroot, Docroot}],
860 {ok, _SCList, _GC, _ChildSpecs} = yaws_api:embedded_start_conf(
861 Docroot, SconfList, GconfList, Id),
862 try
863 {ok,
864 {file_info, _, directory, read_write, _, _, _, _, _, _, _, _, _, _}} =
865 file:read_file_info(yaws:id_dir(Id)),
866 ok
867 after
868 ok = file:del_dir(yaws:id_dir(Id))
869 end.
940ea3a4 » jbothma
2012-07-31 Add basic websocket test.
870
9e12baf8 » vinoski
2009-12-20 proper handling of "/" appmod with excluded paths (patch from wde)
871 %% used for appmod tests
872 %%
5da72a3b » vinoski
2010-05-12 Allow "stream processes" to close the client socket
873 out(_A) ->
9e12baf8 » vinoski
2009-12-20 proper handling of "/" appmod with excluded paths (patch from wde)
874 %% add our special header to mark that we were here
875 [{status, 200},
876 {header, {?APPMOD_HEADER, "true"}}].
Something went wrong with that request. Please try again.