--- src/mod_fastcgi.c (revision 102) +++ src/mod_fastcgi.c (working copy) @@ -329,10 +329,10 @@ int fd; /* fd to the fastcgi process */ int fde_ndx; /* index into the fd-event buffer */ - size_t path_info_offset; /* start of path_info in uri.path */ - pid_t pid; int got_proc; + + buffer *extension; /* used extension, used for SCRIPT_NAME/PATH_INFO of check-local=0 */ plugin_config conf; @@ -359,6 +359,7 @@ hctx->response = buffer_init(); hctx->response_header = buffer_init(); hctx->write_buffer = buffer_init(); + hctx->extension = buffer_init(); hctx->request_id = 0; hctx->state = FCGI_STATE_INIT; @@ -379,6 +380,7 @@ buffer_free(hctx->response); buffer_free(hctx->response_header); buffer_free(hctx->write_buffer); + buffer_free(hctx->extension); if (hctx->rb) { if (hctx->rb->ptr) free(hctx->rb->ptr); @@ -1650,22 +1652,74 @@ * For AUTHORIZER mode these headers should be omitted. */ - fcgi_env_add(p->fcgi_env, CONST_STR_LEN("SCRIPT_NAME"), CONST_BUF_LEN(con->uri.path)); + if (host->check_local == 0 && + !buffer_is_empty(hctx->extension) && + hctx->extension->ptr[0] == '/') { + char *sl; + /* no local check and path-prefix /fcgi_pattern + * + * zope needs this + * + * SCRIPT_NAME => /fcgi_pattern + * PATH_INFO => uri.path - /fcgi_pattern + * + */ + + /* search for / in uri.path after /fcgi_pattern + * + * uri.path = /zope/abc + * + * pattern SCRIPT_NAME PATH_INFO + * /zop /zope /abc + * /zope/ /zope /abc + * /zope/abc /zope/abc (empty) + * / /zope/abc (empty) + * + */ + if (hctx->extension->used == 2) { + /* ext is / only */ + fcgi_env_add(p->fcgi_env, CONST_STR_LEN("SCRIPT_NAME"), CONST_STR_LEN("")); + fcgi_env_add(p->fcgi_env, CONST_STR_LEN("PATH_INFO"), CONST_BUF_LEN(con->uri.path)); + + } else if (hctx->extension->ptr[hctx->extension->used - 2] == '/') { + /* last character is a / */ + + fcgi_env_add(p->fcgi_env, CONST_STR_LEN("SCRIPT_NAME"), con->uri.path->ptr, hctx->extension->used - 2); + if (con->uri.path->used > hctx->extension->used) { + fcgi_env_add(p->fcgi_env, CONST_STR_LEN("PATH_INFO"), + con->uri.path->ptr + hctx->extension->used - 2, + con->uri.path->used - hctx->extension->used + 1); + } else { + fcgi_env_add(p->fcgi_env, CONST_STR_LEN("PATH_INFO"), CONST_STR_LEN("")); + } + + } else if (NULL != (sl = strchr(con->uri.path->ptr + hctx->extension->used - 1, '/'))) { + /* a trailing slash was found */ + fcgi_env_add(p->fcgi_env, CONST_STR_LEN("SCRIPT_NAME"), con->uri.path->ptr, sl - con->uri.path->ptr - 1); + fcgi_env_add(p->fcgi_env, CONST_STR_LEN("PATH_INFO"), sl, strlen(sl)); + } else { + fcgi_env_add(p->fcgi_env, CONST_STR_LEN("SCRIPT_NAME"), CONST_BUF_LEN(con->uri.path)); + fcgi_env_add(p->fcgi_env, CONST_STR_LEN("PATH_INFO"), CONST_STR_LEN("")); + } + + } else { + fcgi_env_add(p->fcgi_env, CONST_STR_LEN("SCRIPT_NAME"), CONST_BUF_LEN(con->uri.path)); - if (!buffer_is_empty(con->request.pathinfo)) { - fcgi_env_add(p->fcgi_env, CONST_STR_LEN("PATH_INFO"), CONST_BUF_LEN(con->request.pathinfo)); + if (!buffer_is_empty(con->request.pathinfo)) { + fcgi_env_add(p->fcgi_env, CONST_STR_LEN("PATH_INFO"), CONST_BUF_LEN(con->request.pathinfo)); + + /* PATH_TRANSLATED is only defined if PATH_INFO is set */ - /* PATH_TRANSLATED is only defined if PATH_INFO is set */ - - if (!buffer_is_empty(host->docroot)) { - buffer_copy_string_buffer(p->path, host->docroot); + if (!buffer_is_empty(host->docroot)) { + buffer_copy_string_buffer(p->path, host->docroot); + } else { + buffer_copy_string_buffer(p->path, con->physical.doc_root); + } + buffer_append_string_buffer(p->path, con->request.pathinfo); + fcgi_env_add(p->fcgi_env, CONST_STR_LEN("PATH_TRANSLATED"), CONST_BUF_LEN(p->path)); } else { - buffer_copy_string_buffer(p->path, con->physical.doc_root); + fcgi_env_add(p->fcgi_env, CONST_STR_LEN("PATH_INFO"), CONST_STR_LEN("")); } - buffer_append_string_buffer(p->path, con->request.pathinfo); - fcgi_env_add(p->fcgi_env, CONST_STR_LEN("PATH_TRANSLATED"), CONST_BUF_LEN(p->path)); - } else { - fcgi_env_add(p->fcgi_env, CONST_STR_LEN("PATH_INFO"), CONST_STR_LEN("")); } } @@ -2923,7 +2977,6 @@ size_t k, i; buffer *fn; fcgi_extension *extension = NULL; - size_t path_info_offset; /* Possibly, we processed already this request */ if (con->file_started == 1) return HANDLER_GO_ON; @@ -2944,8 +2997,6 @@ fcgi_patch_connection(srv, con, p, CONST_BUF_LEN(patch)); } - path_info_offset = 0; - /* check if extension matches */ for (k = 0; k < p->conf.exts->used; k++) { size_t ct_len; @@ -2958,15 +3009,8 @@ if (s_len < ct_len) continue; - /* check extension in the form "/fcgi_pattern" */ if (*(extension->key->ptr) == '/' && strncmp(fn->ptr, extension->key->ptr, ct_len) == 0) { - if (s_len > ct_len + 1) { - char *pi_offset; - - if (0 != (pi_offset = strchr(fn->ptr + ct_len + 1, '/'))) { - path_info_offset = pi_offset - fn->ptr; - } - } + /* check extension in the form "/fcgi_pattern" */ break; } else if (0 == strncmp(fn->ptr + s_len - ct_len, extension->key->ptr, ct_len)) { /* check extension in the form ".fcg" */ @@ -3008,7 +3052,7 @@ handler_ctx *hctx; hctx = handler_ctx_init(); - hctx->path_info_offset = path_info_offset; + buffer_copy_string_buffer(hctx->extension, extension->key); hctx->remote_conn = con; hctx->plugin_data = p; hctx->host = host; @@ -3028,7 +3072,6 @@ handler_ctx *hctx; hctx = handler_ctx_init(); - hctx->path_info_offset = path_info_offset; hctx->remote_conn = con; hctx->plugin_data = p; hctx->host = host;