ez.
ez.

Reputation: 7654

Why is rack response body an array not a string?

a classic hello world example from their doc,

class HelloWorld
  def call(env)
    return [200, {}, ["Hello world!"]]
  end
end

my question is why the third value is [Hello world!"], not "Hello world"? From their doc,

The Body must respond to each and must only yield String values. The Body itself should not be an instance of String, as this will break in Ruby 1.9.

Why body needs to respond to each? and in what case does it matter?

Upvotes: 24

Views: 4642

Answers (2)

Michael Kohl
Michael Kohl

Reputation: 66837

Judging from the sentence The Body itself should not be an instance of String, as this will break in Ruby 1.9., I'd assume that the last element of the response has to be an Enumerable. Since Strings stopped including this module in 1.9, you'll need some sort of collection that implements it.

BTW: hello world examples are often not great for figuring out why something is done in a certain way, they are too trivial.

Upvotes: 7

user570783
user570783

Reputation: 686

I think rack originated on python's wsgi. Here is the explanation for python: http://www.python.org/dev/peps/pep-3333/#buffering-and-streaming

Upvotes: 11

Related Questions