From: Peter Zijlstra Date: Wed, 8 Feb 2006 13:10:53 +0000 (+0100) Subject: Suport Non Parsed Headers (nph) X-Git-Url: https://repo.or.cz/w/mod_fastcgi.git/commitdiff_plain/9bd2a9afcf0196a0314af9d6b3def759a23018ad Suport Non Parsed Headers (nph) This patch adds support for Non Parsed Headers (nph) to mod_fastcgi. Borrowed the code from apache2's mod_cgi. --- diff --git a/fcgi.h b/fcgi.h index 44c13b0..3c9c5a2 100644 --- a/fcgi.h +++ b/fcgi.h @@ -260,6 +260,7 @@ typedef struct _FastCgiServerInfo { u_long totalQueueTime; /* microseconds spent by the web server * waiting to connect to the fastcgi app * since the last dynamicUpdateInterval. */ + int nph; struct _FastCgiServerInfo *next; } fcgi_server; @@ -310,6 +311,7 @@ typedef struct { #ifdef WIN32 BOOL using_npipe_io; /* named pipe io */ #endif + int nph; } fcgi_request; /* Values of parseHeader field */ diff --git a/fcgi_config.c b/fcgi_config.c index 2010e69..2cd11f1 100644 --- a/fcgi_config.c +++ b/fcgi_config.c @@ -733,6 +733,9 @@ const char *fcgi_config_new_static_server(cmd_parms *cmd, void *dummy, const cha else if (strcasecmp(option, "-flush") == 0) { s->flush = 1; } + else if (strcasecmp(option, "-nph") == 0) { + s->nph = 1; + } else if (strcasecmp(option, "-user") == 0) { #ifdef WIN32 return ap_psprintf(tp, diff --git a/fcgi_util.c b/fcgi_util.c index 45d0b9b..a2a6c8a 100644 --- a/fcgi_util.c +++ b/fcgi_util.c @@ -371,11 +371,6 @@ fcgi_util_fs_is_path_ok(pool * const p, const char * const fs_path, struct stat if (stat(fs_path, finfo) < 0) return ap_psprintf(p, "stat(%s) failed: %s", fs_path, strerror(errno)); } - - /* No Parse Header scripts aren't allowed. - * @@@ Well... we really could quite easily */ - if (strncmp(strrchr(fs_path, '/'), "/nph-", 5) == 0) - return ap_psprintf(p, "NPH scripts cannot be run as FastCGI"); if (finfo->st_mode == 0) return ap_psprintf(p, "script not found or unable to stat()"); diff --git a/mod_fastcgi.c b/mod_fastcgi.c index 7f236d3..dd79d35 100644 --- a/mod_fastcgi.c +++ b/mod_fastcgi.c @@ -2469,14 +2469,15 @@ create_fcgi_request(request_rec * const r, } } + fr->nph = (strncmp(strrchr(fs_path, '/'), "/nph-", 5) == 0) || + (fs && fs->nph); + fr->serverInputBuffer = fcgi_buf_new(p, SERVER_BUFSIZE); fr->serverOutputBuffer = fcgi_buf_new(p, SERVER_BUFSIZE); fr->clientInputBuffer = fcgi_buf_new(p, SERVER_BUFSIZE); fr->clientOutputBuffer = fcgi_buf_new(p, SERVER_BUFSIZE); fr->erBufPtr = fcgi_buf_new(p, sizeof(FCGI_EndRequestBody) + 1); fr->gotHeader = FALSE; - fr->parseHeader = SCAN_CGI_READING_HEADERS; - fr->header = ap_make_array(p, 1, 1); fr->fs_stderr = NULL; fr->r = r; fr->readingEndRequestBody = FALSE; @@ -2499,6 +2500,27 @@ create_fcgi_request(request_rec * const r, fr->fd = -1; #endif + if (fr->nph) { + struct ap_filter_t *cur; + + fr->parseHeader = SCAN_CGI_FINISHED; + fr->header = ap_make_array(p, 1, 1); + + /* get rid of all filters up through protocol... since we + * haven't parsed off the headers, there is no way they can + * work + */ + + cur = r->proto_output_filters; + while (cur && cur->frec->ftype < AP_FTYPE_CONNECTION) { + cur = cur->next; + } + r->output_filters = r->proto_output_filters = cur; + } else { + fr->parseHeader = SCAN_CGI_READING_HEADERS; + fr->header = ap_make_array(p, 1, 1); + } + set_uid_n_gid(r, &fr->user, &fr->group); *frP = fr;