You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Rob Hartill <ha...@ooo.lanl.gov> on 1995/08/24 21:10:49 UTC
A feature patch to NPH-ize existing CGI (CGI standard safe)
Attached is a patch which is not a bug fix, but what the hell, it
might be worth playing with, and ultimately merged into a working Apache.
the patch works against 0.8.11
It adds three new features;
1) A companion for ScriptAlias, called "DirectCGIAlias" which is
similar to ScriptAlias except that the script that is called
is treated as a NPH script
2) A "mime" type called "application/x-httpd-direct-cgi" is added
for use with AddType, which maps file extensions to NPH
3) NPH scripts are given a ENV VAR called DIRECT_HEADERS which contains
standard headers, e.g.
HTTP/1.0 %s\r
Date: Thu, 24 Aug 1995 18:49:28 GMT\r
Server: Apache/0.8.11\r
note the '%s' for the script to use to change the response.
Standard CGI scripts can be modified to act as NPH or regular CGI by
checking for "DIRECT_HEADERS", if called in the traditional way, they
send back typical CGI headers. If called as a NPH, the can detect and
use DIRECT_HEADERS, e.g. to modify a perl script add,
if ($ENV{DIRECT_HEADERS}) {
printf($ENV{DIRECT_HEADERS}, "200 Ok");
}
it'll work as before, or as an NPH. Of Course, the script has full control
over its output, so it can ignore or massage the contents of DIRECT_HEADERS
to suit its needs.
Some quick tests on my HP showed that response times for the NPH-esque
versions of the same script gave responses which were 40% quicker. Not
a big surprise when you consider all the process<->process data xfer that
goes on between Apache and CGI. The only real drawback I can see is that
Apache isn't able to log Status and bytes-sent for NPH, but for people
who don't care about these things (I don't) it's a small price to pay.
Anyway, this is a first attempt, nothing is carved into stone, but I think
when we start adding features to Apache, this should be one of them.
enjoy,
rob
*** mod_cgi.c.orig Thu Aug 24 11:07:46 1995
--- mod_cgi.c Thu Aug 24 12:45:33 1995
***************
*** 93,99 ****
int is_scriptaliased (request_rec *r)
{
char *t = table_get (r->notes, "alias-forced-type");
! return t && (!strcmp (t, CGI_MAGIC_TYPE));
}
/****************************************************************
--- 93,104 ----
int is_scriptaliased (request_rec *r)
{
char *t = table_get (r->notes, "alias-forced-type");
! return t
! &&
! (!strcmp (t, CGI_MAGIC_TYPE))
! &&
! (!strcmp (t, DIRECT_CGI_MAGIC_TYPE))
! ;
}
/****************************************************************
***************
*** 225,230 ****
--- 230,236 ----
char argsbuffer[HUGE_STRING_LEN];
int is_included = !strcmp (r->protocol, "INCLUDED");
char *lenp = table_get (r->headers_in, "Content-length");
+ char *t = table_get (r->notes, "alias-forced-type");
struct cgi_child_stuff cld;
***************
*** 232,238 ****
argv0++;
else argv0 = r->filename;
! nph = !(strncmp(argv0,"nph-",4));
if (!(allow_options (r) & OPT_EXECCGI) && !is_scriptaliased (r)) {
log_reason("Options ExecCGI is off in this directory", r->filename, r);
--- 238,255 ----
argv0++;
else argv0 = r->filename;
! nph = !(strncmp(argv0,"nph-",4))
! || !(strcmp(t, DIRECT_CGI_MAGIC_TYPE))
! || !(strcmp(r->content_type, DIRECT_CGI_MAGIC_TYPE));
!
! if (nph) {
! table *e = r->subprocess_env;
! char default_headers[HUGE_STRING_LEN];
!
! sprintf(default_headers, "%s %%s\015\012Date: %s\015\012Server: %s\015\012", SERVER_PROTOCOL,gm_timestr_822 (r->pool, time(NULL)),SERVER_VERSION);
!
! table_set (e, "DIRECT_HEADERS", default_headers);
! }
if (!(allow_options (r) & OPT_EXECCGI) && !is_scriptaliased (r)) {
log_reason("Options ExecCGI is off in this directory", r->filename, r);
***************
*** 344,349 ****
--- 361,367 ----
handler_rec cgi_handlers[] = {
{ CGI_MAGIC_TYPE, cgi_handler },
+ { DIRECT_CGI_MAGIC_TYPE, cgi_handler },
{ NULL }
};
*** httpd.h.orig Thu Aug 24 11:16:33 1995
--- httpd.h Thu Aug 24 11:16:57 1995
***************
*** 216,221 ****
--- 216,222 ----
#define M_INVALID 4
#define CGI_MAGIC_TYPE "application/x-httpd-cgi"
+ #define DIRECT_CGI_MAGIC_TYPE "application/x-httpd-direct-cgi"
#define INCLUDES_MAGIC_TYPE "text/x-server-parsed-html"
#define INCLUDES_MAGIC_TYPE3 "text/x-server-parsed-html3"
#define MAP_FILE_MAGIC_TYPE "application/x-type-map"
*** mod_alias.c.orig Thu Aug 24 11:15:28 1995
--- mod_alias.c Thu Aug 24 11:16:17 1995
***************
*** 148,153 ****
--- 148,155 ----
"a fakename and a realname"},
{ "ScriptAlias", add_alias, CGI_MAGIC_TYPE, RSRC_CONF, TAKE2,
"a fakename and a realname"},
+ { "DirectCGIAlias", add_alias, DIRECT_CGI_MAGIC_TYPE, RSRC_CONF, TAKE2,
+ "a fakename and a realname"},
{ "Redirect", add_redirect, NULL, RSRC_CONF, TAKE2,
"a document to be redirected, then the destination URL" },
{ NULL }