[erlang-bugs] inets httpc cookie parsing bug

mmzeeman <>
Wed Jul 13 14:28:05 CEST 2011


Some servers use expire dates which look different. This sometimes causes
the inets httpc client to fail.

For instance:

1> application:start(inets).
2> httpc:set_options([{cookies, enabled}]).
3> httpc:request("http://www.amazon.com").

Fails with a function_clause exception. The expiry date used here looks
like this: Tue Jan 01 08:00:01 2036 GMT

Looking at the most recent specification regarding cookies (rfc-6265) the
current format is described and quite flexible. The spec also states that
if an error occurs during parsing of the date it should be ignored.

Now what is the correct way to fix this?

Ignoring parsing errors can be done easily.

%% Backwards compatibility with netscape cookies
cookie_attributes([{"expires", Value}| Attributes], Cookie) ->
    try http_util:convert_netscapecookie_date(Value) of
	Time ->
	    ExpireTime = calendar:datetime_to_gregorian_seconds(Time),
	    cookie_attributes(Attributes,
			      Cookie#http_cookie{max_age = ExpireTime})
    catch
	_:_ -> cookie_attributes(Attributes, Cookie)
    end;

Maas





More information about the erlang-bugs mailing list