[PATCH] NPH support for mod_fastcgi; detect aborted client connections
Peter Zijlstra <[email protected]>
| Newsgroups | gmane.comp.web.fastcgi.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, Two patches for mod_fastcgi we are using. The first adds support for non parsed headers. The second solved Andrej's problem of not getting any notification when the web-client aborts the connection. Kind regards, Peter Zijlstra ___________________________________ fastcgi-developers mailing list http://fastcgi.com/fastcgi-developers/
nph-support.patch
(message/rfc822, 4.4 KB)
Date: Wed, 08 Feb 2006 14:10:53 +0100 Subject: No Subject Message-Id: <1139404253.6087.12.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit From: From: <[email protected]> This patch adds support for Non Parsed Headers (nph) to mod_fastcgi. Borrowed the code from apache2's mod_cgi. fcgi.h | 2 ++ fcgi_config.c | 3 +++ fcgi_util.c | 2 ++ mod_fastcgi.c | 26 ++++++++++++++++++++++++-- 4 files changed, 31 insertions(+), 2 deletions(-) Index: libapache-mod-fastcgi-2.4.2/fcgi.h =================================================================== --- libapache-mod-fastcgi-2.4.2.orig/fcgi.h 2006-02-08 12:45:39.272399520 +0100 +++ libapache-mod-fastcgi-2.4.2/fcgi.h 2006-02-08 12:45:42.041097545 +0100 @@ -228,6 +228,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; @@ -278,6 +279,7 @@ typedef struct { #ifdef WIN32 BOOL using_npipe_io; /* named pipe io */ #endif + int nph; } fcgi_request; /* Values of parseHeader field */ Index: libapache-mod-fastcgi-2.4.2/fcgi_util.c =================================================================== --- libapache-mod-fastcgi-2.4.2.orig/fcgi_util.c 2006-02-08 12:45:39.305395921 +0100 +++ libapache-mod-fastcgi-2.4.2/fcgi_util.c 2006-02-08 12:45:42.042097435 +0100 @@ -372,10 +372,12 @@ fcgi_util_fs_is_path_ok(pool * const p, return ap_psprintf(p, "stat(%s) failed: %s", fs_path, strerror(errno)); } +#if 0 /* 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"); +#endif if (finfo->st_mode == 0) return ap_psprintf(p, "script not found or unable to stat()"); Index: libapache-mod-fastcgi-2.4.2/mod_fastcgi.c =================================================================== --- libapache-mod-fastcgi-2.4.2.orig/mod_fastcgi.c 2006-02-08 12:45:39.305395921 +0100 +++ libapache-mod-fastcgi-2.4.2/mod_fastcgi.c 2006-02-08 14:03:13.107341283 +0100 @@ -2469,14 +2469,14 @@ create_fcgi_request(request_rec * const } } + fr->nph = (strstr(fs_path, "/nph-") != NULL) || (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 +2499,28 @@ create_fcgi_request(request_rec * const 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; Index: libapache-mod-fastcgi-2.4.2/fcgi_config.c =================================================================== --- libapache-mod-fastcgi-2.4.2.orig/fcgi_config.c 2006-02-08 12:45:39.271399629 +0100 +++ libapache-mod-fastcgi-2.4.2/fcgi_config.c 2006-02-08 12:45:42.044097217 +0100 @@ -728,6 +728,9 @@ const char *fcgi_config_new_static_serve 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,
conn_abort.patch
(message/rfc822, 1.2 KB)
Date: Wed, 08 Feb 2006 14:10:53 +0100 Subject: No Subject Message-Id: <1139404253.6087.13.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit From: From: Peter Zijlstra <[email protected]> In order to hande the disconnect of web-clients mod_fastcgi needs not only check the return status of ap_pass_brigade() but also the connection state. Otherwise the process manager will glady keep the connection to the FastCGI process open until it is done generating data. mod_fastcgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) Index: libapache-mod-fastcgi-2.4.2/mod_fastcgi.c =================================================================== --- libapache-mod-fastcgi-2.4.2.orig/mod_fastcgi.c 2006-02-08 12:45:42.043097326 +0100 +++ libapache-mod-fastcgi-2.4.2/mod_fastcgi.c 2006-02-08 12:46:45.252202694 +0100 @@ -932,7 +932,7 @@ static int write_to_client(fcgi_request #endif - if (rv) + if (rv || fr->r->connection->aborted) { ap_log_rerror(FCGI_LOG_INFO_NOERRNO, fr->r, "FastCGI: client stopped connection before send body completed");