HTTP_RANGE

gert gert.cuykens at gmail.com
Fri Aug 7 11:23:52 EDT 2009


def application(environ, response):
    range=environ.get('HTTP_RANGE','bytes=0-').replace
('bytes=','').split(',')
    offset=[]
    for r in range: offset.append(r.split('-'))
    out='0123456789'
    lengthF=len(out)
    lengthC=str(lengthF-int(offset[0][0]))
    bitS=int(offset[0][0])
    bitE=lengthF-1
    bytes='bytes '+str(bitS)+'-'+str(bitE)+'/'+str(lengthF)
    response('200 OK', [('Content-Length', lengthC), ('Content-
Range',bytes)])
    return [out[bitS:]]

C:\Users\gert\Desktop>curl http://127.0.0.1/appwsgi/wsgi/download.wsgi
-v
* About to connect() to 127.0.0.1 port 80 (#0)
*   Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> GET /appwsgi/wsgi/download.wsgi HTTP/1.1
> User-Agent: curl/7.19.4 (amd64-pc-win32) libcurl/7.19.4 OpenSSL/0.9.8j zlib/1.2.3
> Host: 127.0.0.1
> Accept: */*

* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Date: Thu, 06 Aug 2009 19:05:09 GMT
< Server: WSGIServer/0.1 Python/3.1
< Content-Length: 10
< Content-Range: bytes 0-9/10
<
0123456789* Closing connection #0

C:\Users\gert\Desktop>curl -C 2 http://127.0.0.1/appwsgi/wsgi/download.wsgi
-v
* About to connect() to 127.0.0.1 port 80 (#0)
*   Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> GET /appwsgi/wsgi/download.wsgi HTTP/1.1
> Range: bytes=2-
> User-Agent: curl/7.19.4 (amd64-pc-win32) libcurl/7.19.4 OpenSSL/0.9.8j zlib/1.2.3
> Host: 127.0.0.1
> Accept: */*

* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Date: Thu, 06 Aug 2009 19:06:52 GMT
< Server: WSGIServer/0.1 Python/3.1
< Content-Length: 8
< Content-Range: bytes 2-9/10
<
23456789* Closing connection #0

Why does it use HTTP 1.0 ? Can I force it to use HTTP 1.1 ?



More information about the Python-list mailing list