Skip to content
This repository
Browse code

Fixed issue 67

  • Loading branch information...
commit 1fc0bc41e070d5f55c092ccfda1c5a3b1bb2f4ef 1 parent 47cdce0
Chandrashekhar Mullaparthi authored April 06, 2012
4  CHANGELOG
... ...
@@ -1,5 +1,9 @@
1 1
 CONTRIBUTIONS & CHANGE HISTORY
2 2
 ==============================
  3
+06-04-2012 - v3.0.4
  4
+             * Fix for the following issue
  5
+               https://github.com/cmullaparthi/ibrowse/issues/67
  6
+
3 7
 13-03-2012 - v3.0.3
4 8
              * Fixes the following issues
5 9
                https://github.com/cmullaparthi/ibrowse/issues/64
1  CONTRIBUTORS
@@ -29,6 +29,7 @@ Paul J. Davis
29 29
 Peter Kristensen
30 30
 Ram Krishnan
31 31
 Richard Cameron
  32
+Ryan Flynn
32 33
 Ryan Zezeski
33 34
 Sean Hinde
34 35
 Sergey Samokhi
2  README.md
Source Rendered
@@ -7,7 +7,7 @@ ibrowse is a HTTP client written in erlang.
7 7
 
8 8
 **Comments to:** chandrashekhar.mullaparthi@gmail.com
9 9
 
10  
-**Current Version:** 3.0.3
  10
+**Current Version:** 3.0.4
11 11
 
12 12
 **Latest Version:** git://github.com/cmullaparthi/ibrowse.git
13 13
 
