1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/webrick/httprequest.rb (WEBrick::HTTPRequest#continue): add

method for generating HTTP/1.1 100 continue response if the client
          expects it, otherwise does nothing.  Patch by Brian Candler.
          ref #855.

        * test/webrick/test_httprequest.rb: test added.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nahi 2010-09-10 10:20:35 +00:00
parent 7f438d8402
commit a4fa58f9ab
4 changed files with 53 additions and 0 deletions

View file

@ -1,3 +1,12 @@
Fri Sep 10 19:11:13 2010 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* lib/webrick/httprequest.rb (WEBrick::HTTPRequest#continue): add
method for generating HTTP/1.1 100 continue response if the client
expects it, otherwise does nothing. Patch by Brian Candler.
ref #855.
* test/webrick/test_httprequest.rb: test added.
Fri Sep 10 17:49:34 2010 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* ext/openssl/lib/openssl/x509-internal.rb: removed unused local

4
NEWS
View file

@ -46,6 +46,10 @@ with all sufficient information, see the ChangeLog file.
* IO#winsize
* IO.console
* webrick
* new method:
* WEBrick::HTTPRequest#continue for generating '100 continue' response.
=== Compatibility issues (excluding feature bug fixes)
* Kernel#respond_to?

View file

@ -122,6 +122,15 @@ module WEBrick
end
end
# Generate HTTP/1.1 100 continue response if the client expects it,
# otherwise does nothing.
def continue
if self['expect'] == '100-continue' && @config[:HTTPVersion] >= "1.1"
@socket << "HTTP/#{@config[:HTTPVersion]} 100 continue#{CRLF}#{CRLF}"
@header.delete('expect')
end
end
def body(&block)
block ||= Proc.new{|chunk| @body << chunk }
read_body(@socket, block)

View file

@ -305,6 +305,37 @@ class TestWEBrickHTTPRequest < Test::Unit::TestCase
assert(req.ssl?)
end
def test_continue_sent
msg = <<-_end_of_message_
POST /path HTTP/1.1
Expect: 100-continue
_end_of_message_
msg.gsub!(/^ {6}/, "")
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req.parse(StringIO.new(msg))
assert req['expect']
l = msg.size
req.continue
assert_not_equal l, msg.size
assert_match /HTTP\/1.1 100 continue\r\n\r\n\z/, msg
assert !req['expect']
end
def test_continue_not_sent
msg = <<-_end_of_message_
POST /path HTTP/1.1
_end_of_message_
msg.gsub!(/^ {6}/, "")
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req.parse(StringIO.new(msg))
assert !req['expect']
l = msg.size
req.continue
assert_equal l, msg.size
end
def test_bad_messages
param = "foo=1;foo=2;foo=3;bar=x"
msg = <<-_end_of_message_