Skip to content
This repository
Browse code

Fix "100-continue" support

I guess it didn't work properly long time...  Fixed #116. Thanks for
reporting!
  • Loading branch information...
commit 80a79185eda288bb5f6f4b3ead4e5692ddee230c 1 parent 6c2ebb0
Hiroshi Nakamura authored October 07, 2012
16  lib/httpclient/session.rb
@@ -874,17 +874,17 @@ def parse_header
874 874
       timeout(@receive_timeout, ReceiveTimeoutError) do
875 875
         initial_line = nil
876 876
         begin
877  
-          initial_line = @socket.gets("\n")
878  
-          if initial_line.nil?
  877
+          begin
  878
+            initial_line = @socket.gets("\n")
  879
+            if initial_line.nil?
  880
+              close
  881
+              raise KeepAliveDisconnected.new(self)
  882
+            end
  883
+          rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE, IOError
  884
+            # JRuby can raise IOError instead of ECONNRESET for now
879 885
             close
880 886
             raise KeepAliveDisconnected.new(self)
881 887
           end
882  
-        rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE, IOError
883  
-          # JRuby can raise IOError instead of ECONNRESET for now
884  
-          close
885  
-          raise KeepAliveDisconnected.new(self)
886  
-        end
887  
-        begin
888 888
           if StatusParseRegexp !~ initial_line
889 889
             @version = '0.9'
890 890
             @status = nil
21  test/test_httpclient.rb
@@ -1540,6 +1540,16 @@ def test_charset
1540 1540
     end
1541 1541
   end
1542 1542
 
  1543
+  if RUBY_VERSION >= "1.9.3"
  1544
+    def test_continue
  1545
+      @client.debug_dev = str = ''
  1546
+      res = @client.get(serverurl + 'continue', :header => {:Expect => '100-continue'})
  1547
+      assert_equal(200, res.status)
  1548
+      assert_equal('done!', res.body)
  1549
+      assert_match(/Expect: 100-continue/, str)
  1550
+    end
  1551
+  end
  1552
+
1543 1553
 private
1544 1554
 
1545 1555
   def check_query_get(query)
@@ -1563,7 +1573,11 @@ def setup_server
1563 1573
       :DocumentRoot => File.dirname(File.expand_path(__FILE__))
1564 1574
     )
1565 1575
     @serverport = @server.config[:Port]
1566  
-    [:hello, :sleep, :servlet_redirect, :redirect1, :redirect2, :redirect3, :redirect_self, :relative_redirect, :chunked, :largebody, :status, :compressed, :charset].each do |sym|
  1576
+    [
  1577
+      :hello, :sleep, :servlet_redirect, :redirect1, :redirect2, :redirect3,
  1578
+      :redirect_self, :relative_redirect, :chunked, :largebody, :status,
  1579
+      :compressed, :charset, :continue
  1580
+    ].each do |sym|
1567 1581
       @server.mount(
1568 1582
         "/#{sym}",
1569 1583
         WEBrick::HTTPServlet::ProcHandler.new(method("do_#{sym}").to_proc)
@@ -1654,6 +1668,11 @@ def do_status(req, res)
1654 1668
     res.status = req.query['status'].to_i
1655 1669
   end
1656 1670
 
  1671
+  def do_continue(req, res)
  1672
+    req.continue
  1673
+    res.body = 'done!'
  1674
+  end
  1675
+
1657 1676
   class TestServlet < WEBrick::HTTPServlet::AbstractServlet
1658 1677
     def get_instance(*arg)
1659 1678
       self

0 notes on commit 80a7918

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