[erlang-bugs] Possible Bug in http:cookie_header(Url)
Mike Ziebeck
mike@REDACTED
Tue Mar 17 21:35:36 CET 2009
Hallo,
using cookies with otp's http:request/1 I was missing
a correct answer from http:cookie_header(Url). It returns
{"cookie",[]} where http_cookie:cookies(HEADER, "/", [46|Host])
returns [{http_cookie,[46|Host],false,Field,Value,
undefined,Expiration,"/",false,false,"0"}]
Test case included.
Best Regards
mz.
cookie_test() ->
Url="http://google.de",
Field="set-cookie",
% 1st (cookies disabled) we ask URL twice and get 2 different cookies
inets:start(),
{ok,{_,H1,_}}=http:request(Url),
Cookie1=proplists:get_value(Field, H1),
{cookie_1,true}={cookie_1,(undefined=/=Cookie1)}, % get sure it is
defined
{ok,{_,H2,_}}=http:request(Url),
Cookie2=proplists:get_value(Field, H2),
{cookie_2,true}={cookie_2,(undefined=/=Cookie2)}, % get sure it is
defined
true=(Cookie1=/=Cookie2), % get sure both differ
inets:stop(),
% 2nd (cookies enabled) we ask URL twice and get a cookie only once
inets:start(),
http:set_options([{cookies, enabled}]),
{_,_,Host,_,_,_}=http_uri:parse(Url),
{ok,{_,H3,_}}=http:request(Url),
Cookie3=proplists:get_value(Field, H3),
{cookie_3,true}={cookie_3,(undefined=/=Cookie3)}, % get sure it is
defined
% ================== This will cause an exception
=======================
CookieHeaderA=http:cookie_header(Url), % test
http:cookie_header
CookieHeaderB=http_cookie:cookies(H3, "/", [46|Host]),
{CookieHeaderA,CookieHeaderA}={CookieHeaderA,CookieHeaderB},
%
=========================================================================
{ok,{_,H4,_}}=http:request(Url),
Cookie4=proplists:get_value(Field, H4),
{cookie_4,true}={cookie_4,(undefined==Cookie4)}, % get sure it is
undefined
true=(Cookie3=/=Cookie4), % get sure both differ
inets:stop().
Results:
** exception error: no match of right hand side value
{{"cookie",[]},
[{http_cookie,".google.de",false,"PREF",
"ID=d780114c65e8ea39:TM=1237321924:LM=1237321924:S=JYbYCgOBocUxi0lC",
undefined,63467613124,"/",false,false,
"0"}]}
in function inets_tools:cookie_test/0
More information about the erlang-bugs
mailing list