From 2e6bff7e8bc66a774e5beafe84eadb33cb93641f Mon Sep 17 00:00:00 2001 From: Chandrashekhar Mullaparthi Date: Sun, 6 Sep 2009 08:26:47 +0100 Subject: [PATCH] Allow socket options to be set by caller during the connect phase as well --- .gitignore | 2 ++ ebin/ibrowse.app | 2 +- src/ibrowse_http_client.erl | 24 ++++++++++++++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2a53be2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.beam + diff --git a/ebin/ibrowse.app b/ebin/ibrowse.app index 9c27ee3..ccab68c 100644 --- a/ebin/ibrowse.app +++ b/ebin/ibrowse.app @@ -1,6 +1,6 @@ {application, ibrowse, [{description, "HTTP client application"}, - {vsn, "1.5.1"}, + {vsn, "1.5.3"}, {modules, [ ibrowse, ibrowse_http_client, ibrowse_app, diff --git a/src/ibrowse_http_client.erl b/src/ibrowse_http_client.erl index ebc4a11..37085f4 100644 --- a/src/ibrowse_http_client.erl +++ b/src/ibrowse_http_client.erl @@ -413,15 +413,31 @@ handle_sock_closed(#state{reply_buffer = Buf, reqs = Reqs, http_status_code = SC State end. -do_connect(Host, Port, _Options, #state{is_ssl=true, ssl_options=SSLOptions}, Timeout) -> +do_connect(Host, Port, Options, #state{is_ssl=true, ssl_options=SSLOptions}, Timeout) -> + Caller_socket_options = get_value(socket_options, Options, []), + Other_sock_options = filter_sock_options(SSLOptions ++ Caller_socket_options), ssl:connect(Host, Port, - [binary, {nodelay, true}, {active, false} | SSLOptions], + [binary, {nodelay, true}, {active, false} | Other_sock_options], Timeout); -do_connect(Host, Port, _Options, _State, Timeout) -> +do_connect(Host, Port, Options, _State, Timeout) -> + Caller_socket_options = get_value(socket_options, Options, []), + Other_sock_options = filter_sock_options(Caller_socket_options), gen_tcp:connect(Host, Port, - [binary, {nodelay, true}, {active, false}], + [binary, {nodelay, true}, {active, false} | Other_sock_options], Timeout). +%% We don't want the caller to specify certain options +filter_sock_options(Opts) -> + lists:filter(fun({active, _}) -> + false; + ({packet, _}) -> + false; + (list) -> + false; + (_) -> + true + end, Opts). + do_send(Req, #state{socket = Sock, is_ssl = true}) -> ssl:send(Sock, Req); do_send(Req, #state{socket = Sock, is_ssl = false}) -> gen_tcp:send(Sock, Req).