~ubuntu-branches/ubuntu/trusty/uwsgi/trusty

« back to all changes in this revision

Viewing changes to plugins/python/wsgi_subhandler.c

  • Committer: Package Import Robot
  • Author(s): Janos Guljas
  • Date: 2012-02-13 03:43:28 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120213034328-d02hz8m5pon6kaxf
Tags: 1.0.3+dfsg-1
* New upstream version.
* Adjust rack plugin LD_RUN_PATH patch.
* Adjust patch for uWSGI Control Center jQuery links in templates.
* Remove '-fno-strict-aliasing' CFLAG patch as it is implemented upstream.
* Remove fix indentation of uwsgidecorators_py patch as implemented upstream.
* Adjust init scripts to use top-bottom options order, as --inherit option
  is not working as in earlier versions. 
* Update debian/copyright file.
* Add LSB Description field to debian/uwsgi.init.d.
* Set Architecture to "all" for binary package uwsgi-extra because
  it contains no architecture dependent files.
* Change uwsgi description. (Closes: #640698)
* New binary packages:
  - uwsgi-plugin-carbon
  - uwsgi-plugin-graylog2
  - uwsgi-plugin-logsocket
  - uwsgi-plugin-probeconnect
  - uwsgi-plugin-probepg
  - uwsgi-plugin-rrdtool
  - uwsgi-plugin-rsyslog
  - uwsgi-plugin-signal
  - uwsgi-plugin-symcall
  - uwsgi-plugin-syslog
* python-uwsgidecorators:
  - fix binary-install rule to call dh_python2
  - remove debian/source.lintian-overrides
* uwsgi-plugin-jvm-openjdk-6:
  - fix FTBFS on armel and powerpc (Closes: #656280)
* uwsgi-plugin-python:
  - document issue "ImportError: No module named site" when using
    virtualenv with Python 2.6 in README.Debian (Closes: #654333)
* Adjust debian/watch uversionmangle option.
* Repack upstram source to remove minimized jQuery and jQuery UI JavaScript
  libraries:
  - add get-orig-source rule to debian/rules
  - append +dfsg to upstream version
  - update debian/watch with dversionmangle option

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
extern struct uwsgi_server uwsgi;
4
4
extern struct uwsgi_python up;
 
5
extern PyTypeObject uwsgi_InputType;
5
6
 
6
7
void *uwsgi_request_subhandler_wsgi(struct wsgi_request *wsgi_req, struct uwsgi_app *wi) {
7
8
 
8
9
        PyObject *zero;
9
 
 
10
 
        //static PyObject *uwsgi_version = NULL;
11
 
 
12
 
        /*
13
 
           if (uwsgi_version == NULL) {
14
 
           uwsgi_version = PyString_FromString(UWSGI_VERSION);
15
 
           }
16
 
           */
17
 
 
 
10
        int i;
 
11
        PyObject *pydictkey, *pydictvalue;
 
12
        char *path_info;
 
13
 
 
14
        for (i = 0; i < wsgi_req->var_cnt; i += 2) {
 
15
#ifdef UWSGI_DEBUG
 
16
                uwsgi_debug("%.*s: %.*s\n", wsgi_req->hvec[i].iov_len, wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i+1].iov_len, wsgi_req->hvec[i+1].iov_base);
 
17
#endif
 
18
#ifdef PYTHREE
 
19
                pydictkey = PyUnicode_DecodeLatin1(wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i].iov_len, NULL);
 
20
                pydictvalue = PyUnicode_DecodeLatin1(wsgi_req->hvec[i + 1].iov_base, wsgi_req->hvec[i + 1].iov_len, NULL);
 
21
#else
 
22
                pydictkey = PyString_FromStringAndSize(wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i].iov_len);
 
23
                pydictvalue = PyString_FromStringAndSize(wsgi_req->hvec[i + 1].iov_base, wsgi_req->hvec[i + 1].iov_len);
 
24
#endif
 
25
 
 
26
#ifdef UWSGI_DEBUG
 
27
                uwsgi_log("%p %d %p %d\n", pydictkey, wsgi_req->hvec[i].iov_len, pydictvalue, wsgi_req->hvec[i + 1].iov_len);
 
28
#endif
 
29
                PyDict_SetItem(wsgi_req->async_environ, pydictkey, pydictvalue);
 
30
                Py_DECREF(pydictkey);
 
31
                Py_DECREF(pydictvalue);
 
32
        }
 
33
 
 
34
        if (wsgi_req->uh.modifier1 == UWSGI_MODIFIER_MANAGE_PATH_INFO) {
 
35
                wsgi_req->uh.modifier1 = 0;
 
36
                pydictkey = PyDict_GetItemString(wsgi_req->async_environ, "SCRIPT_NAME");
 
37
                if (pydictkey) {
 
38
                        if (PyString_Check(pydictkey)) {
 
39
                                pydictvalue = PyDict_GetItemString(wsgi_req->async_environ, "PATH_INFO");
 
40
                                if (pydictvalue) {
 
41
                                        if (PyString_Check(pydictvalue)) {
 
42
                                                path_info = PyString_AsString(pydictvalue);
 
43
                                                PyDict_SetItemString(wsgi_req->async_environ, "PATH_INFO", PyString_FromString(path_info + PyString_Size(pydictkey)));
 
44
                                        }
 
45
                                }
 
46
                        }
 
47
                }
 
48
        }
 
49
 
 
50
 
 
51
#ifndef UWSGI_PYPY
 
52
        // if async_post is mapped as a file, directly use it as wsgi.input
 
53
        if (wsgi_req->async_post) {
 
54
#ifdef PYTHREE
 
55
                wsgi_req->async_input = PyFile_FromFd(fileno(wsgi_req->async_post), "wsgi_input", "rb", 0, NULL, NULL, NULL, 0);
 
56
#else
 
57
                wsgi_req->async_input = PyFile_FromFile(wsgi_req->async_post, "wsgi_input", "r", NULL);
 
58
#endif
 
59
        }
 
60
        else {
 
61
                // create wsgi.input custom object
 
62
                wsgi_req->async_input = (PyObject *) PyObject_New(uwsgi_Input, &uwsgi_InputType);
 
63
                ((uwsgi_Input*)wsgi_req->async_input)->wsgi_req = wsgi_req;
 
64
                ((uwsgi_Input*)wsgi_req->async_input)->pos = 0;
 
65
                ((uwsgi_Input*)wsgi_req->async_input)->readline_pos = 0;
 
66
                ((uwsgi_Input*)wsgi_req->async_input)->readline_max_size = 0;
 
67
 
 
68
        }
 
69
 
 
70
 
 
71
        PyDict_SetItemString(wsgi_req->async_environ, "wsgi.input", wsgi_req->async_input);
 
72
#endif
18
73
 
19
74
#ifdef UWSGI_SENDFILE
20
75
        PyDict_SetItemString(wsgi_req->async_environ, "wsgi.file_wrapper", wi->sendfile);
28
83
        }
