Re: using a 3-tier mod_perl setup
On Sun, 16 Jul 2000, Gunther Birznieks wrote: > Is any of this header rewriting already on Ralf's TODO list for mod_rewrite? > > Does it make sense to make mod_headers more complex? Or to add these > features to mod_rewrite already? > > Just throwing the idea out there. > > This is an interesting module though. > I considered adding the ProxyHeaderRewrite and HeaderRewrite commands to mod_rewrite, but I felt more comfortable mucking around in the much simpler mod_headers. I'm not happy that I had to duplicate some code from mod_rewrite, tho. I did not find any TODO lists for mod_rewrite. BTW, I have attached a newer patch for mod_headers, which fixes a bug of mine with ProxyHeaderRewrite unset. (apply to a stock 1.3.12 mod_headers) I'm glad you find it interesting - this is my first public module contribution. -Tim - (from my original post) The attached patch (cd apache_1.3.XX; patch -p1 < ProxyHeaderRewrite.p2.patch; make install) will add two commands to mod_headers: HeaderRewrite - dynamically set headers for the client ProxyHeaderRewrite - dynamically set headers for the upstream proxy server While the original mod_headers would allow you so say: Header append Foo "burfl" Now you can say HeaderRewrite append Foo "%{ENV:BURFL}", using the full RewriteCond syntax My current lightweight apache server config looks something like: ProxyHeaderRewrite append X-Forwarded-For "%{REMOTE_ADDR}" ProxyHeaderRewrite append X-Frontend-Host "%{HTTP_HOST}" ... SSLOptions StdEnvVars ProxyHeaderRewrite append X-SSL-Cipher "%{ENV:SSL_PROTOCOL} %{ENV:SSL_CIPHER}" --- apache_1.3.12.dist/src/modules/standard/mod_headers.c Wed Oct 27 02:26:53 1999 +++ apache_1.3.12/src/modules/standard/mod_headers.cThu Jul 13 16:53:11 2000 @@ -99,9 +99,52 @@ * To remove a header: * Header unset Author * + * + * Non-standard Additions: + * + *Most code is from mod_rewrite, by + * Ralf S. Engelschall + * [EMAIL PROTECTED] + *Assembled by Tim Bishop <[EMAIL PROTECTED]> + * + * + * HeaderRewrite (set headers to client using RewriteCond syntax) + * + * Syntax: HeaderRewrite action header rewriteValue + * + * This works the same as the header directive, except that full + * mod_rewrite RewriteCond interpolation is performed on the rewriteValue + * string. See http://www.apache.org/docs/mod/mod_rewrite.html#RewriteCond + * (Of course, back-references (%N, $N) have no meaning) + * + * + * ProxyHeaderRewrite (set headers sent to upstream servers (if proxying)) + * + * Syntax: ProxyHeaderRewrite action header rewriteValue + * + * ProxyHeaderRewrite allows you to rewrite headers sent to upstream + * servers when your server is functioning as a proxy server. + * This is useful when you want to send additional header information + * to upstream servers. + * + * Bugs: Cannot rewrite the Host header with ProxyHeaderRewrite + * + * Examples: + * + *# tell upstream server the ip of the request + *ProxyHeaderRewrite append X-Forwarded-For "%{REMOTE_ADDR}" + *# tell upstream server info on SSL status + * + *SSLOptions StdEnvVars + *ProxyHeaderRewrite append X-SSL-Cipher "%{ENV:SSL_PROTOCOL} +%{ENV:SSL_CIPHER}" + * + *# tell upstream server the virtual host used + *ProxyHeaderRewrite append X-Frontend-Host "%{HTTP:Host}" + * */ #include "httpd.h" +#include "http_log.h" #include "http_config.h" typedef enum { @@ -111,12 +154,50 @@ hdr_unset = 'u' /* unset header */ } hdr_actions; +typedef enum { + hdr_string = 's', /* header is a string */ + hdr_env_var = 'v', /* set header from env var */ + hdr_interpolate = 'i' /* header needs to be interpolated (not yet!) */ +} hdr_value_type; + +typedef enum { + hdr_client = 'c', /* modify headers for client */ + hdr_upstream = 'u'/* modify headers for upstream server */ +} hdr_header_target; + typedef struct { -hdr_actions action; -char *header; -char *value; + hdr_actions action; + char *header; + char *value; + hdr_value_type value_type; + hdr_header_target header_target; /* one of hdr_client | hdr_upstream */ } header_entry; + +/* env variable interpolation support */ +static void expand_variables_inbuffer(request_rec *r, char *buf, int buf_len); +static char *expand_variables(request_rec *r, char *str); +static char *lookup_variable(request_rec *r, char *var); +static char *lookup_header(request_rec *r, const char *name); + +#ifndef LONG_STRING_LEN +#define LONG_STRING_LEN 2048 +#endif + +/* REMOTE_NAME returns the hostname, or the dotted quad if the + * hostname lookup fails. It will force a DNS lookup according + * to the HostnameLookups setting. + * from httd_core.h + */ +#define REMOTE_N
Re: using a 3-tier mod_perl setup
Is any of this header rewriting already on Ralf's TODO list for mod_rewrite? Does it make sense to make mod_headers more complex? Or to add these features to mod_rewrite already? Just throwing the idea out there. This is an interesting module though. At 09:56 AM 7/11/00 -0700, Tim Bishop wrote: >I am running a 3-tier mod_perl setup as advised by the Guide: > > Lightweight apache <-> mod_perl apache <-> db server. > >One of the problems with this setup is that the mod_perl apache no longer >knows some details about the client request, like the client IP. > >I used Ask Bjoern Hansen's module proxy_add_forward, which adds a >"X-Forwarded-For" header to to the request as it is forwarded to the >mod_perl apache server. > >After I added SSL to my lightweight (but gaining!) apache, I found >I needed some SSL connection information on the mod_perl server as well. > >I recently fell in love with mod_rewrite, and so I ported some of its >capabilities to mod_headers > >The attached patch > (cd apache_1.3.XX; patch -p1 < ProxyHeaderRewrite.patch; make install) >will add two commands to mod_headers: > >HeaderRewrite - dynamically set headers for the client >ProxyHeaderRewrite - dynamically set headers for the upstream proxy > server > >While the original mod_headers would allow you so say: > >Header append Foo "burfl" > >Now you can say > >HeaderRewrite append Foo "%{ENV:BURFL}", using the full RewriteCond syntax > > > >My current lightweight apache server config looks something like: > >ProxyHeaderRewrite append X-Forwarded-For "%{REMOTE_ADDR}" >ProxyHeaderRewrite append X-Frontend-Host "%{HTTP_HOST}" > >... >SSLOptions StdEnvVars >ProxyHeaderRewrite append X-SSL-Cipher "%{ENV:SSL_PROTOCOL} > %{ENV:SSL_CIPHER}" > > > >Did I miss another way to do this? Is this patch useful? > > >BTW, > >the Guide on server architecture: >http://perl.apache.org/guide/strategy.html > >Ask Bjoern Hansen's module proxy_add_forward >http://www.cpan.org/authors/id/ABH/mod_proxy_add_forward.c > > >-Tim __ Gunther Birznieks ([EMAIL PROTECTED]) eXtropia - The Web Technology Company http://www.extropia.com/
using a 3-tier mod_perl setup
I am running a 3-tier mod_perl setup as advised by the Guide: Lightweight apache <-> mod_perl apache <-> db server. One of the problems with this setup is that the mod_perl apache no longer knows some details about the client request, like the client IP. I used Ask Bjoern Hansen's module proxy_add_forward, which adds a "X-Forwarded-For" header to to the request as it is forwarded to the mod_perl apache server. After I added SSL to my lightweight (but gaining!) apache, I found I needed some SSL connection information on the mod_perl server as well. I recently fell in love with mod_rewrite, and so I ported some of its capabilities to mod_headers The attached patch (cd apache_1.3.XX; patch -p1 < ProxyHeaderRewrite.patch; make install) will add two commands to mod_headers: HeaderRewrite - dynamically set headers for the client ProxyHeaderRewrite - dynamically set headers for the upstream proxy server While the original mod_headers would allow you so say: Header append Foo "burfl" Now you can say HeaderRewrite append Foo "%{ENV:BURFL}", using the full RewriteCond syntax My current lightweight apache server config looks something like: ProxyHeaderRewrite append X-Forwarded-For "%{REMOTE_ADDR}" ProxyHeaderRewrite append X-Frontend-Host "%{HTTP_HOST}" ... SSLOptions StdEnvVars ProxyHeaderRewrite append X-SSL-Cipher "%{ENV:SSL_PROTOCOL} %{ENV:SSL_CIPHER}" Did I miss another way to do this? Is this patch useful? BTW, the Guide on server architecture: http://perl.apache.org/guide/strategy.html Ask Bjoern Hansen's module proxy_add_forward http://www.cpan.org/authors/id/ABH/mod_proxy_add_forward.c -Tim --- apache_1.3.12.dist/src/modules/standard/mod_headers.c Wed Oct 27 09:26:53 1999 +++ apache_1.3.12/src/modules/standard/mod_headers.cTue Jul 11 00:38:26 2000 @@ -99,9 +99,52 @@ * To remove a header: * Header unset Author * + * + * Non-standard Additions: + * + *Most code is from mod_rewrite, by + * Ralf S. Engelschall + * [EMAIL PROTECTED] + *Assembled by Tim Bishop <[EMAIL PROTECTED]> + * + * + * HeaderRewrite (set headers to client using RewriteCond syntax) + * + * Syntax: HeaderRewrite action header rewriteValue + * + * This works the same as the header directive, except that full + * mod_rewrite RewriteCond interpolation is performed on the rewriteValue + * string. See http://www.apache.org/docs/mod/mod_rewrite.html#RewriteCond + * (Of course, back-references (%N, $N) have no meaning) + * + * + * ProxyHeaderRewrite (set headers sent to upstream servers (if proxying)) + * + * Syntax: ProxyHeaderRewrite action header rewriteValue + * + * ProxyHeaderRewrite allows you to rewrite headers sent to upstream + * servers when your server is functioning as a proxy server. + * This is useful when you want to send additional header information + * to upstream servers. + * + * Bugs: Cannot rewrite the Host header with ProxyHeaderRewrite + * + * Examples: + * + *# tell upstream server the ip of the request + *ProxyHeaderRewrite append X-Forwarded-For "%{REMOTE_ADDR}" + *# tell upstream server info on SSL status + * + *SSLOptions StdEnvVars + *ProxyHeaderRewrite append X-SSL-Cipher "%{ENV:SSL_PROTOCOL} +%{ENV:SSL_CIPHER}" + * + *# tell upstream server the virtual host used + *ProxyHeaderRewrite append X-Frontend-Host "%{HTTP:Host}" + * */ #include "httpd.h" +#include "http_log.h" #include "http_config.h" typedef enum { @@ -111,12 +154,50 @@ hdr_unset = 'u' /* unset header */ } hdr_actions; +typedef enum { + hdr_string = 's', /* header is a string */ + hdr_env_var = 'v', /* set header from env var */ + hdr_interpolate = 'i' /* header needs to be interpolated (not yet!) */ +} hdr_value_type; + +typedef enum { + hdr_client = 'c', /* modify headers for client */ + hdr_upstream = 'u'/* modify headers for upstream server */ +} hdr_header_target; + typedef struct { -hdr_actions action; -char *header; -char *value; + hdr_actions action; + char *header; + char *value; + hdr_value_type value_type; + hdr_header_target header_target; /* one of hdr_client | hdr_upstream */ } header_entry; + +/* env variable interpolation support */ +static void expand_variables_inbuffer(request_rec *r, char *buf, int buf_len); +static char *expand_variables(request_rec *r, char *str); +static char *lookup_variable(request_rec *r, char *var); +static char *lookup_header(request_rec *r, const char *name); + +#ifndef LONG_STRING_LEN +#define LONG_STRING_LEN 2048 +#endif + +/* REMOTE_NAME returns the hostname, or the dotted quad if the + * hostname lookup fails. It will force a DNS lookup according + * to the HostnameLookups setting. + * from httd_core.h + */ +#define REM