mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-01 02:35:03 +00:00
better virtual host mode
This commit is contained in:
@@ -407,9 +407,16 @@ int uwsgi_parse_vars(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req)
|
||||
wsgi_req->pyhome = ptrbuf;
|
||||
wsgi_req->pyhome_len = strsize;
|
||||
}
|
||||
else if (!uwsgi_strncmp("UWSGI_CHDIR", 11, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
|
||||
wsgi_req->chdir = ptrbuf;
|
||||
wsgi_req->chdir_len = strsize;
|
||||
}
|
||||
else if (!uwsgi_strncmp("SERVER_NAME", 11, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
|
||||
wsgi_req->host = ptrbuf;
|
||||
wsgi_req->host_len = strsize;
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_debug("SERVER_NAME=%.*s\n", wsgi_req->host_len, wsgi_req->host);
|
||||
#endif
|
||||
}
|
||||
else if (!uwsgi_strncmp("HTTPS", 5, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
|
||||
wsgi_req->https = ptrbuf;
|
||||
|
||||
@@ -2036,6 +2036,23 @@ int init_uwsgi_app(PyObject * force_wsgi_dict, PyObject * my_callable) {
|
||||
|
||||
memset(wi, 0, sizeof(struct uwsgi_app));
|
||||
|
||||
// dynamic chdir ?
|
||||
|
||||
if (uwsgi.wsgi_req->chdir_len > 0) {
|
||||
wi->chdir = malloc(uwsgi.wsgi_req->chdir_len + 1);
|
||||
if (wi->chdir == NULL) {
|
||||
uwsgi_error("malloc()");
|
||||
}
|
||||
memcpy(wi->chdir, uwsgi.wsgi_req->chdir, uwsgi.wsgi_req->chdir_len);
|
||||
wi->chdir[uwsgi.wsgi_req->chdir_len] = 0;
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_debug("chdir to %s\n", wi->chdir);
|
||||
#endif
|
||||
if (chdir(wi->chdir)) {
|
||||
uwsgi_error("chdir()");
|
||||
}
|
||||
}
|
||||
|
||||
if (uwsgi.single_interpreter == 0) {
|
||||
wi->interpreter = Py_NewInterpreter();
|
||||
if (!wi->interpreter) {
|
||||
|
||||
@@ -307,6 +307,7 @@ struct uwsgi_app {
|
||||
#endif
|
||||
|
||||
int requests;
|
||||
char *chdir;
|
||||
|
||||
};
|
||||
|
||||
@@ -394,6 +395,9 @@ struct wsgi_request {
|
||||
char *pyhome;
|
||||
uint16_t pyhome_len;
|
||||
|
||||
char *chdir;
|
||||
uint16_t chdir_len;
|
||||
|
||||
int fd_closed;
|
||||
|
||||
int sendfile_fd;
|
||||
|
||||
+12
-1
@@ -145,6 +145,9 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
#else
|
||||
PyString_Concat(&zero, PyString_FromString("|"));
|
||||
PyString_Concat(&zero, PyString_FromStringAndSize(wsgi_req->script_name, wsgi_req->script_name_len));
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_debug("VirtualHost SCRIPT_NAME=%s\n", PyString_AsString(zero));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
@@ -155,7 +158,7 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
if (PyDict_Contains(uwsgi->py_apps, zero)) {
|
||||
wsgi_req->app_id = PyInt_AsLong(PyDict_GetItem(uwsgi->py_apps, zero));
|
||||
}
|
||||
else if (wsgi_req->script_name_len > 1 || uwsgi->default_app < 0) {
|
||||
else if (wsgi_req->script_name_len > 1 || uwsgi->default_app < 0 || uwsgi->vhost) {
|
||||
/* unavailable app for this SCRIPT_NAME */
|
||||
wsgi_req->app_id = -1;
|
||||
if (wsgi_req->wsgi_script_len > 0 || (wsgi_req->wsgi_callable_len > 0 && wsgi_req->wsgi_module_len > 0)) {
|
||||
@@ -192,6 +195,14 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
|
||||
// set the interpreter
|
||||
PyThreadState_Swap(wi->interpreter);
|
||||
if (wi->chdir) {
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_debug("chdir to %s\n", wi->chdir);
|
||||
#endif
|
||||
if (chdir(wi->chdir)) {
|
||||
uwsgi_error("chdir()");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wi->requests++;
|
||||
|
||||
Reference in New Issue
Block a user