为什么机架响应主体是数组而不是字符串? [英] Why is rack response body an array not a string?

查看:28
本文介绍了为什么机架响应主体是数组而不是字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自他们文档的经典 hello world 示例,

a classic hello world example from their doc,

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

我的问题是为什么第三个值是 [Hello world!"],而不是Hello world"?来自他们的文档,

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

Body 必须响应每个并且只能产生 String 值.这Body 本身不应该是 String 的实例,因为这会中断红宝石 1.9.

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?

推荐答案

我认为 rack 起源于 python 的 wsgi.下面是python的解释:http://www.python.org/dev/peps/pep-3333/#缓冲和流式传输

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

这篇关于为什么机架响应主体是数组而不是字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