瀏覽代碼

Added option to allow caller to specify socket options

pull/16/head
Chandrashekhar Mullaparthi 15 年之前
父節點
當前提交
ce2cc0140e
共有 5 個檔案被更改,包括 32 行新增10 行删除
  1. +3
    -1
      README
  2. +8
    -2
      doc/ibrowse.html
  3. +7
    -0
      src/ibrowse.erl
  4. +13
    -6
      src/ibrowse_http_client.erl
  5. +1
    -1
      vsn.mk

+ 3
- 1
README 查看文件

@ -18,12 +18,14 @@ ibrowse is available under two different licenses. LGPL and the BSD license.
Comments to : Chandrashekhar.Mullaparthi@gmail.com
Version : 1.5.2
Version : 1.5.3
Latest version : git://github.com/cmullaparthi/ibrowse.git
CONTRIBUTIONS & CHANGE HISTORY
==============================
05-09-2009 - * Introduced option to allow caller to set socket options.
29-07-2009 - * The ETS table created for load balancing of requests was not
being deleted which led to the node not being able to create
any more ETS tables if queries were made to many number of

+ 8
- 2
doc/ibrowse.html 查看文件

@ -203,12 +203,14 @@ send_req/4, send_req/5, send_req/6.

<div class="spec">
<p><tt>send_req(Url::string(), Headers::<a href="#type-headerList">headerList()</a>, Method::<a href="#type-method">method()</a>, Body::<a href="#type-body">body()</a>, Options::<a href="#type-optionList">optionList()</a>) -&gt; <a href="#type-response">response()</a></tt>
<ul class="definitions"><li><tt><a name="type-optionList">optionList()</a> = [<a href="#type-option">option()</a>]</tt></li>
<li><tt><a name="type-option">option()</a> = {max_sessions, integer()} | {response_format, <a href="#type-response_format">response_format()</a>} | {stream_chunk_size, integer()} | {max_pipeline_size, integer()} | {trace, <a href="#type-boolean">boolean()</a>} | {is_ssl, <a href="#type-boolean">boolean()</a>} | {ssl_options, [SSLOpt]} | {pool_name, atom()} | {proxy_host, string()} | {proxy_port, integer()} | {proxy_user, string()} | {proxy_password, string()} | {use_absolute_uri, <a href="#type-boolean">boolean()</a>} | {basic_auth, {<a href="#type-username">username()</a>, <a href="#type-password">password()</a>}} | {cookie, string()} | {content_length, integer()} | {content_type, string()} | {save_response_to_file, <a href="#type-srtf">srtf()</a>} | {stream_to, <a href="#type-stream_to">stream_to()</a>} | {http_vsn, {MajorVsn, MinorVsn}} | {host_header, string()} | {inactivity_timeout, integer()} | {connect_timeout, integer()} | {transfer_encoding, {chunked, ChunkSize}}</tt></li>
<li><tt><a name="type-option">option()</a> = {max_sessions, integer()} | {response_format, <a href="#type-response_format">response_format()</a>} | {stream_chunk_size, integer()} | {max_pipeline_size, integer()} | {trace, <a href="#type-boolean">boolean()</a>} | {is_ssl, <a href="#type-boolean">boolean()</a>} | {ssl_options, [SSLOpt]} | {pool_name, atom()} | {proxy_host, string()} | {proxy_port, integer()} | {proxy_user, string()} | {proxy_password, string()} | {use_absolute_uri, <a href="#type-boolean">boolean()</a>} | {basic_auth, {<a href="#type-username">username()</a>, <a href="#type-password">password()</a>}} | {cookie, string()} | {content_length, integer()} | {content_type, string()} | {save_response_to_file, <a href="#type-srtf">srtf()</a>} | {stream_to, <a href="#type-stream_to">stream_to()</a>} | {http_vsn, {MajorVsn, MinorVsn}} | {host_header, string()} | {inactivity_timeout, integer()} | {connect_timeout, integer()} | {socket_options, Sock_opts} | {transfer_encoding, {chunked, ChunkSize}}</tt></li>
<li><tt><a name="type-stream_to">stream_to()</a> = <a href="#type-process">process()</a> | {<a href="#type-process">process()</a>, once}</tt></li>
<li><tt><a name="type-process">process()</a> = pid() | atom()</tt></li>
<li><tt><a name="type-username">username()</a> = string()</tt></li>
<li><tt><a name="type-password">password()</a> = string()</tt></li>
<li><tt>SSLOpt = term()</tt></li>
<li><tt>Sock_opts = [Sock_opt]</tt></li>
<li><tt>Sock_opt = term()</tt></li>
<li><tt>ChunkSize = integer()</tt></li>
<li><tt><a name="type-srtf">srtf()</a> = <a href="#type-boolean">boolean()</a> | <a href="#type-filename">filename()</a></tt></li>
<li><tt><a name="type-filename">filename()</a> = string()</tt></li>
@ -271,6 +273,10 @@ send_req/4, send_req/5, send_req/6.

