Project

General

Profile

mod_proxy.diff

lighty-14x-mod_proxy-rr-fix-sendfile-addition -- gzfelix - Anonymous, 2006-12-29 08:40

View differences:

src/mod_proxy.c (working copy)
22 22
#include "plugin.h"
23 23

  
24 24
#include "inet_ntop_cache.h"
25
#include "stat_cache.h"
25 26
#include "crc32.h"
26 27

  
27 28
#include <stdio.h>
......
66 67
	int debug;
67 68

  
68 69
	proxy_balance_t balance;
70
        unsigned short allow_xsendfile;
69 71
} plugin_config;
70 72

  
71 73
typedef struct {
......
106 108

  
107 109
	size_t path_info_offset; /* start of path_info in uri.path */
108 110

  
111
        int send_content_body;
112

  
109 113
	connection *remote_conn;  /* dump pointer */
110 114
	plugin_data *plugin_data; /* dump pointer */
111 115
} handler_ctx;
......
117 121
static handler_ctx * handler_ctx_init() {
118 122
	handler_ctx * hctx;
119 123

  
120

  
121 124
	hctx = calloc(1, sizeof(*hctx));
122 125

  
123 126
	hctx->state = PROXY_STATE_INIT;
......
131 134
	hctx->fd = -1;
132 135
	hctx->fde_ndx = -1;
133 136

  
137
        hctx->send_content_body = 1;
138

  
134 139
	return hctx;
135 140
}
136 141

  
......
191 196
		{ "proxy.server",              NULL, T_CONFIG_LOCAL, T_CONFIG_SCOPE_CONNECTION },       /* 0 */
192 197
		{ "proxy.debug",               NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },       /* 1 */
193 198
		{ "proxy.balance",             NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },      /* 2 */
199
                { "proxy.allow-x-send-file",   NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },     /* 3 */
194 200
		{ NULL,                        NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
195 201
	};
196 202

  
......
203 209
		s = malloc(sizeof(plugin_config));
204 210
		s->extensions    = array_init();
205 211
		s->debug         = 0;
212
                s->allow_xsendfile = 0;
206 213

  
207 214
		cv[0].destination = s->extensions;
208 215
		cv[1].destination = &(s->debug);
209 216
		cv[2].destination = p->balance_buf;
217
                cv[3].destination = &(s->allow_xsendfile);
210 218

  
211 219
		buffer_reset(p->balance_buf);
212 220

  
......
291 299
					df = data_proxy_init();
292 300

  
293 301
					df->port = 80;
302
                                        df->last_used_ndx = -1;
294 303

  
295 304
					buffer_copy_string_buffer(df->key, da_host->key);
296 305

  
......
680 689

  
681 690
		if (0 == con->file_started) {
682 691
			char *c;
692
                        data_string *ds;
683 693

  
684 694
			/* search for the \r\n\r\n in the string */
685 695
			if (NULL != (c = buffer_search_string_len(hctx->response, "\r\n\r\n", 4))) {
......
701 711
				}
702 712

  
703 713
				con->file_started = 1;
704
				if (blen) {
714

  
715
                                /* delegate to X-Sendfile if the header is available */
716
                                if (p->conf.allow_xsendfile &&
717
                                    (NULL != (ds = (data_string *) array_get_element(con->response.headers, "X-LIGHTTPD-send-file")) || NULL != (ds = (data_string *) array_get_element(con->response.headers, "X-Sendfile")))) {
718
                                  stat_cache_entry *sce;
719

  
720
                                  if (HANDLER_ERROR != stat_cache_get_entry(srv, con, ds->value, &sce)) {
721
                                    /* found */
722
                                    http_chunk_append_file(srv, con, ds->value, 0, sce->st.st_size);
723
                                    hctx->send_content_body = 0; /* ignore the content */
724
                                    joblist_append(srv, con);
725
                                  }
726
                                }
727

  
728
				if (hctx->send_content_body && blen) {
705 729
					http_chunk_append_mem(srv, con, c + 4, blen + 1);
706 730
					joblist_append(srv, con);
707 731
				}
708 732
				hctx->response->used = 0;
709 733
			}
710
		} else {
734
		} else if (hctx->send_content_body) {
711 735
			http_chunk_append_mem(srv, con, hctx->response->ptr, hctx->response->used);
712 736
			joblist_append(srv, con);
713 737
			hctx->response->used = 0;
......
863 887
	PATCH(extensions);
864 888
	PATCH(debug);
865 889
	PATCH(balance);
890
        PATCH(allow_xsendfile);
866 891

  
867 892
	/* skip the first, the global context */
868 893
	for (i = 1; i < srv->config_context->used; i++) {
......
882 907
				PATCH(debug);
883 908
			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("proxy.balance"))) {
884 909
				PATCH(balance);
910
			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("proxy.allow-x-send-file"))) {
911
                                PATCH(allow_xsendfile);
885 912
			}
886 913
		}
887 914
	}
......
1201 1228
			}
1202 1229
		}
1203 1230

  
1204
		/* didn't found a higher id, wrap to the start */
1205
		if (ndx != -1 && max_usage != INT_MAX) {
1231
                /* didn't found a higher id, wrap to the start and clear remaining last_used_ndx bits */
1232
                if (ndx == -1 && max_usage != INT_MAX) {
1233
                  data_proxy *host = (data_proxy *)extension->value->data[max_usage];
1206 1234
			ndx = max_usage;
1235
                  host->last_used_ndx = ndx;
1236

  
1237
                  for(k = ndx+1; k < extension->value->used; k++) {
1238
                    host = (data_proxy *)extension->value->data[k];
1239
                    host->last_used_ndx = -1;
1207 1240
		}
1208 1241

  
1242
                }
1243

  
1209 1244
		break;
1210 1245
	default:
1211 1246
		break;