Project

General

Profile

Actions

Feature #5778

closed

Allow WEBrick::HTTPResponse to send IO-duck-typed bodies

Added by regularfry (Alex Young) about 11 years ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:41725]

Description

WEBrick::HTTPResponse currently type-checks for IO to determine how to transfer content to the outgoing socket. Because of this, it's not possible to use "IO-like" objects as data sources unless they specifically inherit from IO.

The interface HTTPResponse requires from its body objects is very simple: it only calls #read and #close, and optionally #bytesize. This means that the type-check is needlessly strict, and prevents custom objects from being used as data sources. The attached patch removes the type-check on IO, allowing duck-typed objects to be used.

The downside to this patch is that you can't pass in objects that duck-type to String's interface. It wouldn't be hard to remove that restriction if necessary, but I figured this was the less intrusive approach.


Files

httpresponse.patch (2.76 KB) httpresponse.patch regularfry (Alex Young), 12/20/2011 02:02 AM

Updated by mame (Yusuke Endoh) almost 11 years ago

  • Status changed from Open to Assigned
  • Assignee set to mame (Yusuke Endoh)

It is trivial, and the patch looks good to me.
I'll commit it unless there is objection.

--
Yusuke Endoh

Updated by nahi (Hiroshi Nakamura) almost 11 years ago

Yusuke, you may want to assign it to me (maintainer)
I think it's good to improve, but not yet checked the patch...

Updated by mame (Yusuke Endoh) almost 11 years ago

  • Assignee changed from mame (Yusuke Endoh) to nahi (Hiroshi Nakamura)

You have control.

--
Yusuke Endoh

Actions #4

Updated by mame (Yusuke Endoh) about 10 years ago

  • Target version set to 2.6

Blame NaHi!

--
Yusuke Endoh

Actions #5

Updated by naruse (Yui NARUSE) about 5 years ago

  • Target version deleted (2.6)

Updated by mame (Yusuke Endoh) over 4 years ago

  • Assignee changed from nahi (Hiroshi Nakamura) to normalperson (Eric Wong)

@normalperson (Eric Wong), could you handle this ticket?

Updated by hsbt (Hiroshi SHIBATA) about 1 year ago

  • Status changed from Assigned to Closed

webrick is removed from ruby repo since Ruby 3.0.

The canonical repo is here: https://github.com/ruby/webrick/

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0