for connection setup.
</li>
</ul>
<li> The <code>socket_options</code> option can be used to set
specific options on the socket. The <code>{active, true | false | once}</code>
and <code>{packet_type, Packet_type}</code> will be filtered out by ibrowse. </li>
</p>
<h3 class="function"><a name="send_req-6">send_req/6</a></h3>
@ -417,6 +423,6 @@ send_req/4, send_req/5, send_req/6.

<hr>
<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
<p><i>Generated by EDoc, Jul 29 2009, 18:43:30.</i></p>
<p><i>Generated by EDoc, Sep 5 2009, 23:59:48.</i></p>
</body>
</html>

+ 7
- 0
src/ibrowse.erl 查看文件

@ -228,6 +228,10 @@ send_req(Url, Headers, Method, Body) ->
%% </li>
%% </ul>
%%
%% <li> The <code>socket_options</code> option can be used to set
%% specific options on the socket. The <code>{active, true | false | once}</code>
%% and <code>{packet_type, Packet_type}</code> will be filtered out by ibrowse. </li>
%%
%% @spec send_req(Url::string(), Headers::headerList(), Method::method(), Body::body(), Options::optionList()) -> response()
%% optionList() = [option()]
%% option() = {max_sessions, integer()} |
@ -253,6 +257,7 @@ send_req(Url, Headers, Method, Body) ->
%% {host_header, string()} |
%% {inactivity_timeout, integer()} |
%% {connect_timeout, integer()} |
%% {socket_options, Sock_opts} |
%% {transfer_encoding, {chunked, ChunkSize}}
%%
%% stream_to() = process() | {process(), once}
@ -260,6 +265,8 @@ send_req(Url, Headers, Method, Body) ->
%% username() = string()
%% password() = string()
%% SSLOpt = term()
%% Sock_opts = [Sock_opt]
%% Sock_opt = term()
%% ChunkSize = integer()
%% srtf() = boolean() | filename()
%% filename() = string()

+ 13
- 6
src/ibrowse_http_client.erl 查看文件

@ -52,6 +52,7 @@
-record(request, {url, method, options, from,
stream_to, caller_controls_socket = false,
caller_socket_options = [],
req_id,
stream_chunk_size,
save_response_to_file = false,
@ -461,6 +462,7 @@ active_once(#state{cur_req = #request{caller_controls_socket = true}}) ->
active_once(#state{socket = Socket, is_ssl = Is_ssl}) ->
do_setopts(Socket, [{active, once}], Is_ssl).
do_setopts(_Sock, [], _) -> ok;
do_setopts(Sock, Opts, true) -> ssl:setopts(Sock, Opts);
do_setopts(Sock, Opts, false) -> inet:setopts(Sock, Opts).
@ -517,9 +519,12 @@ send_req_1(From,
port = Port,
path = RelPath} = Url,
Headers, Method, Body, Options, Timeout,
#state{status = Status} = State) ->
#state{status = Status,
socket = Socket,
is_ssl = Is_ssl} = State) ->
ReqId = make_req_id(),
Resp_format = get_value(response_format, Options, list),
Caller_socket_options = get_value(socket_options, Options, []),
{StreamTo, Caller_controls_socket} =
case get_value(stream_to, Options, undefined) of
{Caller, once} when is_pid(Caller) or
@ -540,6 +545,7 @@ send_req_1(From,
method = Method,
stream_to = StreamTo,
caller_controls_socket = Caller_controls_socket,
caller_socket_options = Caller_socket_options,
options = Options,
req_id = ReqId,
save_response_to_file = SaveResponseToFile,
@ -547,7 +553,7 @@ send_req_1(From,
response_format = Resp_format,
from = From},
State_1 = State#state{reqs=queue:in(NewReq, State#state.reqs)},
Headers_1 = add_auth_headers(Url, Options, Headers, State),
Headers_1 = add_auth_headers(Url, Options, Headers, State_1),
HostHeaderValue = case lists:keysearch(host_header, 1, Options) of
false ->
case Port of
@ -559,7 +565,7 @@ send_req_1(From,
end,
{Req, Body_1} = make_request(Method,
[{"Host", HostHeaderValue} | Headers_1],
AbsPath, RelPath, Body, Options, State#state.use_proxy),
AbsPath, RelPath, Body, Options, State_1#state.use_proxy),
case get(my_trace_flag) of
true ->
%%Avoid the binary operations if trace is not on...
@ -569,12 +575,13 @@ send_req_1(From,
"--- Request End ---~n", [NReq]);
_ -> ok
end,
case do_send(Req, State) of
do_setopts(Socket, Caller_socket_options, Is_ssl),
case do_send(Req, State_1) of
ok ->
case do_send_body(Body_1, State) of
case do_send_body(Body_1, State_1) of
ok ->
State_2 = inc_pipeline_counter(State_1),
active_once(State_1),
active_once(State_2),
Ref = case Timeout of
infinity ->
undefined;

+ 1
- 1
vsn.mk 查看文件

@ -1,2 +1,2 @@
IBROWSE_VSN = 1.5.2
IBROWSE_VSN = 1.5.3

Loading…
取消
儲存