how to enable web2py using HTTP/1.1 206 PARTIAL CONTENT

71 views
Skip to first unread message

ygao

unread,
Apr 25, 2008, 9:19:21 AM4/25/08
to web...@googlegroups.com
yes,current web2py don't support  this feature.
so I hack web2py using webob module,I think webob  is powerful.
I know there is differences between WebOb and CherryPy Server.
and what is webob,you can google it.
If you've ever waited forever for your files to download from a slow connection, or been cut off midway to download.
you know what is important to HTTP/1.1 206 PARTIAL CONTENT.
see some picture bellow.the hacked web2py support
HTTP/1.1 206 PARTIAL CONTENT.



--
※※※※※※※※※※※※※※※
http://BLOG.donews.com/ygao
UliPad:The powerful Python editor
hack_web2py.png

Massimo Di Pierro

unread,
Apr 25, 2008, 9:24:20 AM4/25/08
to web...@googlegroups.com
thank you I will take a look asap.

<hack_web2py.png>

Massimo Di Pierro

unread,
Apr 25, 2008, 10:27:32 AM4/25/08
to web...@googlegroups.com
webob is part of paste. We used the paste web server and we moved from it in favor of the cherrypy wsgi server. I think we can easily add support for partial content with a few lines in main.py. Let me try... I need to figure out how 206 responses can cohexist with we2py streaming.


On Apr 25, 2008, at 8:19 AM, ygao wrote:

<hack_web2py.png>

Massimo Di Pierro

unread,
Apr 25, 2008, 12:10:25 PM4/25/08
to web...@googlegroups.com
can you try this new main.py and see if it does what you ask?

main.py

ygao

unread,
Apr 26, 2008, 7:03:45 AM4/26/08
to web...@googlegroups.com
On Sat, Apr 26, 2008 at 12:10 AM, Massimo Di Pierro <mdip...@cs.depaul.edu> wrote:
can you try this new main.py and see if it does what you ask?

it does,great! I know a few about HTTP 206.
if the file size is xx gb,I think your have a problem.the problem is loading all content into memory.
I use hacked request to do something like this:you see this is very simple and powerful. you can use any webob Middleware.
so don't re-invent wheel.
                    if  request.range:
                        app = FileApp(static_file)
                        res = request.get_response(app)
                        raise HTTP(206,res.app_iter,**dict(res.headers))
                    else:
                        raise HTTP(200,streamer(open(static_file,'rb')),**headers)




On Apr 25, 2008, at 8:19 AM, ygao wrote:

Massimo Di Pierro

unread,
Apr 26, 2008, 10:04:06 AM4/26/08
to web...@googlegroups.com
sorry. Could not ope your email.

On Apr 26, 2008, at 6:03 AM, ygao wrote:

> --_000_a90eeef0804260403x3116a36axd4efd7edf7cb7337mailgmailcom_
> Content-Type: text/plain; charset="utf-8"
> Content-Transfer-Encoding: base64
>
> DQoNCk9uIFNhdCwgQXByIDI2LCAyMDA4IGF0IDEyOjEwIEFNLCBNYXNzaW1vIERpIFBpZX
> JybyA8
> bWRpcGllcnJvQGNzLmRlcGF1bC5lZHU8bWFpbHRvOm1kaXBpZXJyb0Bjcy5kZXBhdWwuZW
> R1Pj4g
> d3JvdGU6DQpjYW4geW91IHRyeSB0aGlzIG5ldyBtYWluLnB5IGFuZCBzZWUgaWYgaXQgZG
> 9lcyB3
> aGF0IHlvdSBhc2s/
> DQoNCml0IGRvZXMsZ3JlYXQhIEkga25vdyBhIGZldyBhYm91dCBIVFRQIDIw
> Ni4NCmlmIHRoZSBmaWxlIHNpemUgaXMgeHggZ2IsSSB0aGluayB5b3VyIGhhdmUgYSBwcm
> 9ibGVt
> LnRoZSBwcm9ibGVtIGlzIGxvYWRpbmcgYWxsIGNvbnRlbnQgaW50byBtZW1vcnkuDQpJIH
> VzZSBo
> YWNrZWQgcmVxdWVzdCB0byBkbyBzb21ldGhpbmcgbGlrZSB0aGlzOnlvdSBzZWUgdGhpcy
> BpcyB2
> ZXJ5IHNpbXBsZSBhbmQgcG93ZXJmdWwuIHlvdSBjYW4gdXNlIGFueSB3ZWJvYiBNaWRkbG
> V3YXJl
> Lg0Kc28gZG9uJ3QgcmUtaW52ZW50IHdoZWVsLg0KICAgICAgICAgICAgICAgICAgICBpZi
> AgcmVx
> dWVzdC5yYW5nZToNCiAgICAgICAgICAgICAgICAgICAgICAgIGFwcCA9IEZpbGVBcHAoc3
> RhdGlj
> X2ZpbGUpDQogICAgICAgICAgICAgICAgICAgICAgICByZXMgPSByZXF1ZXN0LmdldF9yZX
> Nwb25z
> ZShhcHApDQogICAgICAgICAgICAgICAgICAgICAgIC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mRvbm
> V3cy5j
> b20veWdhbw0KVWxpUGFkOlRoZSBwb3dlcmZ1bCBQeXRob24gZWRpdG9yDQpVbGlQYWQ6VG
> hlIHBv
> d2VyZnVsIFB5dGhvbiBlZGl0b3INCi0tfi0tfi0tLS0tLS0tLX4tLX4tLS0tfi0tLS0tLS
> 0tLS0t
> LX4tLS0tLS0tfi0tfi0tLS1
> +DQpZb3UgcmVjZWl2ZWQgdGhpcyBtZXNzYWdlIGJlY2F1c2UgeW91
> IGFyZSBzdWJzY3JpYmVkIHRvIHRoZSBHb29nbGUgR3JvdXBzICJ3ZWIycHkgV2ViIEZyYW
> 1ld29y
> ayIgZ3JvdXAuDQpUbyBwb3N0IHRvIHRoaXMgZ3JvdXAsIHNlbmQgZW1haWwgdG8gd2ViMn
> B5QGdv
> b2dsZWdyb3Vwcy5jb20NClRvIHVuc3Vic2NyaWJlIGZyb20gdGhpcyBncm91cCwgc2VuZC
> BlbWFp
> bCB0byB3ZWIycHktdW5zdWJzY3JpY

