我们正在尝试让 Flask Web 服务正常工作,但我们在流式帖子方面遇到了一些问题 - 即当标头包含 Transfer-Encoding: chunked 时。
默认 Flask 似乎不支持 HTTP 1.1。有解决办法吗?
我们正在运行这个命令:
$ curl -v -X PUT --header "Transfer-Encoding: chunked" -d @pylucene-3.6.1-2-src.tar.gz "http://localhost:5000/async-test"
针对此代码:
@app.route("/async-test", methods=['PUT'])
def result():
print '------->'+str(request.headers)+'<------------'
print '------->'+str(request.data)+'<------------'
print '------->'+str(request.form)+'<------------'
return 'OK'
这是卷曲输出:
$ curl -v -X PUT --header "Transfer-Encoding: chunked" -d @pylucene-3.6.1-2-src.tar.gz "http://localhost:5000/async-test"
* About to connect() to localhost port 5000 (#0)
* Trying ::1... Connection refused
* Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 5000 (#0)
> PUT /async-test HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:5000
> Accept: */*
> Transfer-Encoding: chunked
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: text/html; charset=utf-8
< Content-Length: 2
< Server: Werkzeug/0.8.3 Python/2.7.1
< Date: Wed, 02 Jan 2013 21:43:24 GMT
<
这是 Flask 服务器的输出:
* Running on 0.0.0.0:5000/
------->Transfer-Encoding: chunked
Content-Length:
User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
Host: localhost:5000
Expect: 100-continue
Accept: */*
Content-Type: application/x-www-form-urlencoded
<------------
-------><------------
------->ImmutableMultiDict([])<------------
它不是 Flask Python,而是 mod_wsgi。只有 mod_wsgi 版本 3.0+ 开始支持分块 http 传输。 Flask Python 内部使用 Werkzeug 工具包作为 mod_wsgi 的接口。如果您从 apt 源安装它,它可能是旧版本。
尝试编译最新版本的mod_wsgi,然后安装Flask框架,可能会解决问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)