Commit 66719e14 authored by iv's avatar iv

Send response to GET method data chunk by chunk.

Flask doc: http://flask.pocoo.org/docs/0.10/patterns/streaming/
parent c4c453bd
from itsdangerous import Signer, base64_encode, base64_decode
from flask import Flask, request, render_template, make_response, g
from flask import Flask, request, render_template, make_response, g, Response
from flask.views import MethodView
import urlparse
......@@ -10,6 +10,8 @@ import os
app = Flask(__name__.split('.')[0])
app.config.from_object(__name__)
BUFFER_SIZE = 128000
ALLOWED_METHODS = ['GET', 'PUT', 'PROPFIND', 'PROPPATCH', 'MKCOL', 'DELETE',
'COPY', 'MOVE', 'OPTIONS']
......@@ -175,10 +177,16 @@ class WebDAV(MethodView):
elif os.path.isfile(localpath):
try:
data_resource = app.fs_handler.get_data(request.path)
# TODO send large response by chunks would be nice for big
# files... http://flask.pocoo.org/docs/0.10/patterns/streaming/
data = data_resource.read()
except Exception:
def generate():
data = data_resource.read(BUFFER_SIZE)
while data:
debug('get a chunk: ' + data)
yield data
data = data_resource.read(BUFFER_SIZE)
return Response(response=generate(), status=response.status,
headers=response.headers)
except Exception, e:
debug(e)
response.status = '500'
else:
response.status = '404'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment