diff --git a/src/ibrowse.erl b/src/ibrowse.erl
index 80a4282..40b3f97 100644
--- a/src/ibrowse.erl
+++ b/src/ibrowse.erl
@@ -175,9 +175,11 @@ send_req(Url, Headers, Method) ->
send_req(Url, Headers, Method, Body) ->
send_req(Url, Headers, Method, Body, []).
-%% @doc Same as send_req/4.
-%% For a description of SSL Options, look in the ssl manpage. If the
-%% HTTP Version to use is not specified, the default is 1.1.
+%% @doc Same as send_req/4.
+
+%% For a description of SSL Options, look in the ssl manpage.
+%% For a description of Process Options, look in the gen_server manpage.
+%% If the HTTP Version to use is not specified, the default is 1.1.
%%
%%
%% - The
host_header
option is useful in the case where ibrowse is
@@ -286,7 +288,8 @@ send_req(Url, Headers, Method, Body) ->
%% {headers_as_is, boolean()} |
%% {give_raw_headers, boolean()} |
%% {preserve_chunked_encoding,boolean()} |
-%% {workaround, head_response_with_body}
+%% {workaround, head_response_with_body} |
+%% {worker_process_options, list()}
%%
%% stream_to() = process() | {process(), once}
%% process() = pid() | atom()
@@ -340,10 +343,12 @@ try_routing_request(Lb_pid, Parsed_url,
Max_pipeline_size,
{SSLOptions, IsSSL},
Headers, Method, Body, Options_1, Timeout, Try_count) when Try_count < 3 ->
+ ProcessOptions = get_value(worker_process_options, Options_1, []),
case ibrowse_lb:spawn_connection(Lb_pid, Parsed_url,
Max_sessions,
Max_pipeline_size,
- {SSLOptions, IsSSL}) of
+ {SSLOptions, IsSSL},
+ ProcessOptions) of
{ok, Conn_Pid} ->
case do_send_req(Conn_Pid, Parsed_url, Headers,
Method, Body, Options_1, Timeout) of
@@ -470,28 +475,32 @@ ensure_bin({Fun, _} = Body) when is_function(Fun) -> Body.
%% request is sent via any of the send_req_direct/4,5,6,7 functions.
%% Note: It is the responsibility of the calling process to control
%% pipeline size on such connections.
-%%
-%% @spec spawn_worker_process(Url::string()) -> {ok, pid()}
-spawn_worker_process(Url) ->
- ibrowse_http_client:start(Url).
-%% @doc Same as spawn_worker_process/1 but takes as input a Host and Port
-%% instead of a URL.
-%% @spec spawn_worker_process(Host::string(), Port::integer()) -> {ok, pid()}
-spawn_worker_process(Host, Port) ->
- ibrowse_http_client:start({Host, Port}).
+%% @spec spawn_worker_process(Url::string() | {Host::string(), Port::integer()}) -> {ok, pid()}
+spawn_worker_process(Args) ->
+ spawn_worker_process(Args, []).
-%% @doc Same as spawn_worker_process/1 except the the calling process
-%% is linked to the worker process which is spawned.
-%% @spec spawn_link_worker_process(Url::string()) -> {ok, pid()}
-spawn_link_worker_process(Url) ->
- ibrowse_http_client:start_link(Url).
+%% @doc Same as spawn_worker_process/1 except with Erlang process options.
+%% @spec spawn_worker_process(Url::string() | {Host::string(), Port::integer(), Options::list()) -> {ok, pid()}
+spawn_worker_process(Host, Port) when is_list(Host), is_integer(Port) ->
+ %% Convert old API calls to new API format.
+ spawn_worker_process({Host, Port}, []);
+spawn_worker_process(Args, Options) ->
+ ibrowse_http_client:start(Args, Options).
-%% @doc Same as spawn_worker_process/2 except the the calling process
+%% @doc Same as spawn_worker_process/1 except the the calling process
%% is linked to the worker process which is spawned.
-%% @spec spawn_link_worker_process(Host::string(), Port::integer()) -> {ok, pid()}
-spawn_link_worker_process(Host, Port) ->
- ibrowse_http_client:start_link({Host, Port}).
+%% @spec spawn_link_worker_process(Url::string() | {Host::string(), Port::integer()}) -> {ok, pid()}
+spawn_link_worker_process(Args) ->
+ spawn_link_worker_process(Args, []).
+
+%% @doc Same as spawn_link_worker_process/1 except with Erlang process options.
+%% @spec spawn_link_worker_process(Url::string() | {Host::string(), Port::integer(), Options::list()) -> {ok, pid()}
+spawn_link_worker_process(Host, Port) when is_list(Host), is_integer(Port) ->
+ %% Convert old API calls to new API format.
+ spawn_link_worker_process({Host, Port}, []);
+spawn_link_worker_process(Args, Options) ->
+ ibrowse_http_client:start_link(Args, Options).
%% @doc Terminate a worker process spawned using
%% spawn_worker_process/2 or spawn_link_worker_process/2. Requests in
diff --git a/src/ibrowse_http_client.erl b/src/ibrowse_http_client.erl
index 59b9e08..76d3906 100644
--- a/src/ibrowse_http_client.erl
+++ b/src/ibrowse_http_client.erl
@@ -15,7 +15,9 @@
%% External exports
-export([
start_link/1,
+ start_link/2,
start/1,
+ start/2,
stop/1,
send_req/7
]).
@@ -79,10 +81,16 @@
%% Description: Starts the server
%%--------------------------------------------------------------------
start(Args) ->
- gen_server:start(?MODULE, Args, []).
+ start(Args, []).
+
+start(Args, Options) ->
+ gen_server:start(?MODULE, Args, Options).
start_link(Args) ->
- gen_server:start_link(?MODULE, Args, []).
+ start_link(Args, []).
+
+start_link(Args, Options) ->
+ gen_server:start_link(?MODULE, Args, Options).
stop(Conn_pid) ->
case catch gen_server:call(Conn_pid, stop) of
diff --git a/src/ibrowse_lb.erl b/src/ibrowse_lb.erl
index d98cf32..44202cb 100644
--- a/src/ibrowse_lb.erl
+++ b/src/ibrowse_lb.erl
@@ -16,7 +16,7 @@
%% External exports
-export([
start_link/1,
- spawn_connection/5,
+ spawn_connection/6,
stop/1
]).
@@ -81,13 +81,14 @@ init([Host, Port]) ->
spawn_connection(Lb_pid, Url,
Max_sessions,
Max_pipeline_size,
- SSL_options)
+ SSL_options,
+ Process_options)
when is_pid(Lb_pid),
is_record(Url, url),
is_integer(Max_pipeline_size),
is_integer(Max_sessions) ->
gen_server:call(Lb_pid,
- {spawn_connection, Url, Max_sessions, Max_pipeline_size, SSL_options}).
+ {spawn_connection, Url, Max_sessions, Max_pipeline_size, SSL_options, Process_options}).
stop(Lb_pid) ->
case catch gen_server:call(Lb_pid, stop) of
@@ -123,19 +124,19 @@ handle_call(_, _From, #state{proc_state = shutting_down} = State) ->
{reply, {error, shutting_down}, State};
%% Update max_sessions in #state with supplied value
-handle_call({spawn_connection, _Url, Max_sess, Max_pipe, _}, _From,
- #state{num_cur_sessions = Num} = State)
+handle_call({spawn_connection, _Url, Max_sess, Max_pipe, _, _}, _From,
+ #state{num_cur_sessions = Num} = State)
when Num >= Max_sess ->
State_1 = maybe_create_ets(State),
Reply = find_best_connection(State_1#state.ets_tid, Max_pipe),
{reply, Reply, State_1#state{max_sessions = Max_sess,
max_pipeline_size = Max_pipe}};
-handle_call({spawn_connection, Url, Max_sess, Max_pipe, SSL_options}, _From,
+handle_call({spawn_connection, Url, Max_sess, Max_pipe, SSL_options, Process_options}, _From,
#state{num_cur_sessions = Cur} = State) ->
State_1 = maybe_create_ets(State),
Tid = State_1#state.ets_tid,
- {ok, Pid} = ibrowse_http_client:start_link({Tid, Url, SSL_options}),
+ {ok, Pid} = ibrowse_http_client:start_link({Tid, Url, SSL_options}, Process_options),
ets:insert(Tid, {Pid, 0, 0}),
{reply, {ok, Pid}, State_1#state{num_cur_sessions = Cur + 1,
max_sessions = Max_sess,