Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many changes to the lhttpc client #32

Closed
wants to merge 49 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
fb133d0
Totally restructure the lhttpc client. lhttpc_client is now a gen_ser…
lastres Jan 21, 2013
e8454f5
Remove lhttpc_manager from supervisor init(). Fix bug in ensure_call …
lastres Jan 22, 2013
7451086
Improve format, remove comented lines and add doc to some functions.
lastres Jan 22, 2013
6739c3f
Fix error to allow to specify only a patch when calling request_client.
lastres Jan 22, 2013
7246e43
Fix client reconnect problem when server returns headers to close con…
lastres Jan 22, 2013
01686bf
Change response format from Reply to {ok, Reply}.
lastres Jan 22, 2013
dfbd50a
Do not close the socket in terminate if it is undefined. (it was alre…
lastres Jan 22, 2013
59a0eef
Fix some test cases.
lastres Jan 22, 2013
d48be4f
Fix connect functionality and attempts to reconnect
Jan 23, 2013
b0434e7
Fix typo error in call parameters
Jan 23, 2013
5c1a452
Refactor test code to reuse in other suites
Jan 23, 2013
5acc7bc
Fix some issues related with read body part functions.
lastres Jan 23, 2013
ef3aacd
Fix get_body_parts size control for fixed length bodies
Jan 23, 2013
afcb0b2
Fix get body parts for fixed length messages and some parameters conf…
Jan 24, 2013
58bc3f9
Fix error related with connection_close test. (exception made gen_ser…
lastres Jan 24, 2013
3f8abe0
Remove message_queue test. Uncomment tests that already pass.
lastres Jan 24, 2013
bc05108
Fix error related with suspende_manager test case (timeout when conne…
lastres Jan 24, 2013
8930896
Fix errors found by dialyzer. Now dialyzer test pass without problems.
lastres Jan 24, 2013
43251f8
Fix partial upload/download
Jan 24, 2013
d5efe12
some lhttpc unit tests fixed
Jan 25, 2013
ef95f8c
Add cookie handling. It just extracts the cookies from the response h…
lastres Jan 25, 2013
9b76b95
Include cookies in the request.
lastres Jan 25, 2013
a1a74a2
Reewrite cookies with the same name instead of rewriting them, check …
lastres Jan 28, 2013
049d2e0
Include option to automatically handle cookies or not {use_cookies, t…
lastres Jan 28, 2013
7d2bf87
Include support for Expires and Max-Age attributes in cookie handling.
lastres Jan 28, 2013
750c426
Add tests for the cookie handling. Fix a couple of errors when handli…
lastres Jan 29, 2013
a33837b
Reestructure some code in cookie handling.
lastres Jan 29, 2013
cc25437
Code refactor
Jan 29, 2013
b7a8643
Code refactor
Jan 29, 2013
681bfc9
Do not allow to send requests to a different host of port than to the…
lastres Jan 30, 2013
e26b103
Refactor some code to avoid too long functions.
lastres Jan 30, 2013
ffa1199
Fix bug in lhttpc_lib.erl
lastres Jan 30, 2013
cea773d
Fix error in the specs.
lastres Jan 30, 2013
7a9b9c6
better handling connect errors such as econnrefused
maxlapshin Feb 19, 2013
89be030
Change "Dic" for "Dec" in the month_to_integer function.
lastres Mar 5, 2013
a38e67a
Quick fix that allows to add the cookies if the path is a prefix.
lastres Mar 5, 2013
6f96e84
fix: path is not required in a cookie, from http://www.ietf.org/rfc/r…
Mar 11, 2013
14594cf
Fix edoc so it doesn't emit errors during compilation
Apr 24, 2013
5641f3d
Refactor connect_socket function
Apr 24, 2013
fad2c7b
Code refactor and formating
Apr 24, 2013
1efb030
Replace string:to_lower with a faster version
Apr 24, 2013
bb3d2a4
Remove warning from tests
Apr 24, 2013
4d97d86
Improvements on the documentation
lastres Aug 29, 2013
b9705c9
Use a nicer style for the edocs
lastres Aug 29, 2013
13be6ea
Fix type errors. Remove unused functions. Fix documentation
lastres Aug 30, 2013
e72afef
Add a better README file
lastres Aug 30, 2013
83d4262
Update the copyright lines
lastres Sep 2, 2013
41ea97f
Remove old files not needed anymore
lastres Sep 2, 2013
1348887
Small additions to the Readme.md
lastres Sep 2, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix partial upload/download
Diana Corbacho authored and lastres committed Aug 28, 2013
commit 43251f8f3872f7725ebee732b299f19c413e8610
4 changes: 2 additions & 2 deletions src/lhttpc.erl
Original file line number Diff line number Diff line change
@@ -689,8 +689,8 @@ verify_options([{connect_timeout, infinity} | Options]) ->
verify_options([{connect_timeout, MS} | Options])
when is_integer(MS), MS >= 0 ->
verify_options(Options);
verify_options([{partial_upload, WindowSize} | Options])
when is_integer(WindowSize), WindowSize >= 0 ->
verify_options([{partial_upload, Bool} | Options])
when is_boolean(Bool) ->
verify_options(Options);
verify_options([{partial_upload, infinity} | Options]) ->
verify_options(Options);
26 changes: 13 additions & 13 deletions src/lhttpc_client.erl
Original file line number Diff line number Diff line change
@@ -211,8 +211,7 @@ handle_call({request, Path, Method, Hdrs, Body, Options}, From,
proxy_setup = (Socket =/= undefined),
proxy_ssl_options = proplists:get_value(proxy_ssl_options, Options, [])
},
{Response, NewState2} = send_request(NewState),
{reply, Response, NewState2};
send_request(NewState);
handle_call(_Msg, _From, #client_state{request = undefined} = State) ->
{reply, {error, no_pending_request}, State};
handle_call({send_body_part, _}, _From, State = #client_state{partial_upload = false}) ->
@@ -223,7 +222,7 @@ handle_call(get_body_part, _From, State = #client_state{partial_download = false
{reply, {error, no_partial_download}, State};
handle_call(_Msg, _From, #client_state{socket = undefined} = State) ->
{reply, {error, connection_closed}, State#client_state{request = undefined}};
handle_call({trailers, Trailers}, _From, State) ->
handle_call({send_trailers, Trailers}, _From, State) ->
case send_trailers(State, Trailers) of
{ok, NewState} ->
read_response(NewState);
@@ -331,14 +330,14 @@ send_body_part(State = #client_state{socket = Socket, ssl = Ssl}, BodyPart) ->
%% @end
%%------------------------------------------------------------------------------
send_request(#client_state{attempts = 0} = State) ->
{{error, connection_closed}, State#client_state{request = undefined}};
{reply, {error, connection_closed}, State#client_state{request = undefined}};
send_request(#client_state{socket = undefined} = State) ->
% if we dont get a keep alive from the previous request, the socket is undefined.
case connect_socket(State) of
{ok, NewState} ->
send_request(NewState);
{Error, NewState} ->
{Error, NewState}
{reply, Error, NewState}
end;
send_request(#client_state{proxy = #lhttpc_url{}, proxy_setup = false,
host = DestHost, port = Port, socket = Socket} = State) ->
@@ -369,13 +368,14 @@ send_request(#client_state{proxy = #lhttpc_url{}, proxy_setup = false,
],
case lhttpc_sock:send(Socket, ConnectRequest, Ssl) of
ok ->
read_proxy_connect_response(State, nil, nil);
{Reply, NewState} = read_proxy_connect_response(State, nil, nil),
{reply, Reply, NewState};
{error, closed} ->
close_socket(State),
{{error, proxy_connection_closed}, State#client_state{socket = undefined, request = undefined}};
{reply, {error, proxy_connection_closed}, State#client_state{socket = undefined, request = undefined}};
{error, _Reason} ->
close_socket(State),
{{error, proxy_connection_closed}, State#client_state{socket = undefined, request = undefined}}
{reply, {error, proxy_connection_closed}, State#client_state{socket = undefined, request = undefined}}
end;
send_request(#client_state{socket = Socket, ssl = Ssl, request = Request,
attempts = Attempts} = State) ->
@@ -385,7 +385,7 @@ send_request(#client_state{socket = Socket, ssl = Ssl, request = Request,
if
%% {partial_upload, WindowSize} is used.
State#client_state.partial_upload ->
{{ok, partial_upload}, State#client_state{attempts = 0}};
{reply, {ok, partial_upload}, State#client_state{attempts = 0}};
not State#client_state.partial_upload ->
read_response(State)
end;
@@ -395,7 +395,7 @@ send_request(#client_state{socket = Socket, ssl = Ssl, request = Request,
attempts = Attempts - 1});
{error, _Reason} ->
close_socket(State),
{{error, connection_closed}, State#client_state{socket = undefined,
{reply, {error, connection_closed}, State#client_state{socket = undefined,
request = undefined}}
end.

@@ -527,8 +527,8 @@ read_response(State, Vsn, {StatusCode, _} = Status, Hdrs) ->
NewHdrs = element(2, Reply),
ReqHdrs = State#client_state.request_headers,
NewSocket = maybe_close_socket(State, Vsn, ReqHdrs, NewHdrs),
{{ok, Reply}, NewState#client_state{socket = NewSocket,
request = undefined}}
{reply, {ok, Reply}, NewState#client_state{socket = NewSocket,
request = undefined}}
end;
{error, closed} ->
%% TODO does it work for partial uploads? I think should return an error
@@ -674,7 +674,7 @@ read_partial_finite_body(#client_state{download_proc = To} = State, ContentLengt
%finished the window, reply to ask for another call to get_body_part
To ! {body_part, window_finished},
State#client_state{body_length = {fixed_length, ContentLength}};
read_partial_finite_body(State, ContentLength, Window) when Window >= 0->
read_partial_finite_body(State, ContentLength, Window) when Window > 0->
case read_body_part(State, ContentLength) of
{ok, Bin} ->
State#client_state.download_proc ! {body_part, Bin},
Loading