[前][次][番号順一覧][スレッド一覧]

ruby-changes:42272

From: hsbt <ko1@a...>
Date: Tue, 29 Mar 2016 12:45:40 +0900 (JST)
Subject: [ruby-changes:42272] hsbt:r54346 (trunk): * lib/webrick/httpresponse.rb: Move error_body to method. It allow to

hsbt	2016-03-29 12:45:32 +0900 (Tue, 29 Mar 2016)

  New Revision: 54346

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54346

  Log:
    * lib/webrick/httpresponse.rb: Move error_body to method. It allow to
      override the body more easily. [fix GH-1307]
    * test/webrick/test_httpresponse.rb: ditto.

  Modified files:
    trunk/ChangeLog
    trunk/lib/webrick/httpresponse.rb
    trunk/test/webrick/test_httpresponse.rb
Index: test/webrick/test_httpresponse.rb
===================================================================
--- test/webrick/test_httpresponse.rb	(revision 54345)
+++ test/webrick/test_httpresponse.rb	(revision 54346)
@@ -146,5 +146,15 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/test/webrick/test_httpresponse.rb#L146
       }
       assert_equal 0, logger.messages.length
     end
+
+    def test_set_error
+      status = 400
+      message = 'missing attribute'
+      @res.status = status
+      error = WEBrick::HTTPStatus[status].new(message)
+      body = @res.set_error(error)
+      assert_match(/#{@res.reason_phrase}/, body)
+      assert_match(/#{message}/, body)
+    end
   end
 end
Index: lib/webrick/httpresponse.rb
===================================================================
--- lib/webrick/httpresponse.rb	(revision 54345)
+++ lib/webrick/httpresponse.rb	(revision 54346)
@@ -352,6 +352,14 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpresponse.rb#L352
         host, port = @config[:ServerName], @config[:Port]
       end
 
+      error_body(backtrace, ex, host, port)
+    end
+
+    private
+
+    # :stopdoc:
+
+    def error_body(backtrace, ex, host, port)
       @body = ''
       @body << <<-_end_of_html_
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
@@ -381,10 +389,6 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpresponse.rb#L389
       _end_of_html_
     end
 
-    private
-
-    # :stopdoc:
-
     def send_body_io(socket)
       begin
         if @request_method == "HEAD"
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54345)
+++ ChangeLog	(revision 54346)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Mar 29 12:45:18 2016  Laurent Arnoud  <laurent@s...>
+
+	* lib/webrick/httpresponse.rb: Move error_body to method. It allow to
+	  override the body more easily. [fix GH-1307]
+	* test/webrick/test_httpresponse.rb: ditto.
+
 Tue Mar 29 06:40:53 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* error.c (rb_compile_err_append): rb_thread_t::base_block is no

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]