Crashing when receiving a HTTP response with status code 100 (Continue) #116

Closed
morinmorin opened this Issue Sep 24, 2012 · 2 comments

Comments

Projects
None yet
2 participants

When parse_header (in session.rb) receives status code 100, it does not repeat reading initial_line. This makes my app crashing. To avoid the crash, the following code

initial_line = nil
begin
  initial_line = @socket.gets("\n")
  if initial_line.nil?
    close
    raise KeepAliveDisconnected.new(self)
  end
rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE, IOError
  # JRuby can raise IOError instead of ECONNRESET for now
  close
  raise KeepAliveDisconnected.new(self)
end

needs to be placed inside begin ... end while (@version == '1.1' && @status == 100) loop.

Patch attached.

OK, GitHub does not seem to allow attaching a file ;)
Here is a patch

diff --git a/lib/httpclient/session.rb b/lib/httpclient/session.rb
index f224a4c..d511470 100644
--- a/lib/httpclient/session.rb
+++ b/lib/httpclient/session.rb
@@ -872,19 +872,19 @@ class HTTPClient
     StatusParseRegexp = %r(\AHTTP/(\d+\.\d+)\s+(\d\d\d)\s*([^\r\n]+)?\r?\n\z)
     def parse_header
       timeout(@receive_timeout, ReceiveTimeoutError) do
-        initial_line = nil
         begin
-          initial_line = @socket.gets("\n")
-          if initial_line.nil?
+          initial_line = nil
+          begin
+            initial_line = @socket.gets("\n")
+            if initial_line.nil?
+              close
+              raise KeepAliveDisconnected.new(self)
+            end
+          rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE, IOError
+            # JRuby can raise IOError instead of ECONNRESET for now
             close
             raise KeepAliveDisconnected.new(self)
           end
-        rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE, IOError
-          # JRuby can raise IOError instead of ECONNRESET for now
-          close
-          raise KeepAliveDisconnected.new(self)
-        end
-        begin
           if StatusParseRegexp !~ initial_line
             @version = '0.9'
             @status = nil

nahi closed this in 80a7918 Oct 7, 2012

Owner

nahi commented Oct 7, 2012

I added this with a test. Thank you for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment