你能提供一个 WSGI 的真实例子吗start_response()
功能?
嗯,start_response()
函数为mod_wsgi http://en.wikipedia.org/wiki/Mod_wsgi定义于第 2678 行mod_wgsi.c http://code.google.com/p/modwsgi/source/browse/mod_wsgi/mod_wsgi.c#2678
他们没有人说“WSGI 如此设计是为了……”
WSGI 在这方面的设计似乎没有太多理由PEP3333 http://www.python.org/dev/peps/pep-3333/。纵观整个web-sig 邮件列表档案 http://mail.python.org/pipermail/web-sig/, 我碰到这条信息 http://mail.python.org/pipermail/web-sig/2010-April/004366.html...
前段时间我反对删除 start_response 的决定
下一个版本 WSGI 中的函数,使用以下事实作为基本原理:
没有start_callable,异步扩展是不可能的
支持。
现在我发现删除 start_response 也会使
不可能支持协程(或者至少某些协程
用法)。
[...]
...它启动了一个关于这部分实现的基本原理的长线程,可能值得一读。
如果您确实想了解 WSGI 接口这方面的起源,则必须阅读 WSGI 接口之间的大量消息这个初稿 http://mail.python.org/pipermail/web-sig/2003-December/000394.html2003 年 12 月,以及这个后来的草案 http://mail.python.org/pipermail/web-sig/2004-August/000518.html2004年8月。
Update
它如何与其他协议兼容?
我不太确定你的意思。忽略所有早期草案,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']
...但结果的行为可能是未定义的。
从外观上看这篇博文 http://dirtsimple.org/2007/02/wsgi-middleware-considered-harmful.html,正在考虑的新 WSGI 2.x 方法是......
def application(environ):
return (status,
headers,
['content block 1',
'content block 2',
'content block 3'])
...这消除了start_response()
可调用,而且,显然,write()
可调用,但没有任何迹象表明它何时(甚至是否)可能取代 WSGI 1.x。