diff --git a/core/protocol.c b/core/protocol.c index 5e650afb..b1c83e24 100644 --- a/core/protocol.c +++ b/core/protocol.c @@ -736,23 +736,34 @@ next: } for (i = 0; i < uwsgi_apps_cnt; i++) { + char* mountpoint = uwsgi_apps[i].mountpoint; + int mountpoint_len = uwsgi_apps[i].mountpoint_len; + + // Ignore trailing mountpoint slashes + if (mountpoint[mountpoint_len - 1] == '/') { + mountpoint_len -= 1; + } + //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; + if (orig_path_info_len >= mountpoint_len) { + if (!uwsgi_startswith(orig_path_info, mountpoint, mountpoint_len) + && mountpoint_len > best_found) { + if (!(orig_path_info_len > mountpoint_len && orig_path_info[mountpoint_len] != '/' )) { + best_found = 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[wsgi_req->script_name_pos].iov_base = wsgi_req->script_name; - wsgi_req->hvec[wsgi_req->script_name_pos].iov_len = wsgi_req->script_name_len; + wsgi_req->hvec[wsgi_req->script_name_pos].iov_base = wsgi_req->script_name; + wsgi_req->hvec[wsgi_req->script_name_pos].iov_len = wsgi_req->script_name_len; - wsgi_req->hvec[wsgi_req->path_info_pos].iov_base = wsgi_req->path_info; - wsgi_req->hvec[wsgi_req->path_info_pos].iov_len = wsgi_req->path_info_len; + wsgi_req->hvec[wsgi_req->path_info_pos].iov_base = wsgi_req->path_info; + wsgi_req->hvec[wsgi_req->path_info_pos].iov_len = wsgi_req->path_info_len; #ifdef UWSGI_DEBUG - 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); + 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); #endif + } } } } @@ -1056,7 +1067,7 @@ char *uwsgi_req_append(struct wsgi_request *wsgi_req, char *key, uint16_t keylen wsgi_req->var_cnt++; ptr += keylen; - + *ptr++ = (uint8_t) (vallen & 0xff); *ptr++ = (uint8_t) ((vallen >> 8) & 0xff); @@ -1123,13 +1134,13 @@ int uwsgi_req_append_path_info_with_index(struct wsgi_request *wsgi_req, char *i *ptr ++= '/'; } memcpy(ptr, index, index_len); - + wsgi_req->hvec[wsgi_req->var_cnt].iov_base = new_path_info; wsgi_req->hvec[wsgi_req->var_cnt].iov_len = wsgi_req->path_info_len; wsgi_req->var_cnt++; wsgi_req->len += 13 + wsgi_req->path_info_len; wsgi_req->path_info = new_path_info; - + return 0; }