4  src/ibrowse.app.src
... ...
@@ -1,6 +1,6 @@
1 1
 {application, ibrowse,
2  
-        [{description, "HTTP client application"},
3  
-         {vsn, "3.0.3"},
  2
+        [{description, "Erlang HTTP client application"},
  3
+         {vsn, "3.0.4"},
4 4
          {modules, [ ibrowse, 
5 5
 		     ibrowse_http_client, 
6 6
 		     ibrowse_app, 
10  src/ibrowse_http_client.erl
@@ -1047,7 +1047,13 @@ parse_response(Data, #state{reply_buffer = Acc, reqs = Reqs,
1047 1047
                     do_error_reply(State#state{reqs = Reqs_1},
1048 1048
                                    {error, proxy_tunnel_failed}),
1049 1049
                     {error, proxy_tunnel_failed};
1050  
-                _ when Method == head ->
  1050
+                _ when Method == head,
  1051
+                       TransferEncoding =/= "chunked" ->
  1052
+                    %% This is not supposed to happen, but it does. An
  1053
+                    %% Apache server was observed to send an "empty"
  1054
+                    %% body, but in a Chunked-Transfer-Encoding way,
  1055
+                    %% which meant there was still a body.
  1056
+                    %% Issue #67 on Github
1051 1057
                     {_, Reqs_1} = queue:out(Reqs),
1052 1058
                     send_async_headers(ReqId, StreamTo, Give_raw_headers, State_1),
1053 1059
                     State_1_1 = do_reply(State_1, From, StreamTo, ReqId, Resp_format,
@@ -1091,7 +1097,7 @@ parse_response(Data, #state{reply_buffer = Acc, reqs = Reqs,
1091 1097
                             State_2
1092 1098
                     end;
1093 1099
                 undefined when HttpVsn =:= "HTTP/1.0";
1094  
-                ConnClose =:= "close" ->
  1100
+                               ConnClose =:= "close" ->
1095 1101
                     send_async_headers(ReqId, StreamTo, Give_raw_headers, State_1),
1096 1102
                     State_1#state{reply_buffer = Data_1};
1097 1103
                 undefined ->
22  src/ibrowse_test.erl
@@ -23,7 +23,9 @@
23 23
          test_20122010/1,
24 24
          test_pipeline_head_timeout/0,
25 25
          test_pipeline_head_timeout/1,
26  
-         do_test_pipeline_head_timeout/4
  26
+         do_test_pipeline_head_timeout/4,
  27
+         test_head_transfer_encoding/0,
  28
+         test_head_transfer_encoding/1
27 29
 	]).
28 30
 
29 31
 test_stream_once(Url, Method, Options) ->
@@ -227,7 +229,8 @@ dump_errors(Key, Iod) ->
227 229
 		    {"http://www.httpwatch.com/httpgallery/chunked/", get},
228 230
                     {"https://github.com", get, [{ssl_options, [{depth, 2}]}]},
229 231
                     {local_test_fun, test_20122010, []},
230  
-                    {local_test_fun, test_pipeline_head_timeout, []}
  232
+                    {local_test_fun, test_pipeline_head_timeout, []},
  233
+                    {local_test_fun, test_head_transfer_encoding, []}
231 234
 		   ]).
232 235
 
233 236
 unit_tests() ->
@@ -436,7 +439,22 @@ log_msg(Fmt, Args) ->
436 439
     io:format("~s -- " ++ Fmt,
437 440
 	      [ibrowse_lib:printable_date() | Args]).
438 441
 
  442
+%%------------------------------------------------------------------------------
  443
+%% Test what happens when the response to a HEAD request is a
  444
+%% Chunked-Encoding response with a non-empty body. Issue #67 on
  445
+%% Github
  446
+%% ------------------------------------------------------------------------------
  447
+test_head_transfer_encoding() ->
  448
+    clear_msg_q(),
  449
+    test_head_transfer_encoding("http://localhost:8181/ibrowse_head_transfer_enc").
439 450
 
  451
+test_head_transfer_encoding(Url) ->
  452
+    case ibrowse:send_req(Url, [], head) of
  453
+        {ok, "400", _, _} ->
  454
+            success;
  455
+        Res ->
  456
+            {test_failed, Res}
  457
+    end.
440 458
 %%------------------------------------------------------------------------------
441 459
 %% Test what happens when the request at the head of a pipeline times out
442 460
 %%------------------------------------------------------------------------------
10  test/ibrowse_test_server.erl
@@ -35,7 +35,7 @@ start_server(Port, Sock_type) ->
35 35
     spawn_link(Fun).
36 36
 
37 37
 stop_server(Port) ->
38  
-    catch exit(whereis(server_proc_name(Port)), kill),
  38
+    server_proc_name(Port) ! stop,
39 39
     ok.
40 40
 
41 41
 server_proc_name(Port) ->
@@ -99,6 +99,8 @@ server_loop(Sock, Sock_type, #request{headers = Headers} = Req) ->
99 99
         {tcp_closed, Sock} ->
100 100
             do_trace("Client closed connection~n", []),
101 101
             ok;
  102
+        stop ->
  103
+            ok;
102 104
         Other ->
103 105
             do_trace("Recvd unknown msg: ~p~n", [Other]),
104 106
             exit({unknown_msg, Other})
@@ -145,6 +147,12 @@ process_request(Sock, Sock_type,
145 147
     do_trace("...Sending response now.~n", []),
146 148
     Resp = <<"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n">>,
147 149
     do_send(Sock, Sock_type, Resp);
  150
+process_request(Sock, Sock_type,
  151
+                #request{method='HEAD',
  152
+                         headers = _Headers,
  153
+                         uri = {abs_path, "/ibrowse_head_transfer_enc"}}) ->
  154
+    Resp = <<"HTTP/1.1 400 Bad Request\r\nServer: Apache-Coyote/1.1\r\nTransfer-Encoding: chunked\r\nDate: Wed, 04 Apr 2012 16:53:49 GMT\r\nConnection: close\r\n\r\n0\r\n\r\n">>,
  155
+    do_send(Sock, Sock_type, Resp);
148 156
 process_request(Sock, Sock_type, Req) ->
149 157
     do_trace("Recvd req: ~p~n", [Req]),
150 158
     Resp = <<"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n">>,

0 notes on commit 1fc0bc4

Seth Falcon

I think this is supposed to be == not =/= since this clause is meant to handle the odd case of a HEAD request response from a server that answers the HEAD request with chunked transfer encoding.

Please sign in to comment.
Something went wrong with that request. Please try again.