29
84
#endif
30
85
 
31
 
        // cache this
32
 
        zero = PyTuple_New(2);
33
 
        PyTuple_SetItem(zero, 0, PyInt_FromLong(1));
34
 
        PyTuple_SetItem(zero, 1, PyInt_FromLong(0));
35
 
        PyDict_SetItemString(wsgi_req->async_environ, "wsgi.version", zero);
36
 
        Py_DECREF(zero);
 
86
        PyDict_SetItemString(wsgi_req->async_environ, "wsgi.version", wi->gateway_version);
37
87
 
38
 
        zero = PyFile_FromFile(stderr, "wsgi_input", "w", NULL);
 
88
#ifndef UWSGI_PYPY
 
89
        zero = PyFile_FromFile(stderr, "wsgi_errors", "w", NULL);
39
90
        PyDict_SetItemString(wsgi_req->async_environ, "wsgi.errors", zero);
40
91
        Py_DECREF(zero);
 
92
#endif
41
93
 
42
94
        PyDict_SetItemString(wsgi_req->async_environ, "wsgi.run_once", Py_False);
43
95
 
 
96
 
 
97
 
44
98
        if (uwsgi.threads > 1) {
45
99
                PyDict_SetItemString(wsgi_req->async_environ, "wsgi.multithread", Py_True);
46
100
        }
55
109
        }
56
110
 
57
111
        if (wsgi_req->scheme_len > 0) {
58
 
                zero = PyString_FromStringAndSize(wsgi_req->scheme, wsgi_req->scheme_len);
 
112
                zero = UWSGI_PYFROMSTRINGSIZE(wsgi_req->scheme, wsgi_req->scheme_len);
59
113
        }
