Why is rack response body an array not a string?

后端 未结 2 1470
野性不改
野性不改 2021-02-12 14:11

a classic hello world example from their doc,

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

my question

相关标签:
2条回答
  • 2021-02-12 14:45

    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

    0 讨论(0)
  • 2021-02-12 14:56

    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.

    0 讨论(0)
提交回复
热议问题