mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-05 13:11:33 +00:00
added --manage-script-name
This commit is contained in:
@@ -236,8 +236,11 @@ static void *http_request(void *u_h_r) {
|
||||
if (!qs) {
|
||||
up = add_uwsgi_var(up, "QUERY_STRING", 12, NULL, 0, 0, watermark);
|
||||
}
|
||||
|
||||
up = add_uwsgi_var(up, "SCRIPT_NAME", 11, "", 0, 0, watermark);
|
||||
up = add_uwsgi_var(up, "PATH_INFO", 9, tmp_buf, path_info_len, 0, watermark);
|
||||
|
||||
|
||||
ptr = tmp_buf;
|
||||
state = uwsgi_http_protocol;
|
||||
|
||||
@@ -290,7 +293,6 @@ static void *http_request(void *u_h_r) {
|
||||
up = add_uwsgi_var(up, "SERVER_NAME", 11, uwsgi.http_server_name, strlen(uwsgi.http_server_name), 0, watermark);
|
||||
up = add_uwsgi_var(up, "SERVER_PORT", 11, uwsgi.http_server_port, strlen(uwsgi.http_server_port), 0, watermark);
|
||||
|
||||
up = add_uwsgi_var(up, "SCRIPT_NAME", 11, "", 0, 0, watermark);
|
||||
|
||||
ip = inet_ntoa(ur->c_addr.sin_addr);
|
||||
up = add_uwsgi_var(up, "REMOTE_ADDR", 11, ip, strlen(ip), 0, watermark);
|
||||
|
||||
@@ -772,35 +772,46 @@ int uwsgi_python_magic(char *mountpoint, char *lazy) {
|
||||
|
||||
}
|
||||
|
||||
int uwsgi_python_xml(char *node, char *content) {
|
||||
int uwsgi_python_xml(char *node, char *content) {
|
||||
|
||||
if (!strcmp("script", node)) {
|
||||
return init_uwsgi_app(LOADER_UWSGI, content, uwsgi.wsgi_req, uwsgi.single_interpreter-1);
|
||||
}
|
||||
else if (!strcmp("file", node)) {
|
||||
return init_uwsgi_app(LOADER_FILE, content, uwsgi.wsgi_req, uwsgi.single_interpreter-1);
|
||||
}
|
||||
else if (!strcmp("eval", node)) {
|
||||
return init_uwsgi_app(LOADER_EVAL, content, uwsgi.wsgi_req, uwsgi.single_interpreter-1);
|
||||
}
|
||||
else if (!strcmp("module", node)) {
|
||||
uwsgi.wsgi_req->module = content;
|
||||
uwsgi.wsgi_req->module_len = strlen(content);
|
||||
return 1;
|
||||
}
|
||||
else if (!strcmp("pyhome", node)) {
|
||||
uwsgi.wsgi_req->pyhome = content;
|
||||
uwsgi.wsgi_req->pyhome_len = strlen(content);
|
||||
return 1;
|
||||
}
|
||||
else if (!strcmp("callable", node)) {
|
||||
uwsgi.wsgi_req->callable = content;
|
||||
uwsgi.wsgi_req->callable_len = strlen(content);
|
||||
return init_uwsgi_app(LOADER_DYN, uwsgi.wsgi_req, uwsgi.wsgi_req, uwsgi.single_interpreter-1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (!strcmp("script", node)) {
|
||||
return init_uwsgi_app(LOADER_UWSGI, content, uwsgi.wsgi_req, uwsgi.single_interpreter-1);
|
||||
}
|
||||
else if (!strcmp("file", node)) {
|
||||
return init_uwsgi_app(LOADER_FILE, content, uwsgi.wsgi_req, uwsgi.single_interpreter-1);
|
||||
}
|
||||
else if (!strcmp("eval", node)) {
|
||||
return init_uwsgi_app(LOADER_EVAL, content, uwsgi.wsgi_req, uwsgi.single_interpreter-1);
|
||||
}
|
||||
else if (!strcmp("wsgi", node)) {
|
||||
return init_uwsgi_app(LOADER_EVAL, content, uwsgi.wsgi_req, uwsgi.single_interpreter-1);
|
||||
}
|
||||
else if (!strcmp("module", node)) {
|
||||
uwsgi.wsgi_req->module = content;
|
||||
uwsgi.wsgi_req->module_len = strlen(content);
|
||||
uwsgi.wsgi_req->callable = strchr(uwsgi.wsgi_req->module, ':');
|
||||
if (uwsgi.wsgi_req->callable) {
|
||||
uwsgi.wsgi_req->callable[0] = 0;
|
||||
uwsgi.wsgi_req->callable++;
|
||||
uwsgi.wsgi_req->callable_len = strlen(uwsgi.wsgi_req->callable);
|
||||
uwsgi.wsgi_req->module_len = strlen(uwsgi.wsgi_req->module);
|
||||
return init_uwsgi_app(LOADER_DYN, uwsgi.wsgi_req, uwsgi.wsgi_req, uwsgi.single_interpreter-1);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else if (!strcmp("pyhome", node)) {
|
||||
uwsgi.wsgi_req->pyhome = content;
|
||||
uwsgi.wsgi_req->pyhome_len = strlen(content);
|
||||
return 1;
|
||||
}
|
||||
else if (!strcmp("callable", node)) {
|
||||
uwsgi.wsgi_req->callable = content;
|
||||
uwsgi.wsgi_req->callable_len = strlen(content);
|
||||
return init_uwsgi_app(LOADER_DYN, uwsgi.wsgi_req, uwsgi.wsgi_req, uwsgi.single_interpreter-1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void uwsgi_python_suspend(struct wsgi_request *wsgi_req) {
|
||||
|
||||
|
||||
+43
@@ -321,6 +321,7 @@ int uwsgi_parse_vars(struct wsgi_request *wsgi_req) {
|
||||
|
||||
ptrbuf = buffer;
|
||||
bufferend = ptrbuf + wsgi_req->uh.pktsize;
|
||||
int i, script_name= -1, path_info= -1;
|
||||
|
||||
/* set an HTTP 500 status as default */
|
||||
wsgi_req->status = 500;
|
||||
@@ -355,6 +356,7 @@ int uwsgi_parse_vars(struct wsgi_request *wsgi_req) {
|
||||
if (!uwsgi_strncmp("SCRIPT_NAME", 11, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
|
||||
wsgi_req->script_name = ptrbuf;
|
||||
wsgi_req->script_name_len = strsize;
|
||||
script_name = wsgi_req->var_cnt + 1;
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_debug("SCRIPT_NAME=%.*s\n", wsgi_req->script_name_len, wsgi_req->script_name);
|
||||
#endif
|
||||
@@ -362,6 +364,7 @@ int uwsgi_parse_vars(struct wsgi_request *wsgi_req) {
|
||||
else if (!uwsgi_strncmp("PATH_INFO", 9, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
|
||||
wsgi_req->path_info = ptrbuf;
|
||||
wsgi_req->path_info_len = strsize;
|
||||
path_info = wsgi_req->var_cnt + 1;
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_debug("PATH_INFO=%.*s\n", wsgi_req->path_info_len, wsgi_req->path_info);
|
||||
#endif
|
||||
@@ -471,6 +474,46 @@ int uwsgi_parse_vars(struct wsgi_request *wsgi_req) {
|
||||
}
|
||||
|
||||
|
||||
if (uwsgi.manage_script_name) {
|
||||
if (uwsgi.apps_cnt > 0 && wsgi_req->path_info_len > 1) {
|
||||
// starts with 1 as the 0 app is the default (/) one
|
||||
int best_found = 0;
|
||||
char *orig_path_info = wsgi_req->path_info;
|
||||
int orig_path_info_len = wsgi_req->path_info_len;
|
||||
// if SCRIPT_NAME is not allocated, add a slot for it
|
||||
if (script_name == -1) {
|
||||
if (wsgi_req->var_cnt >= uwsgi.vec_size - (4 + 2)) {
|
||||
uwsgi_log( "max vec size reached. skip this header.\n");
|
||||
return -1;
|
||||
}
|
||||
wsgi_req->var_cnt++;
|
||||
wsgi_req->hvec[wsgi_req->var_cnt].iov_base = "SCRIPT_NAME";
|
||||
wsgi_req->hvec[wsgi_req->var_cnt].iov_len = 11;
|
||||
wsgi_req->var_cnt++;
|
||||
script_name = wsgi_req->var_cnt;
|
||||
}
|
||||
for(i=1;i<uwsgi.apps_cnt;i++) {
|
||||
uwsgi_log("app mountpoint = %.*s\n", uwsgi.apps[i].mountpoint_len, uwsgi.apps[i].mountpoint);
|
||||
if (orig_path_info_len >= uwsgi.apps[i].mountpoint_len) {
|
||||
if (!uwsgi_startswith(orig_path_info, uwsgi.apps[i].mountpoint, uwsgi.apps[i].mountpoint_len) && uwsgi.apps[i].mountpoint_len > best_found) {
|
||||
best_found = uwsgi.apps[i].mountpoint_len;
|
||||
wsgi_req->script_name = uwsgi.apps[i].mountpoint;
|
||||
wsgi_req->script_name_len = uwsgi.apps[i].mountpoint_len;
|
||||
wsgi_req->path_info = orig_path_info+wsgi_req->script_name_len;
|
||||
wsgi_req->path_info_len = orig_path_info_len-wsgi_req->script_name_len;
|
||||
|
||||
wsgi_req->hvec[script_name].iov_base = wsgi_req->script_name;
|
||||
wsgi_req->hvec[script_name].iov_len = wsgi_req->script_name_len;
|
||||
|
||||
wsgi_req->hvec[path_info].iov_base = wsgi_req->path_info;
|
||||
wsgi_req->hvec[path_info].iov_len = wsgi_req->path_info_len;
|
||||
uwsgi_log("managed SCRIPT_NAME = %.*s PATH_INFO = %.*s\n", wsgi_req->script_name_len, wsgi_req->script_name, wsgi_req->path_info_len, wsgi_req->path_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -640,6 +640,17 @@ inline int uwsgi_strncmp(char *src, int slen, char *dst, int dlen) {
|
||||
|
||||
}
|
||||
|
||||
inline int uwsgi_startswith(char *src, char *what, int wlen) {
|
||||
|
||||
int i;
|
||||
|
||||
for(i=0;i<wlen;i++) {
|
||||
if (src[i] != what[i]) return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *uwsgi_concatn(int c, ...) {
|
||||
|
||||
va_list s;
|
||||
|
||||
@@ -89,6 +89,7 @@ static struct option long_base_options[] = {
|
||||
{"post-buffering-bufsize", required_argument, 0, LONG_ARGS_POST_BUFFERING_SIZE},
|
||||
{"upload-progress", required_argument, 0, LONG_ARGS_UPLOAD_PROGRESS},
|
||||
{"no-default-app", no_argument, &uwsgi.no_default_app, 1},
|
||||
{"manage-script-name", no_argument, &uwsgi.manage_script_name, 1},
|
||||
#ifdef UWSGI_UDP
|
||||
{"udp", required_argument, 0, LONG_ARGS_UDP},
|
||||
#endif
|
||||
|
||||
@@ -591,6 +591,7 @@ struct uwsgi_server {
|
||||
#endif
|
||||
|
||||
int ignore_script_name;
|
||||
int manage_script_name;
|
||||
int no_default_app;
|
||||
int logdate;
|
||||
|
||||
@@ -1096,8 +1097,10 @@ void uwsgi_ldap_config(void);
|
||||
|
||||
#ifdef __clang__
|
||||
int uwsgi_strncmp(char *, int, char *, int);
|
||||
int uwsgi_startswith(char *, char *, int);
|
||||
#else
|
||||
inline int uwsgi_strncmp(char *, int, char *, int);
|
||||
inline int uwsgi_startswith(char *, char *, int);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user