comparison src/http/modules/ngx_http_proxy_module.c @ 110:dad2fe8ecf08 NGINX_0_3_2

nginx 0.3.2 *) Feature: the Sun Studio 10 C compiler support. *) Feature: the "proxy_upstream_max_fails", "proxy_upstream_fail_timeout", "fastcgi_upstream_max_fails", and "fastcgi_upstream_fail_timeout" directives.
author Igor Sysoev <http://sysoev.ru>
date Wed, 12 Oct 2005 00:00:00 +0400
parents 146eff53ab60
children d25a1d6034f1
comparison
equal deleted inserted replaced
109:97da525033a1 110:dad2fe8ecf08
44 ngx_array_t *headers_source; 44 ngx_array_t *headers_source;
45 ngx_array_t *headers_names; 45 ngx_array_t *headers_names;
46 46
47 ngx_array_t *redirects; 47 ngx_array_t *redirects;
48 48
49 ngx_str_t method;
49 ngx_str_t host_header; 50 ngx_str_t host_header;
50 ngx_str_t port_text; 51 ngx_str_t port_text;
51 52
52 ngx_flag_t redirect; 53 ngx_flag_t redirect;
53 } ngx_http_proxy_loc_conf_t; 54 } ngx_http_proxy_loc_conf_t;
98 99
99 100
100 static ngx_conf_post_t ngx_http_proxy_lowat_post = 101 static ngx_conf_post_t ngx_http_proxy_lowat_post =
101 { ngx_http_proxy_lowat_check }; 102 { ngx_http_proxy_lowat_check };
102 103
103 static ngx_conf_enum_t ngx_http_proxy_set_methods[] = {
104 { ngx_string("get"), NGX_HTTP_GET },
105 { ngx_null_string, 0 }
106 };
107 104
108 static ngx_conf_bitmask_t ngx_http_proxy_next_upstream_masks[] = { 105 static ngx_conf_bitmask_t ngx_http_proxy_next_upstream_masks[] = {
109 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR }, 106 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR },
110 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT }, 107 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT },
111 { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER }, 108 { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER },
166 offsetof(ngx_http_proxy_loc_conf_t, headers_source), 163 offsetof(ngx_http_proxy_loc_conf_t, headers_source),
167 NULL }, 164 NULL },
168 165
169 { ngx_string("proxy_method"), 166 { ngx_string("proxy_method"),
170 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 167 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
171 ngx_conf_set_enum_slot, 168 ngx_conf_set_str_slot,
172 NGX_HTTP_LOC_CONF_OFFSET, 169 NGX_HTTP_LOC_CONF_OFFSET,
173 offsetof(ngx_http_proxy_loc_conf_t, upstream.method), 170 offsetof(ngx_http_proxy_loc_conf_t, method),
174 ngx_http_proxy_set_methods }, 171 NULL },
175 172
176 { ngx_string("proxy_pass_request_headers"), 173 { ngx_string("proxy_pass_request_headers"),
177 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, 174 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
178 ngx_conf_set_flag_slot, 175 ngx_conf_set_flag_slot,
179 NGX_HTTP_LOC_CONF_OFFSET, 176 NGX_HTTP_LOC_CONF_OFFSET,
240 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, 237 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
241 ngx_conf_set_bitmask_slot, 238 ngx_conf_set_bitmask_slot,
242 NGX_HTTP_LOC_CONF_OFFSET, 239 NGX_HTTP_LOC_CONF_OFFSET,
243 offsetof(ngx_http_proxy_loc_conf_t, upstream.next_upstream), 240 offsetof(ngx_http_proxy_loc_conf_t, upstream.next_upstream),
244 &ngx_http_proxy_next_upstream_masks }, 241 &ngx_http_proxy_next_upstream_masks },
242
243 { ngx_string("proxy_upstream_max_fails"),
244 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
245 ngx_conf_set_num_slot,
246 NGX_HTTP_LOC_CONF_OFFSET,
247 offsetof(ngx_http_proxy_loc_conf_t, upstream.max_fails),
248 NULL },
249
250 { ngx_string("proxy_upstream_fail_timeout"),
251 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
252 ngx_conf_set_sec_slot,
253 NGX_HTTP_LOC_CONF_OFFSET,
254 offsetof(ngx_http_proxy_loc_conf_t, upstream.fail_timeout),
255 NULL },
245 256
246 { ngx_string("proxy_pass_x_powered_by"), 257 { ngx_string("proxy_pass_x_powered_by"),
247 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, 258 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
248 ngx_conf_set_flag_slot, 259 ngx_conf_set_flag_slot,
249 NGX_HTTP_LOC_CONF_OFFSET, 260 NGX_HTTP_LOC_CONF_OFFSET,
297 NULL, /* exit master */ 308 NULL, /* exit master */
298 NGX_MODULE_V1_PADDING 309 NGX_MODULE_V1_PADDING
299 }; 310 };
300 311
301 312
302 static ngx_str_t ngx_http_proxy_methods[] = {
303 ngx_string("GET "),
304 ngx_string("HEAD "),
305 ngx_string("POST ")
306 };
307
308
309 static char ngx_http_proxy_version[] = " HTTP/1.0" CRLF; 313 static char ngx_http_proxy_version[] = " HTTP/1.0" CRLF;
310 314
311 315
312 static ngx_table_elt_t ngx_http_proxy_headers[] = { 316 static ngx_table_elt_t ngx_http_proxy_headers[] = {
313 { 0, ngx_string("Host"), ngx_string("$proxy_host") }, 317 { 0, ngx_string("Host"), ngx_string("$proxy_host") },
392 { 396 {
393 size_t len, loc_len; 397 size_t len, loc_len;
394 ngx_uint_t i, key; 398 ngx_uint_t i, key;
395 uintptr_t escape; 399 uintptr_t escape;
396 ngx_buf_t *b; 400 ngx_buf_t *b;
397 ngx_str_t *hh; 401 ngx_str_t *hh, method;
398 ngx_chain_t *cl, *body; 402 ngx_chain_t *cl, *body;
399 ngx_list_part_t *part; 403 ngx_list_part_t *part;
400 ngx_table_elt_t *header; 404 ngx_table_elt_t *header;
401 ngx_http_upstream_t *u; 405 ngx_http_upstream_t *u;
402 ngx_http_script_code_pt code; 406 ngx_http_script_code_pt code;
408 412
409 plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module); 413 plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
410 414
411 len = sizeof(ngx_http_proxy_version) - 1 + sizeof(CRLF) - 1; 415 len = sizeof(ngx_http_proxy_version) - 1 + sizeof(CRLF) - 1;
412 416
413 if (u->method) { 417 if (u->method.len) {
414 len += ngx_http_proxy_methods[u->method - 1].len + u->conf->uri.len; 418 /* HEAD was changed to GET to cache response */
419 method = u->method;
420 method.len++;
421
422 } else if (plcf->method.len) {
423 method = plcf->method;
424
415 } else { 425 } else {
416 len += r->method_name.len + 1 + u->conf->uri.len; 426 method = r->method_name;
417 } 427 method.len++;
428 }
429
430 len += method.len + u->conf->uri.len;
418 431
419 escape = 0; 432 escape = 0;
420 433
421 loc_len = r->valid_location ? u->conf->location->len : 0; 434 loc_len = r->valid_location ? u->conf->location->len : 0;
422 435
491 cl->buf = b; 504 cl->buf = b;
492 505
493 506
494 /* the request line */ 507 /* the request line */
495 508
496 if (u->method) { 509 b->last = ngx_cpymem(b->last, method.data, method.len);
497 b->last = ngx_cpymem(b->last,
498 ngx_http_proxy_methods[u->method - 1].data,
499 ngx_http_proxy_methods[u->method - 1].len);
500 } else {
501 b->last = ngx_cpymem(b->last, r->method_name.data,
502 r->method_name.len + 1);
503 }
504 510
505 u->uri.data = b->last; 511 u->uri.data = b->last;
506 512
507 if (u->conf->uri.len == 0 && r->valid_unparsed_uri) { 513 if (u->conf->uri.len == 0 && r->valid_unparsed_uri) {
508 b->last = ngx_cpymem(b->last, r->unparsed_uri.data, 514 b->last = ngx_cpymem(b->last, r->unparsed_uri.data,
1286 * conf->upstream.temp_path = NULL; 1292 * conf->upstream.temp_path = NULL;
1287 * conf->upstream.schema = { 0, NULL }; 1293 * conf->upstream.schema = { 0, NULL };
1288 * conf->upstream.uri = { 0, NULL }; 1294 * conf->upstream.uri = { 0, NULL };
1289 * conf->upstream.location = NULL; 1295 * conf->upstream.location = NULL;
1290 * 1296 *
1297 * conf->method = NULL;
1291 * conf->headers_source = NULL; 1298 * conf->headers_source = NULL;
1292 * conf->headers_set_len = NULL; 1299 * conf->headers_set_len = NULL;
1293 * conf->headers_set = NULL; 1300 * conf->headers_set = NULL;
1294 * conf->headers_set_hash = NULL; 1301 * conf->headers_set_hash = NULL;
1295 * conf->rewrite_locations = NULL; 1302 * conf->rewrite_locations = NULL;
1304 1311
1305 conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE; 1312 conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
1306 conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE; 1313 conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
1307 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE; 1314 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE;
1308 1315
1309 conf->upstream.method = NGX_CONF_UNSET_UINT; 1316 conf->upstream.max_fails = NGX_CONF_UNSET_UINT;
1317 conf->upstream.fail_timeout = NGX_CONF_UNSET;
1318
1310 conf->upstream.pass_request_headers = NGX_CONF_UNSET; 1319 conf->upstream.pass_request_headers = NGX_CONF_UNSET;
1311 conf->upstream.pass_request_body = NGX_CONF_UNSET; 1320 conf->upstream.pass_request_body = NGX_CONF_UNSET;
1312 1321
1313 conf->upstream.redirect_errors = NGX_CONF_UNSET; 1322 conf->upstream.redirect_errors = NGX_CONF_UNSET;
1314 1323
1315 /* "proxy_cyclic_temp_file" is disabled */ 1324 /* "proxy_cyclic_temp_file" is disabled */
1316 conf->upstream.cyclic_temp_file = 0; 1325 conf->upstream.cyclic_temp_file = 0;
1317 1326
1438 1447
1439 if (conf->upstream.max_temp_file_size != 0 1448 if (conf->upstream.max_temp_file_size != 0
1440 && conf->upstream.max_temp_file_size < size) 1449 && conf->upstream.max_temp_file_size < size)
1441 { 1450 {
1442 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 1451 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1443 "\"fastcgi_max_temp_file_size\" must be equal to zero to disable " 1452 "\"proxy_max_temp_file_size\" must be equal to zero to disable "
1444 "the temporary files usage or must be equal or bigger than " 1453 "the temporary files usage or must be equal or bigger than "
1445 "maximum of the value of \"fastcgi_header_buffer_size\" and " 1454 "maximum of the value of \"proxy_header_buffer_size\" and "
1446 "one of the \"fastcgi_buffers\""); 1455 "one of the \"proxy_buffers\"");
1447 1456
1448 return NGX_CONF_ERROR; 1457 return NGX_CONF_ERROR;
1449 } 1458 }
1450 1459
1451 1460
1453 prev->upstream.next_upstream, 1462 prev->upstream.next_upstream,
1454 (NGX_CONF_BITMASK_SET 1463 (NGX_CONF_BITMASK_SET
1455 |NGX_HTTP_UPSTREAM_FT_ERROR 1464 |NGX_HTTP_UPSTREAM_FT_ERROR
1456 |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); 1465 |NGX_HTTP_UPSTREAM_FT_TIMEOUT));
1457 1466
1467 ngx_conf_merge_unsigned_value(conf->upstream.max_fails,
1468 prev->upstream.max_fails, 1);
1469
1470 ngx_conf_merge_sec_value(conf->upstream.fail_timeout,
1471 prev->upstream.fail_timeout, 10);
1472
1473 if (conf->peers && conf->peers->number > 1) {
1474 for (i = 0; i < conf->peers->number; i++) {
1475 conf->peers->peer[i].weight = 1;
1476 conf->peers->peer[i].max_fails = conf->upstream.max_fails;
1477 conf->peers->peer[i].fail_timeout = conf->upstream.fail_timeout;
1478 }
1479 }
1480
1458 ngx_conf_merge_path_value(conf->upstream.temp_path, 1481 ngx_conf_merge_path_value(conf->upstream.temp_path,
1459 prev->upstream.temp_path, 1482 prev->upstream.temp_path,
1460 NGX_HTTP_PROXY_TEMP_PATH, 1, 2, 0, 1483 NGX_HTTP_PROXY_TEMP_PATH, 1, 2, 0,
1461 ngx_garbage_collector_temp_handler, cf); 1484 ngx_garbage_collector_temp_handler, cf);
1462 1485
1463 if (conf->upstream.method == NGX_CONF_UNSET_UINT) { 1486 if (conf->method.len == 0) {
1464 conf->upstream.method = prev->upstream.method; 1487 conf->method = prev->method;
1488
1489 } else {
1490 conf->method.data[conf->method.len] = ' ';
1491 conf->method.len++;
1465 } 1492 }
1466 1493
1467 ngx_conf_merge_value(conf->upstream.pass_request_headers, 1494 ngx_conf_merge_value(conf->upstream.pass_request_headers,
1468 prev->upstream.pass_request_headers, 1); 1495 prev->upstream.pass_request_headers, 1);
1469 ngx_conf_merge_value(conf->upstream.pass_request_body, 1496 ngx_conf_merge_value(conf->upstream.pass_request_body,