ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: nobu@ruby-lang.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:69624] [Ruby trunk - Feature #11266] [PATCH] WEBrick: allow subclassing of Response and Request
Date: Wed, 17 Jun 2015 01:08:11 +0000	[thread overview]
Message-ID: <redmine.journal-52969.20150617010809.8adff978f7100d8a@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11266.20150616093526@ruby-lang.org

Issue #11266 has been updated by Nobuyoshi Nakada.


Any reason to create both together in `create_request_and_response`?

----------------------------------------
Feature #11266: [PATCH] WEBrick: allow subclassing of Response and Request
https://bugs.ruby-lang.org/issues/11266#change-52969

* Author: Julik Tarkhanov
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
To properly support the Rack specification features introduced in 2013, a number of features is needed in HTTPResponse.

* The Response should be able to handle it's socket to the given proc for writing (the socket control should be transferred to another routine). This is required for rack.hijack to work.
* The Response assumes an "IO pull" model via read()/readpartial() for grabbing data from the body. Rack assumes a "push" model for writing the response, so having the ability to take over the socket is better for Rack as well. We can make a Fiber-based adapter to let an iterable object present itself like an IO to WEBrick but having direct socket control is much easier.
* The Response should be able to take control of the chunking. This is currently done as a monkeypatch in Rack, but we much rather have it contained in the Response objects used by the Rack-supplied server handler.

Rack currently solves it by giving WEBrick the read end of an IO pipe, which has a side effect of buffering the entire response even when direct socket operation is needed. This creates a situation where no Rack-based streaming servers can function (no long-polling, no server-sent-events, no large streamed responses via HTTP/FTP adapters etc.)

Since all the three of those require patches to the HTTPResponse, a better approach would be to let the Server object create the right Response and let that response deal with the socket in a way it sees fit. This, however, is impossible at the moment because HTTPResponse and HTTPRequest are hardcoded in the main Server loop code, so if you want to override them with your implementations you have to override the entire service() method.

If we let the Server object instantiate the Response and Request in it's own separate method a Server subclass could use customized versions of those. Pretty much the only downside is one extra method call per HTTP request. Rack could then use it's own Server subclass with the right Response and Request objects in place.

I will be happy to provide a patch.


---Files--------------------------------
custom_req_response.patch (3.25 KB)


-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2015-06-17  0:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-11266.20150616093526@ruby-lang.org>
2015-06-16  9:35 ` [ruby-core:69604] [Ruby trunk - Feature #11266] [Open] WEBrick: allow subclassing of Response and Request me
2015-06-16 12:48 ` [ruby-core:69607] [Ruby trunk - Feature #11266] " me
2015-06-16 13:12 ` [ruby-core:69608] [Ruby trunk - Feature #11266] [PATCH] " me
2015-06-17  1:08 ` nobu [this message]
2015-06-17 18:42 ` [ruby-core:69635] " me
2015-06-19  9:39 ` [ruby-core:69679] " me
2015-07-10 19:14 ` [ruby-core:69944] " me
2015-07-11  0:07 ` [ruby-core:69945] [Ruby trunk - Feature #11266] [Assigned] " nobu
2015-08-05 10:43 ` [ruby-core:70249] [Ruby trunk - Feature #11266] " me
2016-06-23 17:47 ` [ruby-core:76121] [Ruby trunk Feature#11266] " me
2016-06-30  9:12 ` [ruby-core:76212] " naruse
2016-07-26 13:43 ` [ruby-core:76575] " rr.rosas
2018-11-20 16:09 ` [ruby-core:89910] " me
2018-12-19 18:31   ` [ruby-core:90621] " Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-52969.20150617010809.8adff978f7100d8a@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).