Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is rack response body an array not a string?

Tags:

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?

like image 923
ez. Avatar asked May 08 '12 03:05

ez.


1 Answers

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

like image 174
user570783 Avatar answered Sep 23 '22 22:09

user570783