diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index f49a0f0c..fb7b5eab 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -830,7 +830,6 @@ PyObject *py_uwsgi_advanced_sendfile(PyObject * self, PyObject * args) { size_t chunk; off_t pos = 0; size_t filesize = 0; - struct stat stat_buf; struct wsgi_request *wsgi_req = current_wsgi_req(); int fd = -1; @@ -861,31 +860,30 @@ PyObject *py_uwsgi_advanced_sendfile(PyObject * self, PyObject * args) { } } - if (!filesize) { - if (fstat(fd, &stat_buf)) { - uwsgi_error("fstat()"); - goto clear2; - } - else { - filesize = stat_buf.st_size; - } + int tmp_fd = wsgi_req->sendfile_fd; + size_t tmp_filesize = wsgi_req->sendfile_fd_size; + size_t tmp_chunk = wsgi_req->sendfile_fd_chunk; + off_t tmp_pos = wsgi_req->sendfile_fd_pos; - } + wsgi_req->sendfile_fd = fd; + wsgi_req->sendfile_fd_size = filesize; + wsgi_req->sendfile_fd_chunk = chunk; + wsgi_req->sendfile_fd_pos = pos; - if (!filesize) - goto clear2; + // do sendfile + wsgi_req->response_size += uwsgi_sendfile(wsgi_req); - if (!chunk) - chunk = 4096; - - uwsgi.wsgi_req->response_size += uwsgi_do_sendfile(wsgi_req->poll.fd, fd, filesize, chunk, &pos, 0); + // revert to old values + wsgi_req->sendfile_fd = tmp_fd; + wsgi_req->sendfile_fd_size = tmp_filesize; + wsgi_req->sendfile_fd_chunk = tmp_chunk; + wsgi_req->sendfile_fd_pos = tmp_pos; + close(fd); Py_INCREF(Py_True); return Py_True; - clear2: - close(fd); clear: Py_INCREF(Py_None); return Py_None; diff --git a/proto/zeromq.c b/proto/zeromq.c index b6f09448..f722bdac 100644 --- a/proto/zeromq.c +++ b/proto/zeromq.c @@ -454,7 +454,6 @@ ssize_t uwsgi_proto_zeromq_sendfile(struct wsgi_request * wsgi_req) { wsgi_req->sendfile_fd_chunk = 65536; - if (uwsgi.async > 1) { len = read(wsgi_req->sendfile_fd, buf, UMIN(remains, wsgi_req->sendfile_fd_chunk)); if (len != (int) UMIN(remains, wsgi_req->sendfile_fd_chunk)) { diff --git a/welcome.py b/welcome.py index 73e5af1b..b3f298c7 100644 --- a/welcome.py +++ b/welcome.py @@ -1,5 +1,9 @@ import uwsgi +import os +def xsendfile(e, sr): + sr('200 OK', [('Content-Type', 'image/png'), ('X-Sendfile', os.path.abspath('logo_uWSGI.png'))]) + return '' def serve_logo(e, sr): sr('200 OK', [('Content-Type', 'image/png')]) @@ -16,6 +20,7 @@ def serve_config(e, sr): yield "%s = %s
" % (opt, uwsgi.opt[opt]) routes = {} +routes['/xsendfile'] = xsendfile routes['/logo'] = serve_logo routes['/config'] = serve_config routes['/options'] = serve_options