ygao

unread,
Apr 26, 2008, 10:16:58 AM4/26/08
to web...@googlegroups.com
you can find in http://groups.google.com

Massimo Di Pierro

unread,
Apr 26, 2008, 11:19:42 AM4/26/08
to web...@googlegroups.com
I am not sure I understand your suggestion. Currently web2py already
does streaming in both upload and download of large files. Streaming
works also for the 206 PARTIAL CONTENT. It is done by the code in
gluon/streamer.py

I am not sure I opened you email correctly. Could you explain me
again what you are proposing.

Could you also tell me how do you test 206?

Massimo

Massimo Di Pierro

unread,
Apr 26, 2008, 7:27:02 PM4/26/08
to web...@googlegroups.com
I posted another version in trunk 191.
As before it now streams all static content but also properly serves
partial files using 206 PARTIAL CONTENT.
This is transparent to the user. There is nothing you need to do.

You can also use this to serve static files not stored in
'static' (for example uploaded files) in your own controllers by calling

response.stream(filename,request=request)

form the request determines if IF_MODIFIED_SINCE is in the headers
and if file has not been modified returns 304
also from the request, if RANGE is in the headers, it streams only
the request portion of the file.
It also sets automatically the content_length, content-range, content-
type headers.

No need to say the old syntax

return response.stream(open(filename,'rb'))

works and it is still supported for backward compatibility.

Please check it before we make this official.

Massimo

ygao

unread,
Apr 27, 2008, 4:40:22 AM4/27/08
to web...@googlegroups.com
On Sun, Apr 27, 2008 at 7:27 AM, Massimo Di Pierro <mdip...@cs.depaul.edu> wrote:

I posted another version in trunk 191.
As before it now streams all static content but also properly serves
partial files using 206 PARTIAL CONTENT.
This is transparent to the user. There is nothing you need to do.
better!


You can also use this to serve static files not stored in
'static' (for example uploaded files) in your own controllers by calling

   response.stream(filename,request=request)

form the request determines if IF_MODIFIED_SINCE is in the headers
and if file has not been modified returns 304
also from the request, if RANGE is in the headers, it streams only
the request portion of the file.
It also sets automatically the content_length, content-range, content-
type headers.

No need to say the old syntax

    return response.stream(open(filename,'rb'))

works and it is still supported for backward compatibility.

Please check it before we make this official.

Massimo



On Apr 26, 2008, at 10:19 AM, Massimo Di Pierro wrote:

>
> I am not sure I understand your suggestion. Currently web2py already
> does streaming in both upload and download of large files. Streaming
> works also for the 206 PARTIAL CONTENT. It is done by the code in
> gluon/streamer.py
>
> I am not sure I opened you email correctly. Could you explain me
> again what you are proposing.
>
> Could you also tell me how do you test 206?
>
> Massimo
>
> >



ygao

unread,
Apr 27, 2008, 4:46:42 AM4/27/08
to web...@googlegroups.com
On Sat, Apr 26, 2008 at 11:19 PM, Massimo Di Pierro <mdip...@cs.depaul.edu> wrote:

I am not sure I understand your suggestion. Currently web2py already
does streaming in both upload and download of large files. Streaming
works also for the 206 PARTIAL CONTENT. It is done by the code in
gluon/streamer.py

I am not sure I opened you email correctly. Could you explain me
again what you are proposing.
I say web2py's request and respond have many same code  with webob.
why you re-invent the wheel?.

Could you also tell me how do you test 206?
I use download manager software *flashget*.

Massimo


Reply all
Reply to author
Forward
0 new messages