Skip to content
This repository has been archived by the owner on Sep 19, 2019. It is now read-only.

Commit

Permalink
Fixed bug in processing of save_response_to_file option
Browse files Browse the repository at this point in the history
  • Loading branch information
Chandrashekhar Mullaparthi committed Sep 24, 2009
1 parent 2e6bff7 commit 75bab56
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
6 changes: 5 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ ibrowse is available under two different licenses. LGPL and the BSD license.

Comments to : Chandrashekhar.Mullaparthi@gmail.com

Version : 1.5.3
Version : 1.5.4

Latest version : git://github.com/cmullaparthi/ibrowse.git

CONTRIBUTIONS & CHANGE HISTORY
==============================
24-09-2009 - * When a filename was supplied with the 'save_response_to_file'
option, the option was being ignored. Bug report from
Adam Kocoloski

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
Expand Down
2 changes: 1 addition & 1 deletion src/ibrowse.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
%%%-------------------------------------------------------------------
%% @author Chandrashekhar Mullaparthi <chandrashekhar dot mullaparthi at gmail dot com>
%% @copyright 2005-2009 Chandrashekhar Mullaparthi
%% @version 1.5.2
%% @version 1.5.4
%% @doc The ibrowse application implements an HTTP 1.1 client. This
%% module implements the API of the HTTP client. There is one named
%% process called 'ibrowse' which assists in load balancing and maintaining configuration. There is one load balancing process per unique webserver. There is
Expand Down
20 changes: 11 additions & 9 deletions src/ibrowse_http_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ handle_sock_data(Data, #state{status = get_body,

accumulate_response(Data,
#state{
cur_req = #request{save_response_to_file = true,
cur_req = #request{save_response_to_file = Srtf,
tmp_file_fd = undefined} = CurReq,
http_status_code=[$2 | _]}=State) ->
TmpFilename = make_tmp_filename(),
http_status_code=[$2 | _]}=State) when Srtf /= false ->
TmpFilename = make_tmp_filename(Srtf),
case file:open(TmpFilename, [write, delayed_write, raw]) of
{ok, Fd} ->
accumulate_response(Data, State#state{
Expand All @@ -310,23 +310,23 @@ accumulate_response(Data,
{error, Reason} ->
{error, {file_open_error, Reason}}
end;
accumulate_response(Data, #state{cur_req = #request{save_response_to_file = true,
accumulate_response(Data, #state{cur_req = #request{save_response_to_file = Srtf,
tmp_file_fd = Fd},
transfer_encoding=chunked,
reply_buffer = Reply_buf,
http_status_code=[$2 | _]
} = State) ->
} = State) when Srtf /= false ->
case file:write(Fd, [Reply_buf, Data]) of
ok ->
State#state{reply_buffer = <<>>};
{error, Reason} ->
{error, {file_write_error, Reason}}
end;
accumulate_response(Data, #state{cur_req = #request{save_response_to_file = true,
accumulate_response(Data, #state{cur_req = #request{save_response_to_file = Srtf,
tmp_file_fd = Fd},
reply_buffer = RepBuf,
http_status_code=[$2 | _]
} = State) ->
} = State) when Srtf /= false ->
case file:write(Fd, [RepBuf, Data]) of
ok ->
State#state{reply_buffer = <<>>};
Expand Down Expand Up @@ -364,14 +364,16 @@ accumulate_response(Data, #state{reply_buffer = RepBuf,
State#state{reply_buffer = RepBuf_1}
end.

make_tmp_filename() ->
make_tmp_filename(true) ->
DownloadDir = ibrowse:get_config_value(download_dir, filename:absname("./")),
{A,B,C} = now(),
filename:join([DownloadDir,
"ibrowse_tmp_file_"++
integer_to_list(A) ++
integer_to_list(B) ++
integer_to_list(C)]).
integer_to_list(C)]);
make_tmp_filename(File) when is_list(File) ->
File.


%%--------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion vsn.mk
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
IBROWSE_VSN = 1.5.3
IBROWSE_VSN = 1.5.4

0 comments on commit 75bab56

Please sign in to comment.