[erlang-questions] erlang-questions] Erlang HTTP client is not so fault tollerant...

Ingela Anderton Andin <>
Mon Dec 10 09:59:36 CET 2007


Hi!

The code for parsing HTTP is not written defensively, yes we want the
parsing code to crash on bad input. The HTTP-client did not crash
it returned an error-message (so it is fault tolerant!) That in this 
case happens to be
the call-stack as it was an unexpected error in some sense.

{error,{badarg,[{erlang,list_to_integer,["301\r\nDate:"]},
                {httpc_response,parse_status_code,4},
                {httpc_handler,handle_info,2},
                {gen_server,handle_msg,5},
                {proc_lib,init_p,5}]}}


In this particular case it could be argued the a more "user-friendly"
error-message could be accomplished. It is true that a temporary
process spawned by the http client crashed and was reported to have
done so.

I am considering catching the error in the temporary process
and then letting it terminate normaly to avoid confusion.
Something like {http_parse_error, HTTPMsg}
could be given as reason instead of the call-stack.

This particular error is something that we
will consider accepting in the relaxed mode of the HTTP-client.

Regards Ingela - OTP team
> Hi there,
>
> a normal HTTP 301 response should look like this:
>
> HTTP/1.1 301 Moved Permanently
> Date: Sun, 09 Dec 2007 10:54:02 GMT
> Server: Apache/1.3.37 (Unix) PHP/4.4.4 with Suhosin-Patch
> FrontPage/5.0.2.4803 mod_fastcgi/mod_fastcgi-SNAP-0404142202 mod_ssl/2.8.28
> OpenSSL/0.9.6i
> Location: http://www.spielendverdienen.de/startseite.html
>
> However, some servers return
>
> HTTP/1.1 301
> Date: Sun, 09 Dec 2007 10:52:58 GMT
> Server: Apache/1.3.37 (Unix) FrontPage/5.0.2.2623 mod_ssl/2.8.28
> OpenSSL/0.9.8a
> Location: http://charmed.qanet.de/en/
>
> (notice the first line, in the second response the reason is missing)
>
> When requesting a page from a server that returns the second http-response,
> erlang crashes:
>
> 27> http:request("http://charmed.qanet.de/",foo).
> {error,{badarg,[{erlang,list_to_integer,["301\r\nDate:"]},
>                 {httpc_response,parse_status_code,4},
>                 {httpc_handler,handle_info,2},
>                 {gen_server,handle_msg,5},
>                 {proc_lib,init_p,5}]}}
>
> =ERROR REPORT==== 9-Dec-2007::14:04:08 ===
> ** Generic server <0.106.0> terminating
> ** Last message in was {tcp,#Port<0.185>,
>                             <<"HTTP/1.1 301\r\nDate: Sun, 09 Dec 2007
> 13:04:18 G
> MT\r\nServer: Apache/1.3.37 (Unix) FrontPage/5.0.2.2623 mod_ssl/2.8.28
> OpenSSL/0
> .9.8a\r\nLocation: http://charmed.qanet.de/en/\r\nKeep-Alive: timeout=15,
> max=10
> 0\r\nConnection: Keep-Alive\r\nTransfer-Encoding: chunked\r\nContent-Type:
> text/
> html\r\n\r\n">>}
> ** When Server state == {state,
>                             {request,#Ref<0.0.0.444>,<0.62.0>,0,http,
>                                 {"charmed.qanet.de",80},
>                                 "/",[],get,
>                                 {http_request_h,undefined,"keep-alive",
>                                     undefined,undefined,undefined,undefined,
>                                     undefined,undefined,undefined,undefined,
>                                     undefined,undefined,undefined,undefined,
>                                     undefined,undefined,"charmed.qanet.de",
>                                     undefined,undefined,undefined,undefined,
>                                     undefined,undefined,undefined,undefined,
>                                     undefined,[],undefined,undefined,
>                                     undefined,undefined,"0",undefined,
>                                     undefined,undefined,undefined,undefined,
>                                     undefined,[]},
>                                 {[],[]},
>                                 {http_options,infinity,true,[],undefined,
>                                     false},
>                                 "http://charmed.qanet.de/",[],none,[]},
>                             {tcp_session,
>                                 {{"charmed.qanet.de",80},<0.106.0>},
>                                 false,http,#Port<0.185>,1},
>                             undefined,undefined,undefined,
>                             {httpc_response,parse,[nolimit]},
>                             {[],[]},
>                             new,[],nolimit,nolimit,
>                             {options,
>                                 {undefined,[]},
>                                 0,2,2,enabled,enabled,false},
>                             {timers,[],undefined},
>                             httpc_manager_foo,undefined}
> ** Reason for termination ==
> ** {badarg,[{erlang,list_to_integer,["301\r\nDate:"]},
>             {httpc_response,parse_status_code,4},
>             {httpc_handler,handle_info,2},
>             {gen_server,handle_msg,5},
>             {proc_lib,init_p,5}]}
> 28>
>
> Therefore, I'd like to replace the first line of the incoming server
> response from "HTTP/1.1 301\r\n" to "HTTP/1.1 301 Moved Permanently\r\n",
> but I can't seem to find where the appropriate to do so would be...
>
> Can you help me with this?
>   




More information about the erlang-questions mailing list