]> git.pld-linux.org Git - packages/lighttpd.git/blob - lighttpd-proxy-fix-redirects.patch
- add lost configtest to reload target
[packages/lighttpd.git] / lighttpd-proxy-fix-redirects.patch
1 diff -ur lighttpd-1.4.8-o/doc/proxy.txt lighttpd-1.4.8/doc/proxy.txt
2 --- lighttpd-1.4.8-o/doc/proxy.txt      2005-08-10 16:26:16.000000000 -0600
3 +++ lighttpd-1.4.8/doc/proxy.txt        2006-01-10 01:55:04.000000000 -0700
4 @@ -67,6 +67,8 @@
5    :"host":      is ip of the proxy server
6    :"port":      is tcp-port on the "host" used by the proxy
7                  server (default: 80)
8 +  :"fix-redirects":  rewrite redirects from proxied servers to reflect this
9 +                                                                                server's hostname and port
10  
11    e.g.: ::
12    
13 diff -ur lighttpd-1.4.8-o/src/array.h lighttpd-1.4.8/src/array.h
14 --- lighttpd-1.4.8-o/src/array.h        2005-09-23 12:24:18.000000000 -0600
15 +++ lighttpd-1.4.8/src/array.h  2006-01-10 00:38:55.000000000 -0700
16 @@ -129,6 +129,7 @@
17                 
18         int usage; /* fair-balancing needs the no. of connections active on this host */
19         int last_used_ndx; /* round robin */
20 +       short fix_redirects;    
21  } data_fastcgi;
22  
23  data_fastcgi *data_fastcgi_init(void);
24 diff -ur lighttpd-1.4.8-o/src/data_fastcgi.c lighttpd-1.4.8/src/data_fastcgi.c
25 --- lighttpd-1.4.8-o/src/data_fastcgi.c 2005-08-23 08:36:12.000000000 -0600
26 +++ lighttpd-1.4.8/src/data_fastcgi.c   2006-01-10 00:38:55.000000000 -0700
27 @@ -57,6 +57,7 @@
28         ds->host = buffer_init();
29         ds->port = 0;
30         ds->is_disabled = 0;
31 +       ds->fix_redirects = 0;
32         
33         ds->copy = data_fastcgi_copy;
34         ds->free = data_fastcgi_free;
35 diff -ur lighttpd-1.4.8-o/src/mod_proxy.c lighttpd-1.4.8/src/mod_proxy.c
36 --- lighttpd-1.4.8-o/src/mod_proxy.c    2005-11-18 05:29:36.000000000 -0700
37 +++ lighttpd-1.4.8/src/mod_proxy.c      2006-01-10 00:58:18.000000000 -0700
38 @@ -277,6 +277,7 @@
39                                                 { "host",              NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },      /* 0 */
40                                                 { "port",              NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },       /* 1 */
41                                                 { "balance",              NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },   /* 2 */
42 +                                               { "fix-redirects",     NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },       /* 3 */
43                                                 { NULL,                NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
44                                         };
45                                         
46 @@ -297,6 +298,7 @@
47                                         
48                                         pcv[0].destination = df->host;
49                                         pcv[1].destination = &(df->port);
50 +                                       pcv[3].destination = &(df->fix_redirects);
51                                         
52                                         if (0 != config_insert_values_internal(srv, da_host->value, pcv)) {
53                                                 return HANDLER_ERROR;
54 @@ -527,7 +529,7 @@
55  }
56  
57  
58 -static int proxy_response_parse(server *srv, connection *con, plugin_data *p, buffer *in) {
59 +static int proxy_response_parse(server *srv, connection *con, plugin_data *p, buffer *in, handler_ctx *hctx) {
60         char *s, *ns;
61         int http_response_status = -1;
62         
63 @@ -586,7 +588,17 @@
64                         break;
65                 case 8:
66                         if (0 == strncasecmp(key, "Location", key_len)) {
67 +                               buffer *host;
68                                 con->parsed_response |= HTTP_LOCATION;
69 +
70 +                               host = buffer_init();
71 +                               buffer_copy_string_len(host, con->request.http_host, strchr(con->request.http_host->ptr, ':') - con->request.http_host->ptr);
72 +
73 +                               if(hctx->host->fix_redirects && strncmp(value, "http://", 7) == 0 && strncasecmp(value + 7, host->ptr, host->used) == 0 && *(value + 7 + host->used) == ':' && atoi(value + 7 + host->used + 1) == hctx->host->port) {
74 +                                       value = strchr(value + 7 + host->used, '/');
75 +                               }
76 +
77 +                               buffer_free(host);
78                         }
79                         break;
80                 case 10:
81 @@ -688,7 +700,7 @@
82                                 log_error_write(srv, __FILE__, __LINE__, "sb", "Header:", hctx->response_header);
83  #endif
84                                 /* parse the response header */
85 -                               proxy_response_parse(srv, con, p, hctx->response_header);
86 +                               proxy_response_parse(srv, con, p, hctx->response_header, hctx);
87                                         
88                                 /* enable chunked-transfer-encoding */
89                                 if (con->request.http_version == HTTP_VERSION_1_1 &&
This page took 0.029855 seconds and 3 git commands to generate.