60
114
        else if (wsgi_req->https_len > 0) {
61
115
                if (!strncasecmp(wsgi_req->https, "on", 2) || wsgi_req->https[0] == '1') {
62
 
                        zero = PyString_FromString("https");
 
116
                        zero = UWSGI_PYFROMSTRING("https");
63
117
                }
64
118
                else {
65
 
                        zero = PyString_FromString("http");
 
119
                        zero = UWSGI_PYFROMSTRING("http");
66
120
                }
67
121
        }
68
122
        else {
69
 
                zero = PyString_FromString("http");
 
123
                zero = UWSGI_PYFROMSTRING("http");
70
124
        }
71
125
        PyDict_SetItemString(wsgi_req->async_environ, "wsgi.url_scheme", zero);
72
126
        Py_DECREF(zero);
74
128
 
75
129
        wsgi_req->async_app = wi->callable;
76
130
 
 
131
 
77
132
        // export .env only in non-threaded mode
 
133
#ifndef UWSGI_PYPY
78
134
        if (uwsgi.threads < 2) {
79
135
                PyDict_SetItemString(up.embedded_dict, "env", wsgi_req->async_environ);
80
136
        }
 
137
#endif
81
138
 
82
 
        zero = PyString_FromString(UWSGI_VERSION);
83
 
        PyDict_SetItemString(wsgi_req->async_environ, "uwsgi.version", zero);
84
 
        Py_DECREF(zero);
 
139
        PyDict_SetItemString(wsgi_req->async_environ, "uwsgi.version", wi->uwsgi_version);
85
140
 
86
141
        if (uwsgi.cores > 1) {
87
 
                PyDict_SetItemString(wsgi_req->async_environ, "uwsgi.core", PyInt_FromLong(wsgi_req->async_id));
 
142
                zero = PyInt_FromLong(wsgi_req->async_id);
 
143
                PyDict_SetItemString(wsgi_req->async_environ, "uwsgi.core", zero);
 
144
                Py_DECREF(zero);
88
145
        }
89
146
 
 
147
        // cache this ?
90
148
        if (uwsgi.cluster_fd >= 0) {
91
149
                zero = PyString_FromString(uwsgi.cluster);
92
150
                PyDict_SetItemString(wsgi_req->async_environ, "uwsgi.cluster", zero);
96
154
                Py_DECREF(zero);
97
155
        }
98
156
 
99
 
        zero = PyString_FromString(uwsgi.hostname);
100
 
        PyDict_SetItemString(wsgi_req->async_environ, "uwsgi.node", zero);
101
 
        Py_DECREF(zero);
 
157
        PyDict_SetItemString(wsgi_req->async_environ, "uwsgi.node", wi->uwsgi_node);
102
158
 
103
159
 
104
160
#ifdef UWSGI_ROUTING
113
169
 
114
170
 
115
171
        PyTuple_SetItem(wsgi_req->async_args, 0, wsgi_req->async_environ);
116
 
        return python_call(wsgi_req->async_app, wsgi_req->async_args, up.catch_exceptions);
 
172
        return python_call(wsgi_req->async_app, wsgi_req->async_args, up.catch_exceptions, wsgi_req);
117
173
}
118
174
 
119
175
int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) {
138
194
 
139
195
 
140
196
#ifdef UWSGI_SENDFILE
 
197
#ifdef __FreeBSD__
 
198
        if ( ((wsgi_req->sendfile_obj == wsgi_req->async_result) || ( wsgi_req->sendfile_fd_size > 0 && wsgi_req->response_size < wsgi_req->sendfile_fd_size)) && wsgi_req->sendfile_fd != -1) {
 
199
#else
141
200
        if (wsgi_req->sendfile_obj == wsgi_req->async_result && wsgi_req->sendfile_fd != -1) {
 
201
#endif
142
202
                sf_len = uwsgi_sendfile(wsgi_req);
143
203
                if (sf_len < 1) goto clear;
144
204
                wsgi_req->response_size += sf_len;
180
240
                                uwsgi_log("Memory Error detected !!!\n");       
181
241
                        }               
182
242
                        uwsgi.workers[uwsgi.mywid].exceptions++;
 
243
                        uwsgi_apps[wsgi_req->app_id].exceptions++;
183
244
                        PyErr_Print();
184
245
                }       
185
246
                goto clear;