librelist archives

« back to archive

Transfer-Encoding: chunked

Transfer-Encoding: chunked

From:
James Percent
Date:
2013-01-02 @ 22:21
Hey Flaskers,

We're trying get something working and having some issues.  I think it's
related to chunked transfer.  Unless I missed it, I can't find any examples
on the site.  Is it not supported or is there something that has to be set
in the response?

We are running this command:
    $ curl -v -X PUT  --header "Transfer-Encoding: chunked" -d
@pylucene-3.6.1-2-src.tar.gz "http://localhost:5000/async-test"

Against this code:

@app.route("/async-test", methods=['PUT'])
def result():
    print '------->'+str(request.headers)+'<------------'
    print '------->'+str(request.data)+'<------------'
    print '------->'+str(request.form)+'<------------'
    return 'OK'

Here's the curl output:

$ 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
<

And here's the Flask server output:

 * Running on http://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([])<------------

Any help is greatly appreciated.

Best,
James

Re: [flask] Transfer-Encoding: chunked

From:
Steven Kryskalla
Date:
2013-01-04 @ 01:43
On Wed, Jan 2, 2013 at 2:21 PM, James Percent <james@syndeticlogic.org> wrote:
> We're trying get something working and having some issues.  I think it's
> related to chunked transfer.  Unless I missed it, I can't find any examples
> on the site.  Is it not supported or is there something that has to be set
> in the response?

There is an issue on the flask bug tracker here:

https://github.com/mitsuhiko/flask/issues/367

It's not fully supported by the WSGI protocol, so werkzeug does not
implement it. But some WSGI servers do implement it, so if you really
need chunked transfers you could use one of those servers and handle
it outside of flask (e.g. at the WSGI middleware layer, one level
above flask).

-Steve