您能否提供一个真实的 WSGI start_response() 函数示例?
好吧,mod_wsgi 的 start_response() 函数是在 line 2678 of mod_wgsi.c 上定义的
没有人说“WSGI 是这样设计的……”
PEP3333 中似乎没有太多理由说明 WSGI 设计的这一方面。翻看web-sig mailing list archives,我遇到了this message...
前段时间我反对删除 start_response 的决定
来自下一个版本 WSGI 的函数,使用以下事实作为基本原理
没有 start_callable,异步扩展是不可能的
支持。
现在我发现删除 start_response 也会使
不可能支持协程(或者,至少,一些协程
用法)。
[...]
...它开始了一个关于这部分实现的基本原理的长线程,可能值得一读。
如果您真的想知道 WSGI 接口这方面的起源,您将不得不阅读 2003 年 12 月的 this initial draft 和 2004 年 8 月的 this later draft 之间的大量消息。
更新
这将如何与其他协议兼容?
我不太清楚你的意思。忽略所有的早期草案,WSGI 1.x 接口可以以两种不同的方式使用。
“已弃用”的方法是……
def application(environ, start_response):
write = start_response(status, headers)
write('content block 1')
write('content block 2')
write('content block 3')
return None
...而“推荐”的方法是...
def application(environ, start_response):
start_response(status, headers)
return ['content block 1',
'content block 2',
'content block 3']
大概,你可以同时使用...
def application(environ, start_response):
write = start_response(status, headers)
write('content block 1')
return ['content block 2',
'content block 3']
...但产生的行为可能是未定义的。
从this blog post 看来,正在考虑的新 WSGI 2.x 方法是...
def application(environ):
return (status,
headers,
['content block 1',
'content block 2',
'content block 3'])
...它消除了 start_response() 可调用对象,显然还有 write() 可调用对象,但没有迹象表明它何时(或什至)可能取代 WSGI 1.x。