Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add recv_timeout option

  • Loading branch information...
commit 5aff16529ef351b9696d711d889aae4b7f35bd95 1 parent efd877f
@benoitc authored
View
3  doc/hackney.md
@@ -197,6 +197,9 @@ redirection even on POST
* insecure: to perform "insecure" SSL connections and
transfers without checking the certificate
+* {recv_timeout, infinity | integer()}: timeout used when
+receiving a connection. Default is infinity
+
View
2  doc/hackney_request.md
@@ -57,5 +57,5 @@
###stream_body/2##
-`stream_body(Body, Client) -> any()`
+`stream_body(Func, Client) -> any()`
View
2  include/hackney.hrl
@@ -42,7 +42,7 @@
netloc = netloc,
options = [],
socket = nil,
- timeout = infinity,
+ recv_timeout = infinity,
follow_redirect = false,
max_redirect = 5,
force_redirect = false,
View
12 src/hackney.erl
@@ -80,7 +80,9 @@ connect(Transport, Host, Port, #client{socket=Skt, options=Opts}=Client)
socket_from_pool(Pool, {Transport, Host, Port}, Client)
end;
connect(Transport, Host, Port, Options) when is_list(Options) ->
- connect(Transport, Host, Port, #client{options=Options}).
+ Timeout = proplists:get_value(recv_timeout, Options, infinity),
+ connect(Transport, Host, Port, #client{recv_timeout=Timeout,
+ options=Options}).
%% @doc close the client
close(Client) ->
@@ -159,6 +161,8 @@ request(Method, URL, Headers, Body) ->
%% <li>{proxy, proxy_options()}: to connect via a proxy.</li>
%% <li>insecure: to perform "insecure" SSL connections and
%% transfers without checking the certificate</li>
+%% <li>{recv_timeout, infinity | integer()}: timeout used when
+%% receiving a connection. Default is infinity</li>
%% </ul>
%%
%% </li>
@@ -332,13 +336,15 @@ maybe_proxy(Transport, Host, Port, Options)
connect(Transport, Host, Port, Options)
end.
-connect_proxy(ProxyUrl, Host, Port, ProxyOpts, Options) ->
+connect_proxy(ProxyUrl, Host, Port, ProxyOpts0, Options) ->
Host = iolist_to_binary([Host, ":", integer_to_list(Port)]),
Headers = [{<<"Host">>, Host}],
+ Timeout = proplists:get_value(recv_timeout, Options, infinity),
+ ProxyOpts = [{recv_timeout, Timeout} | ProxyOpts0],
case request(connect, ProxyUrl, Headers, <<>>, ProxyOpts) of
{ok, 200, _, Client0} ->
Client = skip_body(Client0),
- {ok, Client#client{options=Options}};
+ {ok, Client#client{recv_timeout=Timeout, options=Options}};
{ok, S, H, Client} ->
Body = body(Client),
{error, {proxy_connection, S, H, Body}};
View
9 src/hackney_response.erl
@@ -156,9 +156,8 @@ stream_body(Client=#client{body_state=done}) ->
-spec stream_body_recv(#client{})
-> {ok, binary(), #client{}} | {error, atom()}.
-stream_body_recv(Client=#client{
- transport=Transport, socket=Socket, buffer=Buffer}) ->
- case Transport:recv(Socket, 0, 5000) of
+stream_body_recv(Client=#client{buffer=Buffer}) ->
+ case recv(Client) of
{ok, Data} -> transfer_decode(<< Buffer/binary, Data/binary >>,
Client);
{error, Reason} -> {error, Reason}
@@ -323,8 +322,8 @@ te_identity(Data, {Streamed, Total}) ->
ce_identity(Data) ->
{ok, Data}.
-recv(#client{transport=Transport, socket=Skt}) ->
- Transport:recv(Skt, 0).
+recv(#client{transport=Transport, socket=Skt, recv_timeout=Timeout}) ->
+ Transport:recv(Skt, 0, Timeout).
close(#client{socket=nil}=Client) ->
Please sign in to comment.
Something went wrong with that request. Please try again.