From 4038d0137fd0e962748e5cde093d14ef75625a3b Mon Sep 17 00:00:00 2001 From: normal Date: Wed, 19 Dec 2018 11:08:05 +0000 Subject: webrick: add the ability to override res, req creation So that a customized HTTPServer subclass can use it's own Request/Response classes. To apply the override, make a subclass of WEBrick::HTTPServer and override the `create_request_and_response(with_webrick_config)` method. The method should return an Array of [request, response]. To check whether the Server supports this method (i.e. when using older versions of WEBrick when needing this functionality), you can ask the server if it responds to the method server.respond_to?(:create_request_and_response) This is backportable. [ruby-core:69604] [Feature #11266] From: Julik Tarkhanov git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/webrick/httpserver.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/webrick/httpserver.rb b/lib/webrick/httpserver.rb index 6945868ec8..e85d059319 100644 --- a/lib/webrick/httpserver.rb +++ b/lib/webrick/httpserver.rb @@ -68,8 +68,8 @@ module WEBrick def run(sock) while true - res = HTTPResponse.new(@config) - req = HTTPRequest.new(@config) + req = create_request(@config) + res = create_response(@config) server = self begin timeout = @config[:RequestTimeout] @@ -224,6 +224,20 @@ module WEBrick } end + ## + # Creates the HTTPRequest used when handling the HTTP + # request. Can be overridden by subclasses. + def create_request(with_webrick_config) + HTTPRequest.new(with_webrick_config) + end + + ## + # Creates the HTTPResponse used when handling the HTTP + # request. Can be overridden by subclasses. + def create_response(with_webrick_config) + HTTPResponse.new(with_webrick_config) + end + ## # Mount table for the path a servlet is mounted on in the directory space # of the server. Users of WEBrick can only access this indirectly via -- cgit v1.2.3