introducing raw mode

This commit is contained in:
Unbit
2013-09-30 13:43:13 +02:00
parent ba03837e29
commit 23b3d7483f
10 changed files with 73 additions and 7 deletions
+8 -1
View File
@@ -160,6 +160,8 @@ struct uwsgi_option uwsgi_python_options[] = {
{"python-version", no_argument, 0, "report python version", uwsgi_opt_pyver, NULL, UWSGI_OPT_IMMEDIATE},
{"python-raw", required_argument, 0, "load a python file for managing raw requests", uwsgi_opt_set_str, &up.raw, 0},
{0, 0, 0, 0, 0, 0, 0},
};
@@ -1074,7 +1076,6 @@ void uwsgi_python_init_apps() {
up.loaders[LOADER_CALLABLE] = uwsgi_callable_loader;
up.loaders[LOADER_STRING_CALLABLE] = uwsgi_string_callable_loader;
struct uwsgi_string_list *upli = up.import_list;
while(upli) {
if (strchr(upli->value, '/') || uwsgi_endswith(upli->value, ".py")) {
@@ -1125,6 +1126,12 @@ next:
uppa = uppa->next;
}
if (up.raw) {
up.raw_callable = uwsgi_file_loader(up.raw);
if (up.raw_callable) {
Py_INCREF(up.raw_callable);
}
}
if (up.wsgi_config != NULL) {
init_uwsgi_app(LOADER_UWSGI, up.wsgi_config, uwsgi.wsgi_req, up.main_thread, PYTHON_APP_TYPE_WSGI);
+24
View File
@@ -0,0 +1,24 @@
#include "uwsgi_python.h"
extern struct uwsgi_server uwsgi;
extern struct uwsgi_python up;
static int manage_raw_response(struct wsgi_request *wsgi_req) {
return 0;
}
int uwsgi_request_python_raw(struct wsgi_request *wsgi_req) {
if (!up.raw_callable) return UWSGI_OK;
UWSGI_GET_GIL
PyObject *args = PyTuple_New(1);
PyTuple_SetItem(args, 0, PyInt_FromLong(wsgi_req->fd));
wsgi_req->async_result = PyEval_CallObject(up.raw_callable, args);
if (wsgi_req->async_result) {
manage_raw_response(wsgi_req);
Py_DECREF((PyObject *) wsgi_req->async_result);
}
Py_DECREF(args);
UWSGI_RELEASE_GIL;
return UWSGI_OK;
}
+6 -1
View File
@@ -1,4 +1,4 @@
#include "../../uwsgi.h"
#include <uwsgi.h>
#include <Python.h>
#include <frameobject.h>
@@ -181,6 +181,9 @@ struct uwsgi_python {
char *programname;
int wsgi_strict;
char *raw;
PyObject *raw_callable;
};
@@ -277,6 +280,8 @@ struct uwsgi_buffer *uwsgi_python_exception_repr(struct wsgi_request *);
struct uwsgi_buffer *uwsgi_python_backtrace(struct wsgi_request *);
void uwsgi_python_exception_log(struct wsgi_request *);
int uwsgi_request_python_raw(struct wsgi_request *);
#define py_current_wsgi_req() current_wsgi_req();\
if (!wsgi_req) {\
return PyErr_Format(PyExc_SystemError, "you can call uwsgi api function only from the main callable");\
+1 -1
View File
@@ -11,7 +11,7 @@ def get_python_version():
return version
NAME='python'
GCC_LIST = ['python_plugin', 'pyutils', 'pyloader', 'wsgi_handlers', 'wsgi_headers', 'wsgi_subhandler', 'web3_subhandler', 'pump_subhandler', 'gil', 'uwsgi_pymodule', 'profiler', 'symimporter', 'tracebacker']
GCC_LIST = ['python_plugin', 'pyutils', 'pyloader', 'wsgi_handlers', 'wsgi_headers', 'wsgi_subhandler', 'web3_subhandler', 'pump_subhandler', 'gil', 'uwsgi_pymodule', 'profiler', 'symimporter', 'tracebacker', 'raw']
CFLAGS = ['-I' + sysconfig.get_python_inc(), '-I' + sysconfig.get_python_inc(plat_specific=True) ]
LDFLAGS = []
+2
View File
@@ -292,6 +292,8 @@ PyObject *py_eventfd_write(PyObject * self, PyObject * args) {
int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) {
if (wsgi_req->is_raw) return uwsgi_request_python_raw(wsgi_req);
struct uwsgi_app *wi;
if (wsgi_req->async_force_again) {