4
%% Copyright Ericsson AB 2004-2011. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
21
-module(http_format_SUITE).
22
-author('ingela@erix.ericsson.se').
24
-include_lib("common_test/include/ct.hrl").
25
-include("test_server_line.hrl").
26
-include("http_internal.hrl").
28
%% Test server specific exports
29
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, init_per_group/2,end_per_group/2, init_per_testcase/2, end_per_testcase/2]).
31
%% Test cases must be exported.
32
-export([ chunk_decode/1, chunk_encode/1,
33
chunk_extensions_otp_6005/1, chunk_decode_otp_6264/1,
34
chunk_decode_empty_chunk_otp_6511/1,
35
chunk_decode_trailer/1,
36
http_response/1, http_request/1, validate_request_line/1,
37
esi_parse_headers/1, cgi_parse_headers/1,
38
is_absolut_uri/1, convert_netscapecookie_date/1]).
40
suite() -> [{ct_hooks,[ts_install_cth]}].
43
[{group, chunk}, http_response, http_request,
44
validate_request_line, {group, script}, is_absolut_uri,
45
convert_netscapecookie_date].
48
[{script, [], [esi_parse_headers, cgi_parse_headers]},
50
[chunk_decode, chunk_encode, chunk_extensions_otp_6005,
51
chunk_decode_otp_6264,
52
chunk_decode_empty_chunk_otp_6511,
53
chunk_decode_trailer]}].
55
init_per_suite(Config) ->
58
end_per_suite(_Config) ->
61
init_per_group(_GroupName, Config) ->
64
end_per_group(_GroupName, Config) ->
68
init_per_testcase(_, Config) ->
69
Dog = test_server:timetrap(?t:minutes(1)),
70
NewConfig = lists:keydelete(watchdog, 1, Config),
71
[{watchdog, Dog} | NewConfig].
73
end_per_testcase(_, Config) ->
74
Dog = ?config(watchdog, Config),
75
test_server:timetrap_cancel(Dog),
78
%%-------------------------------------------------------------------------
79
%% Test cases starts here.
80
%%-------------------------------------------------------------------------
83
%%-------------------------------------------------------------------------
85
["Test http_chunk:decode/3"];
86
chunk_decode(suite) ->
88
chunk_decode(Config) when is_list(Config) ->
89
ReqHeaders = #http_request_h{'transfer-encoding' = "chunked"},
90
ChunkedBody = "A" ++ ?CRLF ++ "1234567890" ++ ?CRLF ++ "4" ++
91
?CRLF ++ "HEJ!" ++ ?CRLF ++ "0" ++ ?CRLF ++ ?CRLF,
92
{ok, {Headers, Body}} =
93
http_chunk:decode(list_to_binary(ChunkedBody),
94
?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
95
"1234567890HEJ!" = binary_to_list(Body),
96
%% When the "chunked" is removed by the decoding the header
97
%% will become empty in this case i.e. undefined!
98
NewReqHeaders = http_chunk:handle_headers(ReqHeaders, Headers),
99
undefined = NewReqHeaders#http_request_h.'transfer-encoding',
101
NewChunkedBody = ["A" ++ [?CR], [?LF] ++ "12345", "67890" ++ ?CRLF ++ "4"
102
++ ?CRLF ++ "HEJ!" ++ ?CRLF ++ "0" ++ [?CR],
105
{Module, Function, Args} =
106
http_chunk:decode(list_to_binary(hd(NewChunkedBody)),
107
?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
109
{_, Body} = parse(Module, Function, Args, tl(NewChunkedBody)),
110
"1234567890HEJ!" = binary_to_list(Body),
114
%%-------------------------------------------------------------------------
115
chunk_extensions_otp_6005(doc) ->
116
["Make sure so called extensions are ignored"];
117
chunk_extensions_otp_6005(suite) ->
119
chunk_extensions_otp_6005(Config) when is_list(Config)->
120
ChunkedBody = "A;ignore this" ++ ?CRLF ++ "1234567890" ++
121
?CRLF ++ "4" ++ ?CRLF ++ "HEJ!"++ ?CRLF ++ "0" ++
122
";extensionname=extensionvalue;foo=bar" ++ ?CRLF ++ ?CRLF,
123
{ok, {["content-length:14"], Body}} =
124
http_chunk:decode(list_to_binary(ChunkedBody),
125
?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
126
"1234567890HEJ!" = binary_to_list(Body),
128
ChunkedBody1 = ["A;", "ignore this" ++ [?CR], [?LF] ++ "1234567890" ++
129
?CRLF ++ "4" ++ ?CRLF ++ "HEJ!"++ ?CRLF ++ "0" ++
130
";extensionname=extensionvalue;foo=bar" ++ ?CRLF ++ ?CRLF],
132
{Module1, Function1, Args1} =
133
http_chunk:decode(list_to_binary(hd(ChunkedBody1)),
134
?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
136
{_, NewBody} = parse(Module1, Function1, Args1, tl(ChunkedBody1)),
137
"1234567890HEJ!" = binary_to_list(NewBody),
140
%%-------------------------------------------------------------------------
141
chunk_decode_otp_6264(doc) ->
142
["Check that 0 in the body does not count as the last chunk"];
143
chunk_decode_otp_6264(suite) ->
145
chunk_decode_otp_6264(Config) when is_list(Config)->
146
ChunkedBody = "A;ignore this" ++ ?CRLF ++ "1234567890" ++
147
?CRLF ++ "4" ++ ?CRLF ++ "0123"++ ?CRLF ++ "0" ++
148
";extensionname=extensionvalue;foo=bar" ++ ?CRLF ++ ?CRLF,
149
{ok, {["content-length:14"], Body}} =
150
http_chunk:decode(list_to_binary(ChunkedBody),
151
?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
152
"12345678900123" = binary_to_list(Body),
154
NewChunkedBody = ["A" ++ [?CR], [?LF] ++ "12345", "67890" ++ ?CRLF ++ "1"
155
++ ?CRLF ++ "0" ++ ?CRLF ++ "0" ++ [?CR],
158
{Module, Function, Args} =
159
http_chunk:decode(list_to_binary(hd(NewChunkedBody)),
160
?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
162
{_, NewBody} = parse(Module, Function, Args, tl(NewChunkedBody)),
163
"12345678900" = binary_to_list(NewBody),
165
NewChunkedBody1 = ["A" ++ [?CR], [?LF] ++ "12345", "67890" ++ ?CRLF ++ "1"
166
++ ?CRLF ++ "0", ?CRLF ++ "0", [?CR], [?LF],
169
{Module1, Function1, Args1} =
170
http_chunk:decode(list_to_binary(hd(NewChunkedBody1)),
171
?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
173
{_, NewBody} = parse(Module1, Function1, Args1, tl(NewChunkedBody1)),
174
"12345678900" = binary_to_list(NewBody),
177
%%-------------------------------------------------------------------------
178
chunk_decode_empty_chunk_otp_6511(doc) ->
180
chunk_decode_empty_chunk_otp_6511(suite) ->
182
chunk_decode_empty_chunk_otp_6511(Config) when is_list(Config) ->
183
ChunkedBody = "0" ++ ?CRLF ++ ?CRLF,
184
{ok,{["content-length:0"],<<>>}} =
185
http_chunk:decode(list_to_binary(ChunkedBody),
186
?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
189
%%-------------------------------------------------------------------------
190
chunk_decode_trailer(doc) ->
191
["Make sure trailers are handled correctly. Trailers should"
192
"become new headers"];
193
chunk_decode_trailer(suite) ->
195
chunk_decode_trailer(Config) when is_list(Config)->
196
ChunkedBody = "1a; ignore-stuff-here" ++ ?CRLF ++
197
"abcdefghijklmnopqrstuvwxyz" ++ ?CRLF ++ "10" ++ ?CRLF
198
++ "1234567890abcdef" ++ ?CRLF ++ "0" ++ ?CRLF
199
++ "some-footer:some-value" ++ ?CRLF
200
++ "another-footer:another-value" ++ ?CRLF ++ ?CRLF,
202
{ok, {Headers, Body}} =
203
http_chunk:decode(list_to_binary(ChunkedBody),
204
?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
206
%% There is no guaranteed order of headers.
207
true = lists:member("content-length:42", Headers),
208
true = lists:member("some-footer:some-value", Headers),
209
true = lists:member("another-footer:another-value", Headers),
210
"abcdefghijklmnopqrstuvwxyz1234567890abcdef" = binary_to_list(Body),
212
ChunkedBody1 = "1a" ++ ?CRLF ++
213
"abcdefghijklmnopqrstuvwxyz" ++ ?CRLF ++ "10" ++ ?CRLF
214
++ "1234567890abcdef" ++ ?CRLF ++ "0" ++ ?CRLF
215
++ "some-footer:some-value" ++ ?CRLF ++ ?CRLF,
217
{ok, {Headers1, Body1}} =
218
http_chunk:decode(list_to_binary(ChunkedBody1),
219
?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
221
true = lists:member("content-length:42", Headers1),
222
true = lists:member("some-footer:some-value", Headers1),
223
false = lists:member("another-footer:another-value", Headers1),
224
"abcdefghijklmnopqrstuvwxyz1234567890abcdef" = binary_to_list(Body1),
227
ChunkedBody2 = ["1a", ?CRLF ++
228
"abcdefghijklmnopqrstuvwxyz" ++ ?CRLF ++ "10" ++ ?CRLF
229
++ "1234567890abcdef" ++ ?CRLF ++ "0", ";",
230
"ignore stuff here=foobar", ?CRLF ++
231
"some-footer:some-value", ?CRLF, ?CRLF],
233
{Module, Function, Args} =
234
http_chunk:decode(list_to_binary(hd(ChunkedBody2)),
235
?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
237
{_, NewBody} = parse(Module, Function, Args, tl(ChunkedBody2)),
238
"abcdefghijklmnopqrstuvwxyz1234567890abcdef" = binary_to_list(NewBody),
240
ChunkedBody3 = ["1a", ?CRLF ++
241
"abcdefghijklmnopqrstuvwxyz", ?CRLF ++ "10" ++ ?CRLF
242
++ "1234567890abcdef" ++ ?CRLF ++ "0" ++ ?CRLF
243
++ "some-footer:some-value", [?CR], [?LF] , ?CRLF],
245
{Module1, Function1, Args1} =
246
http_chunk:decode(list_to_binary(hd(ChunkedBody3)),
247
?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
249
{_, NewBody} = parse(Module1, Function1, Args1, tl(ChunkedBody3)),
250
"abcdefghijklmnopqrstuvwxyz1234567890abcdef" = binary_to_list(NewBody),
254
%%-------------------------------------------------------------------------
256
["Test http_chunk:encode/1 & http_chunk:encode_last/0"];
257
chunk_encode(suite) ->
259
chunk_encode(Config) when is_list(Config) ->
260
<<54, ?CR, ?LF, 102,111,111,98,97,114, ?CR, ?LF>> =
261
http_chunk:encode(list_to_binary("foobar")),
262
["6", ?CR, ?LF,"foobar", ?CR, ?LF] = http_chunk:encode("foobar"),
263
<<$0, ?CR, ?LF, ?CR, ?LF >> = http_chunk:encode_last(),
267
%%-------------------------------------------------------------------------
268
http_response(doc) ->
269
["Test httpc_response:parse*. This test case will simulate that the "
270
"message will be recived a little at the time on a socket and the "
271
"package may be broken up into smaller parts at arbitrary point."];
272
http_response(suite) ->
274
http_response(Config) when is_list(Config) ->
276
HttpHead1 = ["HTTP", "/1.1 ", "20", "0 ", "ok", [?CR, ?LF],
277
"content-length:83" ++ ?CRLF ++ "content", "-type:",
278
"text/html" ++ ?CRLF ++
279
"date:Thu, 28 Oct 2004 07:57:43 GMT" ++
280
[?CR], [?LF, ?CR, ?LF]],
284
#http_response_h{'content-length' = "83",
285
'content-type' = "text/html",
286
date = "Thu, 28 Oct 2004 07:57:43 GMT"},
288
parse(httpc_response, parse, [?HTTP_MAX_HEADER_SIZE, false],
291
HttpHead2 = ["HTTP/1.1 200", " ok", [?CR], [?LF] ++
292
"content-length:83" ++ ?CRLF ++ "content-type:",
293
"text/html" ++ ?CRLF ++
294
"date:" ++ "Thu, 28 Oct 2004 07:57:43 GMT" ++
299
#http_response_h{'content-length' = "83",
300
'content-type' = "text/html",
301
date = "Thu, 28 Oct 2004 07:57:43 GMT"},
303
parse(httpc_response, parse, [?HTTP_MAX_HEADER_SIZE, false],
306
HttpHead3 = ["HTTP/1.1 200 ", "ok", ?CRLF ++
307
"content-length:83" ++ ?CRLF ++ "content-type:",
308
"text/html" ++ ?CRLF ++
309
"date:" ++ "Thu, 28 Oct 2004 07:57:43 GMT" ++
310
[?CR, ?LF,?CR], [?LF]],
314
#http_response_h{'content-length' = "83",
315
'content-type' = "text/html",
316
date = "Thu, 28 Oct 2004 07:57:43 GMT"},
318
parse(httpc_response, parse, [?HTTP_MAX_HEADER_SIZE, false],
321
HttpBody = ["<HTML>\n<HEAD>\n<TITLE> dummy </TITLE>\n</HEAD>\n<BODY>\n",
322
"<H1>dummy</H1>\n</BODY>\n</HTML>\n"],
324
NewBody = lists:flatten(HttpBody),
325
Length = length(NewBody),
328
(httpc_response, whole_body, [<<>>,Length],
331
HttpBody1 = ["<HTML", ">\n<HEAD>", "\n<TITLE> dummy </TITLE>\n</HEAD>\n",
332
"<BODY>\n", "<H1>du", "mmy</H1>\n</BODY>\n</HTML>\n"],
334
NewBody1 = lists:flatten(HttpBody1),
335
Length1 = length(NewBody1),
336
NewBody1 = binary_to_list(parse
337
(httpc_response, whole_body,
338
[<<>>,Length1], HttpBody1)),
340
%%-------------------------------------------------------------------------
342
["Test httpd_request:parse* This test case will simulate that the "
343
"message will be recived a little at the time on a socket and the "
344
"package may be broken up into smaller parts at arbitrary point."];
345
http_request(suite) ->
347
http_request(Config) when is_list(Config) ->
349
HttpHead = ["GE", "T ", "http://www.erlang", ".org ", "HTTP",
350
"/1.1" ++ ?CRLF ++ "host:",
351
"www.erlang.org" ++ [?CR],
352
[?LF] ++ "te: " ++ ?CRLF, ?CRLF],
354
"http://www.erlang.org",
356
{#http_request_h{host = "www.erlang.org", te = []},
357
["te: ","host:www.erlang.org"]}, <<>>} =
358
parse(httpd_request, parse, [?HTTP_MAX_HEADER_SIZE], HttpHead),
360
HttpHead1 = ["GET http://www.erlang.org HTTP/1.1" ++
361
[?CR], [?LF, ?CR, ?LF]],
363
"http://www.erlang.org",
365
{#http_request_h{}, []}, <<>>} =
366
parse(httpd_request, parse, [?HTTP_MAX_HEADER_SIZE], HttpHead1),
369
HttpHead2 = ["GET http://www.erlang.org HTTP/1.1" ++
370
[?CR, ?LF, ?CR], [?LF]],
372
"http://www.erlang.org",
374
{#http_request_h{}, []}, <<>>} =
375
parse(httpd_request, parse, [?HTTP_MAX_HEADER_SIZE], HttpHead2),
377
%% Note the following body is not related to the headers above
378
HttpBody = ["<HTML>\n<HEAD>\n<TITLE> dummy </TITLE>\n</HEAD>\n<BODY>\n",
379
"<H1>dummy</H1>\n</BODY>\n</HTML>\n"],
381
NewBody = lists:flatten(HttpBody),
382
Length = length(NewBody),
385
(httpd_request, whole_body, [<<>>,Length], HttpBody)),
387
HttpBody1 = ["<HTML", ">\n<HEAD>", "\n<TITLE> dummy </TITLE>\n</HEAD>\n",
388
"<BODY>\n", "<H1>du", "mmy</H1>\n</BODY>\n</HTML>\n"],
390
NewBody1 = lists:flatten(HttpBody1),
391
Length1 = length(NewBody1),
394
(httpd_request, whole_body,
395
[<<>>, Length1], HttpBody1)),
397
%%-------------------------------------------------------------------------
398
validate_request_line(doc) ->
399
["Test httpd_request:validate/3. Makes sure you can not get past"
400
" the server_root and that the request is recognized by the server"
401
" and protcol version." ];
402
validate_request_line(suite) ->
404
validate_request_line(Config) when is_list(Config) ->
406
%% HTTP/0.9 only has GET requests
408
httpd_request:validate("GET", "http://www.erlang/org", "HTTP/0.9"),
409
{error, {not_supported,
410
{"HEAD", "http://www.erlang/org", "HTTP/0.9"}}} =
411
httpd_request:validate("HEAD", "http://www.erlang/org", "HTTP/0.9"),
412
{error, {not_supported,
413
{"TRACE", "http://www.erlang/org", "HTTP/0.9"}}} =
414
httpd_request:validate("TRACE", "http://www.erlang/org", "HTTP/0.9"),
415
{error, {not_supported,
416
{"POST", "http://www.erlang/org", "HTTP/0.9"}}} =
417
httpd_request:validate("POST", "http://www.erlang/org", "HTTP/0.9"),
420
ok = httpd_request:validate("HEAD", "http://www.erlang/org",
422
ok = httpd_request:validate("GET", "http://www.erlang/org",
424
ok = httpd_request:validate("POST","http://www.erlang/org",
426
ok = httpd_request:validate("TRACE","http://www.erlang/org",
428
{error, {not_supported,
429
{"FOOBAR", "http://www.erlang/org", "HTTP/1.1"}}} =
430
httpd_request:validate("FOOBAR", "http://www.erlang/org",
433
%% Attempts to get outside of server_root directory by relative links
434
ForbiddenUri = "http://127.0.0.1:8888/../../../../../etc/passwd",
435
{error, {bad_request, {forbidden, ForbiddenUri}}} =
436
httpd_request:validate("GET", ForbiddenUri, "HTTP/1.1"),
439
"http://127.0.0.1:8888/././././././../../../../../etc/passwd",
440
{error, {bad_request, {forbidden, ForbiddenUri2}}} =
441
httpd_request:validate("GET", ForbiddenUri2, "HTTP/1.1"),
443
HexForbiddenUri = "http://127.0.0.1:8888/%2e%2e/%2e%2e/%2e%2e/"
444
"home/ingela/test.html",
445
{error, {bad_request, {forbidden, HexForbiddenUri}}} =
446
httpd_request:validate("GET", HexForbiddenUri, "HTTP/1.1"),
449
"http://127.0.0.1:8888/foobar/../../../home/ingela/test.html",
450
{error, {bad_request, {forbidden, NewForbiddenUri}}} =
451
httpd_request:validate("GET", NewForbiddenUri, "HTTP/1.1"),
454
"http://127.0.0.1:8888/../home/ingela/test.html",
455
{error, {bad_request, {forbidden, NewForbiddenUri1}}} =
456
httpd_request:validate("GET", NewForbiddenUri1, "HTTP/1.1"),
459
%%-------------------------------------------------------------------------
460
esi_parse_headers(doc) ->
461
["Test httpd_esi:*. All header values are received in the same"
463
esi_parse_headers(suite) ->
465
esi_parse_headers(Config) when is_list(Config) ->
467
ESIResult = "content-type:text/html\r\ndate:Thu, 28 Oct 2004 07:57:43 "
468
"GMT\r\nstatus:200 OK\r\n\r\nFoobar",
470
{"content-type:text/html\r\ndate:Thu, 28 Oct 2004 07:57:43 GMT\r\nst"
471
"atus:200 OK\r\n" = Headers,
472
"Foobar"} = httpd_esi:parse_headers(ESIResult),
474
{ok,[{"date","Thu, 28 Oct 2004 07:57:43 GMT"},
475
{"content-type","text/html"}], 200} =
476
httpd_esi:handle_headers(Headers),
479
"location:http://foo.bar.se\r\ndate:Thu, 28 Oct 2004 07:57:43 "
482
{"location:http://foo.bar.se\r\ndate:Thu, 28 Oct 2004 07:57:43 GMT\r\n" =
484
= httpd_esi:parse_headers(ESIResult2),
486
{ok,[{"date","Thu, 28 Oct 2004 07:57:43 GMT"},
487
{"location","http://foo.bar.se"}], 302} =
488
httpd_esi:handle_headers(Headers2),
490
{proceed,"/foo/bar.html"} =
491
httpd_esi:handle_headers("location:/foo/bar.html\r\n"),
494
%%--------------------------------------------------------------------
495
cgi_parse_headers(doc) ->
496
["Test httpd_cgi:*. This test case will simulate that the "
497
"message will be recived a little at the time on a socket and the "
498
"package may be broken up into smaller parts at arbitrary point."];
499
cgi_parse_headers(suite) ->
501
cgi_parse_headers(Config) when is_list(Config) ->
503
CGIResult = ["content-type:text", "/html\ndate:Thu, 28 Oct 2004 07:57:43 "
504
"GMT\nst", "atus:200 OK\n", "\nFoobar"],
507
parse(httpd_cgi, parse_headers, [<<>>, [], []], CGIResult),
509
"Foobar" = binary_to_list(Body),
511
{ok,[{"content-type","text/html"},
512
{"date","Thu, 28 Oct 2004 07:57:43 GMT"}], {200,"OK"}} =
513
httpd_cgi:handle_headers(Headers),
515
CGIResult2 = ["location:http://foo.bar.se\ndate:Thu, 28 Oct 2004"
516
" 07:57:43 GMT\n\n"],
517
{Headers2, _} = parse(httpd_cgi, parse_headers,
518
[<<>>, [], []], CGIResult2),
520
{ok,[{"location","http://foo.bar.se"},
521
{"date","Thu, 28 Oct 2004 07:57:43 GMT"}], {302,"Redirect"}} =
522
httpd_cgi:handle_headers(Headers2),
524
{proceed,"/foo/bar.html"} =
525
httpd_cgi:handle_headers(["location:/foo/bar.html\n"]),
527
CGIHTTPResult = ["Content-Type:text", "/html\n", "Connection:close\r\n",
528
"Content-Language:en\r\nAge:", "4711\r\n\r\n\nfoobar"],
530
{Headers3, _} = parse(httpd_cgi, parse_headers,
531
[<<>>, [], []], CGIHTTPResult),
533
{ok,[{"content-type","text/html"},
534
{"connection","close"},
535
{"content-language","en"},
536
{"age","4711"}], {200,"ok"}} = httpd_cgi:handle_headers(Headers3),
540
%%-------------------------------------------------------------------------
541
is_absolut_uri(doc) ->
542
["Test http_request:is_absolut_uri/1."];
543
is_absolut_uri(suite) ->
545
is_absolut_uri(Config) when is_list(Config) ->
546
true = http_request:is_absolut_uri("http://www.erlang.org"),
547
true = http_request:is_absolut_uri("https://www.erlang.org"),
548
false = http_request:is_absolut_uri("index.html").
551
%%-------------------------------------------------------------------------
552
convert_netscapecookie_date(doc) ->
553
["Test http_util:convert_netscapecookie_date/1."];
554
convert_netscapecookie_date(suite) ->
556
convert_netscapecookie_date(Config) when is_list(Config) ->
557
{{2006,1,6},{8,59,38}} =
558
http_util:convert_netscapecookie_date("Mon, 06-Jan-2006 08:59:38 GMT"),
559
{{2006,2, 7},{8,59,38}} =
560
http_util:convert_netscapecookie_date("Tue, 07-Feb-2006 08:59:38 GMT"),
561
{{2006,3,8},{8,59,38}} =
562
http_util:convert_netscapecookie_date("Wdy, 08-Mar-2006 08:59:38 GMT"),
563
{{2006,4,9},{8,59,38}} =
564
http_util:convert_netscapecookie_date("Thu, 09-Apr-2006 08:59:38 GMT"),
565
{{2006,5,10},{8,59,38}} =
566
http_util:convert_netscapecookie_date("Fri, 10-May-2006 08:59:38 GMT"),
567
{{2006,6,11},{8,59,38}} =
568
http_util:convert_netscapecookie_date("Sat, 11-Jun-2006 08:59:38 GMT"),
569
{{2006,7,12},{8,59,38}} =
570
http_util:convert_netscapecookie_date("Sun, 12-Jul-2006 08:59:38 GMT"),
571
{{2006,8,12},{8,59,38}} =
572
http_util:convert_netscapecookie_date("Sun, 12-Aug-2006 08:59:38 GMT"),
573
{{2006,9,12},{8,59,38}} =
574
http_util:convert_netscapecookie_date("Sun, 12-Sep-2006 08:59:38 GMT"),
575
{{2006,10,12},{8,59,38}} =
576
http_util:convert_netscapecookie_date("Sun, 12-Oct-2006 08:59:38 GMT"),
577
{{2006,11,12},{8,59,38}} =
578
http_util:convert_netscapecookie_date("Sun, 12-Nov-2006 08:59:38 GMT"),
579
{{2006,12,12},{8,59,38}} =
580
http_util:convert_netscapecookie_date("Sun, 12-Dec-2006 08:59:38 GMT"),
581
{{2006,12,12},{8,59,38}} =
582
http_util:convert_netscapecookie_date("Sun 12-Dec-2006 08:59:38 GMT"),
583
{{2006,12,12},{8,59,38}} =
584
http_util:convert_netscapecookie_date("Sun, 12-Dec-06 08:59:38 GMT"),
585
{{2006,12,12},{8,59,38}} =
586
http_util:convert_netscapecookie_date("Sun 12-Dec-06 08:59:38 GMT"),
589
%%--------------------------------------------------------------------
590
%%% Internal functions
591
%%--------------------------------------------------------------------
593
parse(Module, Function, Args, [Data | Rest]) ->
594
case Module:Function([list_to_binary(Data) | Args]) of
597
{NewModule, NewFunction, NewArgs} ->
598
parse(NewModule, NewFunction, NewArgs, Rest)