Permalink
Browse files

Fix "100-continue" support

I guess it didn't work properly long time...  Fixed #116. Thanks for
reporting!
  • Loading branch information...
nahi committed Oct 7, 2012
1 parent 6c2ebb0 commit 80a79185eda288bb5f6f4b3ead4e5692ddee230c
Showing with 28 additions and 9 deletions.
  1. +8 −8 lib/httpclient/session.rb
  2. +20 −1 test/test_httpclient.rb
View
@@ -874,17 +874,17 @@ def parse_header
timeout(@receive_timeout, ReceiveTimeoutError) do
initial_line = nil
begin
- initial_line = @socket.gets("\n")
- if 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
View
@@ -1540,6 +1540,16 @@ def test_charset
end
end
+ if RUBY_VERSION >= "1.9.3"
+ def test_continue
+ @client.debug_dev = str = ''
+ res = @client.get(serverurl + 'continue', :header => {:Expect => '100-continue'})
+ assert_equal(200, res.status)
+ assert_equal('done!', res.body)
+ assert_match(/Expect: 100-continue/, str)
+ end
+ end
+
private
def check_query_get(query)
@@ -1563,7 +1573,11 @@ def setup_server
:DocumentRoot => File.dirname(File.expand_path(__FILE__))
)
@serverport = @server.config[:Port]
- [:hello, :sleep, :servlet_redirect, :redirect1, :redirect2, :redirect3, :redirect_self, :relative_redirect, :chunked, :largebody, :status, :compressed, :charset].each do |sym|
+ [
+ :hello, :sleep, :servlet_redirect, :redirect1, :redirect2, :redirect3,
+ :redirect_self, :relative_redirect, :chunked, :largebody, :status,
+ :compressed, :charset, :continue
+ ].each do |sym|
@server.mount(
"/#{sym}",
WEBrick::HTTPServlet::ProcHandler.new(method("do_#{sym}").to_proc)
@@ -1654,6 +1668,11 @@ def do_status(req, res)
res.status = req.query['status'].to_i
end
+ def do_continue(req, res)
+ req.continue
+ res.body = 'done!'
+ end
+
class TestServlet < WEBrick::HTTPServlet::AbstractServlet
def get_instance(*arg)
self

0 comments on commit 80a7918

Please sign in to comment.