You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Ralf S. Engelschall" <rs...@engelschall.com> on 1998/03/12 15:49:45 UTC

[PATCH] Unbundling mod_proxy and mod_mime

Unbundle mod_proxy and mod_mime
-------------------------------

The following patch successfully unbundles the proxy module and the mime
module. This is especially essential to be able to compile these two modules
as shared objects. Because in the past you have to compile mod_mime statically
because of this cross-module function call. On the other hand compiling in
mod_proxy implied compiling in of mod_mime. This especially was ugly for the
situation where Apache was used as a Reverse Proxy, because there you only
need mod_proxy (and only for HTTP) and mod_rewrite.  But you were forced to
compile mod_mime into the binary, too.  This restriction is now obsolete, too.
(Because mime_find_ct() was only needed for FTP which is not needed in a
reverse proxy ;_)

BTW: Instead of performing a complete sub-request we could just
     use find_types() but that's a little bit too low-level I think.  Using a
     sub-request call is more API conforming...

                                       Ralf S. Engelschall
                                       rse@engelschall.com
                                       www.engelschall.com

Index: CHANGES
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/CHANGES,v
retrieving revision 1.701
diff -u -r1.701 CHANGES
--- CHANGES	1998/03/12 10:28:52	1.701
+++ CHANGES	1998/03/12 14:43:36
@@ -1,5 +1,12 @@
 Changes with Apache 1.3b6
 
+  *) Replaced the hard-coded cross-module function call mime_find_ct() (from
+     mod_proxy to mod_mime) by an equivalent (and only slightly slower) API
+     sub-request call. This cleans up mod_mime by removing the ugly export
+     kludge, makes the one-liner file mod_mime.h obsolete, and especially
+     unbundles mod_proxy and mod_mime. This way they both now can be compiled
+     as shared objects and are no longer tied together. [Ralf S. Engelschall]
+
   *) API: Clarify usage of content_type, handler, content_encoding,
      content_language and content_languages fields in request_rec.  They
      must always be lowercased; and the strings pointed to shouldn't
Index: modules/proxy/proxy_ftp.c
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/modules/proxy/proxy_ftp.c,v
retrieving revision 1.49
diff -u -r1.49 proxy_ftp.c
--- proxy_ftp.c	1998/02/22 21:35:31	1.49
+++ proxy_ftp.c	1998/03/12 14:34:11
@@ -55,6 +55,7 @@
 
 #include "mod_proxy.h"
 #include "http_main.h"
+#include "http_request.h"
 #include "../standard/mod_mime.h"
 
 DEF_Explain
@@ -426,6 +427,7 @@
     int one = 1;
     const long int zero = 0L;
     NET_SIZE_T clen;
+    request_rec *rsub;
 
     void *sconf = r->server->module_config;
     proxy_server_conf *conf =
@@ -929,15 +931,17 @@
     if (parms[0] == 'd')
 	proxy_add_header(resp_hdrs, "Content-Type", "text/html", HDR_REP);
     else {
-	mime_find_ct(r);
-	if (r->content_type != NULL) {
-	    proxy_add_header(resp_hdrs, "Content-Type", r->content_type,
-			     HDR_REP);
-	    Explain1("FTP: Content-Type set to %s", r->content_type);
-	}
-	else {
-	    proxy_add_header(resp_hdrs, "Content-Type", "text/plain", HDR_REP);
-	}
+        /* perform a subrequest to find out the corresponding MIME type */
+        rsub = sub_req_lookup_file(r->filename, r);
+        if (rsub->content_type != NULL) {
+            proxy_add_header(resp_hdrs, "Content-Type", 
+                     rsub->content_type, HDR_REP);
+            Explain1("FTP: Content-Type set to %s", rsub->content_type);
+        }
+        else {
+            proxy_add_header(resp_hdrs, "Content-Type", "text/plain", HDR_REP);
+        }
+        destroy_sub_req(rsub);
     }
 
 /* check if NoCache directive on this host */
Index: modules/standard/mod_mime.c
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/modules/standard/mod_mime.c,v
retrieving revision 1.34
diff -u -r1.34 mod_mime.c
--- mod_mime.c	1998/03/12 13:37:51	1.34
+++ mod_mime.c	1998/03/12 14:36:00
@@ -237,7 +237,6 @@
     cfg_closefile(f);
 }
 
-/* note that the proxy module uses this via mime_find_ct */
 static int find_ct(request_rec *r)
 {
     const char *fn = strrchr(r->filename, '/');
@@ -323,11 +322,6 @@
         return DECLINED;
 
     return OK;
-}
-
-API_EXPORT(int) mime_find_ct(request_rec *r)
-{
-    return find_ct(r);
 }
 
 module MODULE_VAR_EXPORT mime_module =

Re: [PATCH] Unbundling mod_proxy and mod_mime

Posted by Dean Gaudet <dg...@arctic.org>.
Shouldn't you stuff "proxy:" or something in front of the filename?  Or is
it already there 'cause r->filename is the proxy subreq?

Why isn't there a content_type to begin with?  I mean, you're already in
the middle of a request for r->filename, and if it works as a
subrequest... why isn't r->content_type set? 

Dean