static int manage_raw_response(struct wsgi_request *wsgi_req) { int ret = 0; if (!wsgi_req->async_force_again) { ret = uwsgi_python_send_body(wsgi_req, (PyObject *) wsgi_req->async_result); if (ret == 0) { if (PyInt_Check((PyObject *) wsgi_req->async_result) || PyObject_HasAttrString((PyObject *) wsgi_req->async_result, "fileno")) { // is it a file ? int fd = PyObject_AsFileDescriptor((PyObject *) wsgi_req->async_result); if (fd >= 0) { wsgi_req->sendfile_fd = fd; uwsgi_response_sendfile_do(wsgi_req, fd, 0, 0); wsgi_req->sendfile_fd = -1; return UWSGI_OK; } } } } if (ret == 0) { if (!wsgi_req->async_placeholder) { wsgi_req->async_placeholder = PyObject_GetIter((PyObject *) wsgi_req->async_result); if (!wsgi_req->async_placeholder) return UWSGI_OK; } PyObject *pychunk = PyIter_Next((PyObject *) wsgi_req->async_placeholder); if (!pychunk) return UWSGI_OK; ret = uwsgi_python_send_body(wsgi_req, pychunk); if (ret == 0) { if (PyInt_Check(pychunk) || PyObject_HasAttrString(pychunk, "fileno")) { // is it a file ? int fd = PyObject_AsFileDescriptor(pychunk); if (fd >= 0) { wsgi_req->sendfile_fd = fd; uwsgi_response_sendfile_do(wsgi_req, fd, 0, 0); wsgi_req->sendfile_fd = -1; } } } Py_DECREF(pychunk); return UWSGI_AGAIN; } return UWSGI_OK; }
int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) { PyObject *pychunk; // return or yield ? // in strict mode we do not optimize apps directly returning strings (or bytes) if (!up.wsgi_strict) { if (uwsgi_python_send_body(wsgi_req, (PyObject *)wsgi_req->async_result)) goto clear; } if (wsgi_req->sendfile_obj == wsgi_req->async_result) { if (wsgi_req->sendfile_fd >= 0) { UWSGI_RELEASE_GIL uwsgi_response_sendfile_do(wsgi_req, wsgi_req->sendfile_fd, 0, 0); UWSGI_GET_GIL } // we do not have an iterable, check for read() method else if (PyObject_HasAttrString((PyObject *)wsgi_req->async_result, "read")) {