Why is rack response body an array not a string?

后端 未结 2 1469
野性不改
野性不改 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: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.

提交回复
热议问题