From 473c6308bbfed958ab04f45f53305e5d82d733fa Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 23 Nov 2011 16:22:50 +0100 Subject: Fixed acceptor exit warnings (detected by dialyzer). Also fixed cookie_header/3 and updated documented accordingly. Also added documentation for undocumented URI parse option. --- lib/inets/doc/src/httpc.xml | 33 +++++++++++++++++++++------- lib/inets/src/http_client/httpc.erl | 21 +++++++++++++----- lib/inets/src/http_client/httpc_manager.erl | 4 +++- lib/inets/src/http_server/httpd_acceptor.erl | 20 ++++++----------- 4 files changed, 51 insertions(+), 27 deletions(-) diff --git a/lib/inets/doc/src/httpc.xml b/lib/inets/doc/src/httpc.xml index b1f964ae69..730efb729f 100644 --- a/lib/inets/doc/src/httpc.xml +++ b/lib/inets/doc/src/httpc.xml @@ -178,13 +178,14 @@ filename() = string() timeout() = integer() >= 0 | infinity Options = options() options() = [option()] - option() = {sync, boolean()} | - {stream, stream_to()} | - {body_format, body_format()} | - {full_result, boolean()} | - {headers_as_is, boolean() | - {socket_opts, socket_opts()} | - {receiver, receiver()}} + option() = {sync, boolean()} | + {stream, stream_to()} | + {body_format, body_format()} | + {full_result, boolean()} | + {headers_as_is, boolean() | + {socket_opts, socket_opts()} | + {receiver, receiver()}, + {ipv6_host_with_brackets, boolean()}} stream_to() = none | self | {self, once} | filename() socket_opts() = [socket_opt()] receiver() = pid() | function()/1 | {Module, Function, Args} @@ -408,6 +409,15 @@ apply(Module, Function, [ReplyInfo | Args])

Defaults to the pid() of the process calling the request function (self()).

+ + + +

When parsing the Host-Port part of an URI with a IPv6 address + with brackets, shall we retain those brackets (true) or + strip them (false).

+

Defaults to false.

+
+ @@ -572,17 +582,24 @@ apply(Module, Function, [ReplyInfo | Args]) cookie_header(Url) -> - cookie_header(Url, Profile) -> header() | {error, Reason} + cookie_header(Url, Profile | Opts) -> header() | {error, Reason} + cookie_header(Url, Opts, Profile) -> header() | {error, Reason} Returns the cookie header that would be sent when making a request to Url using the profile Profile. Url = url() + Opts = [cookie_header_opt()] Profile = profile() | pid() (when started stand_alone) + cookie_header_opt() = {ipv6_host_with_brackets, boolean()}

Returns the cookie header that would be sent when making a request to Url using the profile Profile. If no profile is specified the default profile will be used.

+

The option ipv6_host_with_bracket deals with how to + parse IPv6 addresses. + See the Options argument of the + request/4,5 for more info.

