Patch for: http://trac.lighttpd.net/trac/ticket/1545 Allows the headers to be used by mod_extforward to be specified in config. For example for use with a Zeus ZXTM loadbalancer: extforward.headers = ("X-Cluster-Client-Ip") --- lighttpd-1.4.19/src/mod_extforward.c.extforward 2008-03-02 13:59:18.000000000 +0100 +++ lighttpd-1.4.19/src/mod_extforward.c 2008-03-12 15:18:28.000000000 +0100 @@ -80,6 +80,7 @@ typedef struct { array *forwarder; + array *headers; } plugin_config; typedef struct { @@ -135,6 +136,7 @@ if (!s) continue; array_free(s->forwarder); + array_free(s->headers); free(s); } @@ -154,7 +156,8 @@ size_t i = 0; config_values_t cv[] = { - { "extforward.forwarder", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 0 */ + { "extforward.forwarder", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 0 */ + { "extforward.headers", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 1 */ { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } }; @@ -167,8 +170,10 @@ s = calloc(1, sizeof(plugin_config)); s->forwarder = array_init(); + s->headers = array_init(); cv[0].destination = s->forwarder; + cv[1].destination = s->headers; p->config_storage[i] = s; @@ -187,6 +192,7 @@ plugin_config *s = p->config_storage[0]; PATCH(forwarder); + PATCH(headers); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { @@ -202,6 +208,8 @@ if (buffer_is_equal_string(du->key, CONST_STR_LEN("extforward.forwarder"))) { PATCH(forwarder); + } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("extforward.headers"))) { + PATCH(headers); } } } @@ -335,6 +343,8 @@ URIHANDLER_FUNC(mod_extforward_uri_handler) { plugin_data *p = p_d; data_string *forwarded = NULL; + data_string *ds; + size_t k; #ifdef HAVE_IPV6 char b2[INET6_ADDRSTRLEN + 1]; struct addrinfo *addrlist = NULL; @@ -354,15 +364,22 @@ "-- mod_extforward_uri_handler called"); } - if ((NULL == (forwarded = (data_string *) array_get_element(con->request.headers,"X-Forwarded-For")) && - NULL == (forwarded = (data_string *) array_get_element(con->request.headers, "Forwarded-For")))) { + for(k=0; kconf.headers->used; k++) { + ds = (data_string *)p->conf.headers->data[k]; + if (NULL != (forwarded = (data_string*)array_get_element(con->request.headers, ds->value->ptr))) break; + } - if (con->conf.log_request_handling) { - log_error_write(srv, __FILE__, __LINE__, "s", - "no X-Forwarded-For|Forwarded-For: found, skipping"); - } + if(NULL == forwarded) { + if ((NULL == (forwarded = (data_string *) array_get_element(con->request.headers,"X-Forwarded-For")) && + NULL == (forwarded = (data_string *) array_get_element(con->request.headers, "Forwarded-For"))) || + (p->conf.headers->used > 0)) { - return HANDLER_GO_ON; + if (con->conf.log_request_handling) { + log_error_write(srv, __FILE__, __LINE__, "s", "no forward header found, skipping"); + } + + return HANDLER_GO_ON; + } } #ifdef HAVE_IPV6