From 74c337792a5cfc81211ce368648ce425f1fbb297 Mon Sep 17 00:00:00 2001 From: Chandrashekhar Mullaparthi Date: Thu, 20 Jan 2011 06:34:48 +0000 Subject: [PATCH] Various changes. See README for details --- Makefile | 3 ++- README | 19 ++++++++++++++++++- ebin/ibrowse.app | 2 +- src/Makefile | 2 +- src/ibrowse.erl | 18 +++++++++--------- src/ibrowse_http_client.erl | 29 ++++++++++++++++------------- test/Makefile | 21 +++++++++++++++++++++ test/ibrowse_test_server.erl | 12 ++++++++---- vsn.mk | 2 +- 9 files changed, 77 insertions(+), 31 deletions(-) create mode 100644 test/Makefile diff --git a/Makefile b/Makefile index 2380676..a547e97 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ include vsn.mk all: (cd src ; make) + (cd test ; make) clean: (cd src ; make clean) @@ -11,7 +12,7 @@ install: all cp -r ebin $(DESTDIR)/lib/ibrowse-$(IBROWSE_VSN)/ test: all - erl -noshell -pa ebin -s ibrowse -s ibrowse_test unit_tests \ + erl -noshell -pa ebin -pa test -s ibrowse -s ibrowse_test unit_tests \ -s ibrowse_test verify_chunked_streaming \ -s ibrowse_test test_chunked_streaming_once \ -s erlang halt diff --git a/README b/README index d47f28d..42173fe 100644 --- a/README +++ b/README @@ -18,7 +18,7 @@ ibrowse is available under two different licenses. LGPL or the BSD license. Comments to : Chandrashekhar.Mullaparthi@gmail.com -Version : 2.1.2 +Version : 2.1.3 Latest version : git://github.com/cmullaparthi/ibrowse.git @@ -56,10 +56,27 @@ Seth Falcon Steve Vinoski Thomas Lindgren Younès Hafri +fholzhauser (https://github.com/fholzhauser/) tholschuh (https://github.com/tholschuh/) CONTRIBUTIONS & CHANGE HISTORY ============================== +16-01-2011 - v2.1.3 + * Fixed issues with streaming and chunked responses when using + the 'caller controls socket' feature. See following links for + details. Contributed by Filipe David Manana. + https://github.com/cmullaparthi/ibrowse/pull/24 + https://github.com/cmullaparthi/ibrowse/pull/25 + https://github.com/cmullaparthi/ibrowse/pull/27 + https://github.com/cmullaparthi/ibrowse/pull/28 + https://github.com/cmullaparthi/ibrowse/pull/29 + + * Fix for issue 32 reported by fholzhauser + https://github.com/cmullaparthi/ibrowse/issues#issue/32 + + * Fixed some dialyzer warnings. Thanks to Kostis for reporting + them. + 20-12-2010 - v2.1.2 * Pipelining wasn't working when used in conjunction with the {stream_to, {self(), once}} option. Bug report by diff --git a/ebin/ibrowse.app b/ebin/ibrowse.app index c8e4227..875620d 100644 --- a/ebin/ibrowse.app +++ b/ebin/ibrowse.app @@ -1,6 +1,6 @@ {application, ibrowse, [{description, "HTTP client application"}, - {vsn, "2.1.2"}, + {vsn, "2.1.3"}, {modules, [ ibrowse, ibrowse_http_client, ibrowse_app, diff --git a/src/Makefile b/src/Makefile index 145c0a2..9c1bf63 100644 --- a/src/Makefile +++ b/src/Makefile @@ -13,7 +13,7 @@ INCLUDE_DIRS = -I./ ERLC ?= erlc ERLC_EMULATOR ?= erl -boot start_clean -COMPILER_OPTIONS = -W +warn_unused_vars +nowarn_shadow_vars +warn_unused_import +COMPILER_OPTIONS = -W +debug_info +warn_unused_vars +nowarn_shadow_vars +warn_unused_import .SUFFIXES: .erl .beam $(SUFFIXES) EBIN = ../ebin diff --git a/src/ibrowse.erl b/src/ibrowse.erl index e105150..f70f92f 100644 --- a/src/ibrowse.erl +++ b/src/ibrowse.erl @@ -6,8 +6,8 @@ %%% Created : 11 Oct 2003 by Chandrashekhar Mullaparthi %%%------------------------------------------------------------------- %% @author Chandrashekhar Mullaparthi -%% @copyright 2005-2010 Chandrashekhar Mullaparthi -%% @version 2.1.2 +%% @copyright 2005-2011 Chandrashekhar Mullaparthi +%% @version 2.1.3 %% @doc The ibrowse application implements an HTTP 1.1 client in erlang. 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 @@ -683,16 +683,16 @@ init(_) -> State = #state{}, put(my_trace_flag, State#state.trace), put(ibrowse_trace_token, "ibrowse"), - ets:new(ibrowse_lb, [named_table, public, {keypos, 2}]), - ets:new(ibrowse_conf, [named_table, protected, {keypos, 2}]), - ets:new(ibrowse_stream, [named_table, public]), + ibrowse_lb = ets:new(ibrowse_lb, [named_table, public, {keypos, 2}]), + ibrowse_conf = ets:new(ibrowse_conf, [named_table, protected, {keypos, 2}]), + ibrowse_stream = ets:new(ibrowse_stream, [named_table, public]), import_config(), {ok, #state{}}. import_config() -> case code:priv_dir(ibrowse) of - {error, _} = Err -> - Err; + {error, _} -> + ok; PrivDir -> Filename = filename:join(PrivDir, "ibrowse.conf"), import_config(Filename) @@ -723,8 +723,8 @@ import_config(Filename) -> io:format("Skipping unrecognised term: ~p~n", [X]) end, lists:foreach(Fun, Terms); - Err -> - Err + _Err -> + ok end. %% @doc Internal export diff --git a/src/ibrowse_http_client.erl b/src/ibrowse_http_client.erl index 774142a..7d606e6 100644 --- a/src/ibrowse_http_client.erl +++ b/src/ibrowse_http_client.erl @@ -216,12 +216,14 @@ handle_info({ssl_closed, _Sock}, State) -> handle_sock_closed(State), {stop, normal, State}; -handle_info({tcp_error, _Sock}, State) -> - do_trace("Error on connection to ~1000.p:~1000.p~n", [State#state.host, State#state.port]), +handle_info({tcp_error, _Sock, Reason}, State) -> + do_trace("Error on connection to ~1000.p:~1000.p -> ~1000.p~n", + [State#state.host, State#state.port, Reason]), handle_sock_closed(State), {stop, normal, State}; -handle_info({ssl_error, _Sock}, State) -> - do_trace("Error on SSL connection to ~1000.p:~1000.p~n", [State#state.host, State#state.port]), +handle_info({ssl_error, _Sock, Reason}, State) -> + do_trace("Error on SSL connection to ~1000.p:~1000.p -> ~1000.p~n", + [State#state.host, State#state.port, Reason]), handle_sock_closed(State), {stop, normal, State}; @@ -466,7 +468,7 @@ handle_sock_closed(#state{reply_buffer = Buf, reqs = Reqs, http_status_code = SC undefined -> Buf; _ -> - file:close(Fd), + ok = file:close(Fd), {file, TmpFilename} end, Reply = case get_value(give_raw_headers, Options, false) of @@ -475,11 +477,11 @@ handle_sock_closed(#state{reply_buffer = Buf, reqs = Reqs, http_status_code = SC false -> {ok, SC, Headers, Buf} end, - do_reply(State, From, StreamTo, ReqId, Resp_format, Reply), - do_error_reply(State#state{reqs = Reqs_1}, connection_closed), - State; + State_1 = do_reply(State, From, StreamTo, ReqId, Resp_format, Reply), + ok = do_error_reply(State_1#state{reqs = Reqs_1}, connection_closed), + State_1; _ -> - do_error_reply(State, connection_closed), + ok = do_error_reply(State, connection_closed), State end. @@ -1276,7 +1278,7 @@ handle_response(#request{from=From, stream_to=StreamTo, req_id=ReqId, reply_buffer = RepBuf, recvd_headers = RespHeaders}=State) when SaveResponseToFile /= false -> Body = RepBuf, - file:close(Fd), + ok = file:close(Fd), ResponseBody = case TmpFilename of undefined -> Body; @@ -1663,8 +1665,8 @@ fail_pipelined_requests(#state{reqs = Reqs, cur_req = CurReq} = State, Reply) -> {_, Reqs_1} = queue:out(Reqs), #request{from=From, stream_to=StreamTo, req_id=ReqId, response_format = Resp_format} = CurReq, - do_reply(State, From, StreamTo, ReqId, Resp_format, Reply), - do_error_reply(State#state{reqs = Reqs_1}, previous_request_failed). + State_1 = do_reply(State, From, StreamTo, ReqId, Resp_format, Reply), + do_error_reply(State_1#state{reqs = Reqs_1}, previous_request_failed). split_list_at(List, N) -> split_list_at(List, N, []). @@ -1708,7 +1710,8 @@ to_ascii($9) -> 9; to_ascii($0) -> 0. cancel_timer(undefined) -> ok; -cancel_timer(Ref) -> erlang:cancel_timer(Ref). +cancel_timer(Ref) -> _ = erlang:cancel_timer(Ref), + ok. cancel_timer(Ref, {eat_message, Msg}) -> cancel_timer(Ref), diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..fa221bf --- /dev/null +++ b/test/Makefile @@ -0,0 +1,21 @@ +include ../vsn.mk + +ERL_FILES = ibrowse_test_server.erl + + +INCLUDE_DIRS = -I./ + +ERLC ?= erlc +ERLC_EMULATOR ?= erl -boot start_clean +COMPILER_OPTIONS = -W +warn_unused_vars +nowarn_shadow_vars +warn_unused_import + +.SUFFIXES: .erl .beam $(SUFFIXES) + +all: $(ERL_FILES:%.erl=%.beam) + +%.beam: %.erl + ${ERLC} $(COMPILER_OPTIONS) $(INCLUDE_DIRS) -o ./ $< + +clean: + rm -f *.beam + diff --git a/test/ibrowse_test_server.erl b/test/ibrowse_test_server.erl index d3b66bc..45c6958 100644 --- a/test/ibrowse_test_server.erl +++ b/test/ibrowse_test_server.erl @@ -17,18 +17,22 @@ start_server(Port, Sock_type) -> Fun = fun() -> register(server_proc_name(Port), self()), case do_listen(Sock_type, Port, [{active, false}, + {reuseaddr, true}, {nodelay, true}, {packet, http}]) of {ok, Sock} -> do_trace("Server listening on port: ~p~n", [Port]), accept_loop(Sock, Sock_type); Err -> - do_trace("Failed to start server on port ~p. ~p~n", - [Port, Err]), - Err + erlang:error( + lists:flatten( + io_lib:format( + "Failed to start server on port ~p. ~p~n", + [Port, Err]))), + exit({listen_error, Err}) end end, - spawn(Fun). + spawn_link(Fun). stop_server(Port) -> exit(whereis(server_proc_name(Port)), kill). diff --git a/vsn.mk b/vsn.mk index ac4bf7a..235c0ca 100644 --- a/vsn.mk +++ b/vsn.mk @@ -1,2 +1,2 @@ -IBROWSE_VSN = 2.1.2 +IBROWSE_VSN = 2.1.3