You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Dave Rolsky <au...@urth.org> on 2000/11/28 06:00:49 UTC

Potential patch for mod_proxy in the 1.3.* code

First, a description of the problem.

I am primarily a Perl programmer and I do a lot of work with mod_perl.  I
recently wrote some MP3 serving code similar to Lincoln Stein's
Apache::MP3 module.  One aspect of this code is to generate ICY protocol
headers as part of serving streaming MP3.

Per a fairly standard Apache/mod_perl, I have two separate httpd instances
running.  One, on port 80, is a 'plain' Apache without mod_perl.  This
server proxies requests that need mod_perl to a mod_perl enabled server on
another port.

Back to the ICY headers.  This protocol does not run over HTTP, so I
needed total control over what gets sent to the client.  If the client
connects directly to the mod_perl enabled server, there is no problem.
However, mod_proxy will add the following lines to any 'malformed'
(backasswards in the code ;) responses from the server to which it is
proxying.

HTTP/1.0 200 OK
Date: <date>

Normally this is desirable but it was hosing up the ICY headers in my
precious MP3 stream!

So I decided mod_proxy needed another configuration directive to allow
this header addition to be turned of, which I called ProxyAddHeaders
(better name suggestions are welcome).  By default this is true, in which
case the default behavior is left alone.  If it is false, then the first
line is not added to the output.

The second line, the Date header, actually comes from some actions inside
the ap_proxy_cache_update routine.  Right now I've just set NoCache *
inside my config file to work around this.  However, if there is interest
in this patch I would be happy to fix this issue as well.  There are
several ways around it.  Either I can have ap_proxy_cache_update check the
conf->add_headers value _or_ I can simply delete the Date header after it
is added if it wasn't already there, assuming that ProxyAddHeaders is
false.

Anyway, below is my first hack at a patch against the Apache 1.3.12
source.  If there is interest in this patch for the core I would of course
do a patch against the latest CVS version.


-dave

/*==================
www.urth.org
We await the New Sun
==================*/



diff -u proxy/mod_proxy.c /usr/src/misc/apache_1.3.12-2/src/modules/proxy/mod_proxy.c
--- proxy/mod_proxy.c	Tue Jan 11 08:13:43 2000
+++ /usr/src/misc/apache_1.3.12-2/src/modules/proxy/mod_proxy.c	Mon Nov 27 21:36:38 2000
@@ -441,6 +441,7 @@
     ps->cache.dirlength_set = 0;
     ps->cache.cache_completion = DEFAULT_CACHE_COMPLETION;
     ps->cache.cache_completion_set = 0;
+    ps->add_headers = 1;

     return ps;
 }
@@ -476,6 +477,7 @@
     ps->cache.dirlevels = (overrides->cache.dirlevels_set == 0) ? base->cache.dirlevels : overrides->cache.dirlevels;
     ps->cache.dirlength = (overrides->cache.dirlength_set == 0) ? base->cache.dirlength : overrides->cache.dirlength;
     ps->cache.cache_completion = (overrides->cache.cache_completion_set == 0) ? base->cache.cache_completion : overrides->cache.cache_completion;
+    ps->add_headers = (overrides->add_headers_set == 0) ? base->add_headers : overrides->add_headers;

     return ps;
 }
@@ -882,6 +884,18 @@
     return NULL;
 }

+static const char *
+    set_add_headers(cmd_parms *parms, void *dummy, int flag)
+{
+    proxy_server_conf *psf =
+    ap_get_module_config(parms->server->module_config, &proxy_module);
+
+    psf->add_headers = flag;
+    psf->add_headers_set = 1;
+    return NULL;
+}
+
+
 static const handler_rec proxy_handlers[] =
 {
     {"proxy-server", proxy_handler},
@@ -930,6 +944,8 @@
      "Force a http cache completion after this percentage is loaded"},
     {"ProxyVia", set_via_opt, NULL, RSRC_CONF, TAKE1,
      "Configure Via: proxy header header to one of: on | off | block | full"},
+    {"ProxyAddHeaders", set_add_headers, NULL, RSRC_CONF, FLAG,
+     "add minimal HTTP headers if none are received from the server being proxied to"},
     {NULL}
 };

diff -u proxy/mod_proxy.h /usr/src/misc/apache_1.3.12-2/src/modules/proxy/mod_proxy.h
--- proxy/mod_proxy.h	Tue Jan 11 08:13:44 2000
+++ /usr/src/misc/apache_1.3.12-2/src/modules/proxy/mod_proxy.h	Mon Nov 27 21:06:44 2000
@@ -224,6 +224,8 @@
     char viaopt_set;
     size_t recv_buffer_size;
     char recv_buffer_size_set;
+    int add_headers;            /* true if we will add minimal HTTP headers when none are provided */
+    char add_headers_set;
 } proxy_server_conf;

 struct hdr_entry {
diff -u proxy/proxy_http.c /usr/src/misc/apache_1.3.12-2/src/modules/proxy/proxy_http.c
--- proxy/proxy_http.c	Tue Jan 11 08:13:45 2000
+++ /usr/src/misc/apache_1.3.12-2/src/modules/proxy/proxy_http.c	Mon Nov 27 22:28:05 2000
@@ -439,11 +439,13 @@

 	clear_connection(p, resp_hdrs);	/* Strip Connection hdrs */
     }
-    else {
+    else  {
 /* an http/0.9 response */
 	backasswards = 1;
-	r->status = 200;
-	r->status_line = "200 OK";
+	if (conf->add_headers) {
+	    r->status = 200;
+	    r->status_line = "200 OK";
+	}

 /* no headers */
 	resp_hdrs = ap_make_table(p, 20);
@@ -485,7 +487,7 @@
     ap_hard_timeout("proxy receive", r);

 /* write status line */
-    if (!r->assbackwards)
+    if (!r->assbackwards && (!backasswards || (backasswards && conf->add_headers)))
 	ap_rvputs(r, "HTTP/1.0 ", r->status_line, CRLF, NULL);
     if (c != NULL && c->fp != NULL &&
 	ap_bvputs(c->fp, "HTTP/1.0 ", r->status_line, CRLF, NULL) == -1) {
@@ -499,7 +501,7 @@
     tdo.cache = c;
     ap_table_do(ap_proxy_send_hdr_line, &tdo, resp_hdrs, NULL);

-    if (!r->assbackwards)
+    if (!r->assbackwards && (!backasswards || (backasswards && conf->add_headers)))
 	ap_rputs(CRLF, r);
     if (c != NULL && c->fp != NULL && ap_bputs(CRLF, c->fp) == -1) {
 	ap_log_rerror(APLOG_MARK, APLOG_ERR, c->req,