diff --git a/lib/inets/src/http_client/httpc.erl b/lib/inets/src/http_client/httpc.erl index d72c34fa6b..ae87ceed93 100644 --- a/lib/inets/src/http_client/httpc.erl +++ b/lib/inets/src/http_client/httpc.erl @@ -34,7 +34,7 @@ set_option/2, set_option/3, set_options/1, set_options/2, store_cookies/2, store_cookies/3, - cookie_header/1, cookie_header/2, + cookie_header/1, cookie_header/2, cookie_header/3, which_cookies/0, which_cookies/1, reset_cookies/0, reset_cookies/1, stream_next/1, @@ -290,25 +290,36 @@ store_cookies(SetCookieHeaders, Url, Profile) %%-------------------------------------------------------------------------- -%% cookie_header(Url [, Profile]) -> Header | {error, Reason} -%% +%% cookie_header(Url) -> Header | {error, Reason} +%% cookie_header(Url, Profile) -> Header | {error, Reason} +%% cookie_header(Url, Opts, Profile) -> Header | {error, Reason} +%% %% Description: Returns the cookie header that would be sent when making %% a request to . %%------------------------------------------------------------------------- cookie_header(Url) -> cookie_header(Url, default_profile()). -cookie_header(Url, Profile) -> +cookie_header(Url, Profile) when is_atom(Profile) orelse is_pid(Profile) -> + cookie_header(Url, [], Profile); +cookie_header(Url, Opts) when is_list(Opts) -> + cookie_header(Url, Opts, default_profile()). + +cookie_header(Url, Opts, Profile) + when (is_list(Opts) andalso (is_atom(Profile) orelse is_pid(Profile))) -> ?hcrt("cookie header", [{url, Url}, + {opts, Opts}, {profile, Profile}]), try begin - httpc_manager:which_cookies(Url, profile_name(Profile)) + httpc_manager:which_cookies(Url, Opts, profile_name(Profile)) end catch exit:{noproc, _} -> {error, {not_started, Profile}} end. + + %%-------------------------------------------------------------------------- diff --git a/lib/inets/src/http_client/httpc_manager.erl b/lib/inets/src/http_client/httpc_manager.erl index 121562195f..a97cbb83f1 100644 --- a/lib/inets/src/http_client/httpc_manager.erl +++ b/lib/inets/src/http_client/httpc_manager.erl @@ -271,9 +271,11 @@ reset_cookies(ProfileName) -> which_cookies(ProfileName) when is_atom(ProfileName) -> call(ProfileName, which_cookies). + which_cookies(Url, ProfileName) when is_list(Url) andalso is_atom(ProfileName) -> - call(ProfileName, {which_cookies, Url, []}). + which_cookies(Url, [], ProfileName). + which_cookies(Url, Options, ProfileName) when is_list(Url) andalso is_list(Options) andalso is_atom(ProfileName) -> call(ProfileName, {which_cookies, Url, Options}). diff --git a/lib/inets/src/http_server/httpd_acceptor.erl b/lib/inets/src/http_server/httpd_acceptor.erl index 1c954106c1..046e491bbf 100644 --- a/lib/inets/src/http_server/httpd_acceptor.erl +++ b/lib/inets/src/http_server/httpd_acceptor.erl @@ -139,11 +139,11 @@ acceptor_loop(Manager, SocketType, ListenSocket, ConfigDb, AcceptTimeout) -> handle_error(Reason, ConfigDb), ?MODULE:acceptor_loop(Manager, SocketType, ListenSocket, ConfigDb, AcceptTimeout); - {'EXIT', _Reason} = EXIT -> - ?hdri("accept exited", [{reason, _Reason}]), - handle_error(EXIT, ConfigDb), - ?MODULE:acceptor_loop(Manager, SocketType, ListenSocket, - ConfigDb, AcceptTimeout) + {'EXIT', Reason} -> + ?hdri("accept exited", [{reason, Reason}]), + ReasonString = + lists:flatten(io_lib:format("Accept exit: ~p", [Reason])), + accept_failed(ConfigDb, ReasonString) end. @@ -152,9 +152,6 @@ handle_connection(Manager, ConfigDb, AcceptTimeout, SocketType, Socket) -> http_transport:controlling_process(SocketType, Socket, Pid), httpd_request_handler:socket_ownership_transfered(Pid, SocketType, Socket). - --spec handle_error(Error::timeout|emfile|closed|econnreset|econnaborted|esslaccept|{enfile, _}|{'EXIT', Reason::any()}|any(), ConfigDB::any()) -> ok | no_return(). - handle_error(timeout, _) -> ok; @@ -192,16 +189,13 @@ handle_error(esslaccept, _) -> %% not write an error message. ok; -handle_error({'EXIT', Reason}, ConfigDb) -> - String = lists:flatten(io_lib:format("Accept exit: ~p", [Reason])), - accept_failed(ConfigDb, String); - handle_error(Reason, ConfigDb) -> String = lists:flatten(io_lib:format("Accept error: ~p", [Reason])), accept_failed(ConfigDb, String). --spec accept_failed(_, string()) -> no_return(). +-spec accept_failed(ConfigDB :: term(), + ReasonString :: string()) -> no_return(). accept_failed(ConfigDb, String) -> error_logger:error_report(String), -- cgit v1.2.3