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 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 from flask.views import MethodView
import urlparse import urlparse
...@@ -10,6 +10,8 @@ import os ...@@ -10,6 +10,8 @@ import os
app = Flask(__name__.split('.')[0]) app = Flask(__name__.split('.')[0])
app.config.from_object(__name__) app.config.from_object(__name__)
BUFFER_SIZE = 128000
ALLOWED_METHODS = ['GET', 'PUT', 'PROPFIND', 'PROPPATCH', 'MKCOL', 'DELETE', ALLOWED_METHODS = ['GET', 'PUT', 'PROPFIND', 'PROPPATCH', 'MKCOL', 'DELETE',
'COPY', 'MOVE', 'OPTIONS'] 'COPY', 'MOVE', 'OPTIONS']
...@@ -175,10 +177,16 @@ class WebDAV(MethodView): ...@@ -175,10 +177,16 @@ class WebDAV(MethodView):
elif os.path.isfile(localpath): elif os.path.isfile(localpath):
try: try:
data_resource = app.fs_handler.get_data(request.path) data_resource = app.fs_handler.get_data(request.path)
# TODO send large response by chunks would be nice for big def generate():
# files... http://flask.pocoo.org/docs/0.10/patterns/streaming/ data = data_resource.read(BUFFER_SIZE)
data = data_resource.read() while data:
except Exception: 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' response.status = '500'
else: else:
response.status = '404' 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