You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by pq...@apache.org on 2009/03/28 00:56:53 UTC
svn commit: r759395 - /httpd/httpd/trunk/modules/proxy/mod_serf.c
Author: pquerna
Date: Fri Mar 27 23:56:53 2009
New Revision: 759395
URL: http://svn.apache.org/viewvc?rev=759395&view=rev
Log:
Add support for Preserving the client provided Host header.
* modules/proxy/mod_serf.c
(serf_config_t): Add preservehost member.
(setup_request): If preservehost is set, use the client provided Host header,
otherwise use the one from the configuration.
(is_true): New helper function for decoding true/false strings.
(add_pass): Change to an argv configuration function, check for not enough
args, and parse everything after the URI into key/value pairs.
(create_dir_config): Default to setting preservehost to on.
(serf_cmds): Change add_pass to a take argv directive.
Modified:
httpd/httpd/trunk/modules/proxy/mod_serf.c
Modified: httpd/httpd/trunk/modules/proxy/mod_serf.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_serf.c?rev=759395&r1=759394&r2=759395&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/mod_serf.c (original)
+++ httpd/httpd/trunk/modules/proxy/mod_serf.c Fri Mar 27 23:56:53 2009
@@ -31,6 +31,7 @@
typedef struct {
int on;
+ int preservehost;
apr_uri_t url;
} serf_config_t;
@@ -290,8 +291,13 @@
apr_table_do(copy_headers_in, hdrs_bkt, ctx->r->headers_in, NULL);
- /* XXXXXX: SerfPreserveHost on */
- serf_bucket_headers_setn(hdrs_bkt, "Host", ctx->conf->url.hostname);
+ if (ctx->conf->preservehost) {
+ serf_bucket_headers_setn(hdrs_bkt, "Host",
+ apr_table_get(ctx->r->headers_in, "Host"));
+ }
+ else {
+ serf_bucket_headers_setn(hdrs_bkt, "Host", ctx->conf->url.hostname);
+ }
serf_bucket_headers_setn(hdrs_bkt, "Accept-Encoding", "gzip");
@@ -460,13 +466,29 @@
return drive_serf(r, conf);
}
+static int is_true(const char *w)
+{
+ if (strcasecmp(w, "on") == 0 ||
+ strcasecmp(w, "1") == 0 ||
+ strcasecmp(w, "true") == 0)
+ {
+ return 1;
+ }
+
+ return 0;
+}
static const char *add_pass(cmd_parms *cmd, void *vconf,
- const char *vdest)
+ int argc, char *const argv[])
{
+ int i;
apr_status_t rv;
serf_config_t *conf = (serf_config_t *) vconf;
- rv = apr_uri_parse(cmd->pool, vdest, &conf->url);
+ if (argc < 1) {
+ return "SerfPass must have at least a URI.";
+ }
+
+ rv = apr_uri_parse(cmd->pool, argv[0], &conf->url);
if (rv != APR_SUCCESS) {
return "mod_serf: Unable to parse SerfPass url.";
@@ -481,8 +503,20 @@
conf->url.path = "/";
}
- conf->on = 1;
+ for (i = 1; i < argc; i++) {
+ const char *p = argv[i];
+ const char *x = ap_strchr(p, '=');
+
+ if (x) {
+ char *key = apr_pstrndup(cmd->pool, p, x-p);
+ if (strcmp(key, "preservehost") == 0) {
+ conf->preservehost = is_true(x+1);
+ }
+ }
+ }
+ conf->on = 1;
+
return NULL;
}
@@ -558,6 +592,7 @@
{
serf_config_t *new = (serf_config_t *) apr_pcalloc(p, sizeof(serf_config_t));
new->on = 0;
+ new->preservehost = 1;
return new;
}
@@ -585,8 +620,8 @@
{
AP_INIT_TAKE_ARGV("SerfCluster", add_cluster, NULL, RSRC_CONF,
"Configure a cluster backend"),
- AP_INIT_TAKE1("SerfPass", add_pass, NULL, OR_INDEXES,
- "URL to reverse proxy to"),
+ AP_INIT_TAKE_ARGV("SerfPass", add_pass, NULL, OR_INDEXES,
+ "URL to reverse proxy to"),
{NULL}
};