aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--NEWS4
-rw-r--r--lib/webrick/httprequest.rb9
-rw-r--r--test/webrick/test_httprequest.rb31
4 files changed, 53 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 400be6f252..19c33a02d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/NEWS b/NEWS
index 92b519234b..97ef5c596f 100644
--- a/NEWS
+++ b/NEWS
@@ -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?
diff --git a/lib/webrick/httprequest.rb b/lib/webrick/httprequest.rb
index 28be9fd790..75d26b529a 100644
--- a/lib/webrick/httprequest.rb
+++ b/lib/webrick/httprequest.rb
@@ -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)
diff --git a/test/webrick/test_httprequest.rb b/test/webrick/test_httprequest.rb
index 4a1db38bca..7869c21795 100644
--- a/test/webrick/test_httprequest.rb
+++ b/test/webrick/test_httprequest.rb
@@ -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_