ruby-changes:17218
From: nahi <ko1@a...>
Date: Fri, 10 Sep 2010 19:20:42 +0900 (JST)
Subject: [ruby-changes:17218] Ruby:r29218 (trunk): * lib/webrick/httprequest.rb (WEBrick::HTTPRequest#continue): add
nahi 2010-09-10 19:20:35 +0900 (Fri, 10 Sep 2010) New Revision: 29218 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29218 Log: * 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. Modified files: trunk/ChangeLog trunk/NEWS trunk/lib/webrick/httprequest.rb trunk/test/webrick/test_httprequest.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 29217) +++ ChangeLog (revision 29218) @@ -1,3 +1,12 @@ +Fri Sep 10 19:11:13 2010 NAKAMURA, Hiroshi <nahi@r...> + + * 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@r...> * ext/openssl/lib/openssl/x509-internal.rb: removed unused local Index: lib/webrick/httprequest.rb =================================================================== --- lib/webrick/httprequest.rb (revision 29217) +++ lib/webrick/httprequest.rb (revision 29218) @@ -122,6 +122,15 @@ 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) Index: NEWS =================================================================== --- NEWS (revision 29217) +++ NEWS (revision 29218) @@ -46,6 +46,10 @@ * IO#winsize * IO.console +* webrick + * new method: + * WEBrick::HTTPRequest#continue for generating '100 continue' response. + === Compatibility issues (excluding feature bug fixes) * Kernel#respond_to? Index: test/webrick/test_httprequest.rb =================================================================== --- test/webrick/test_httprequest.rb (revision 29217) +++ test/webrick/test_httprequest.rb (revision 29218) @@ -305,6 +305,37 @@ 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_ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/