Mercurial > hg > nginx-vendor-1-0
comparison src/http/modules/proxy/ngx_http_proxy_handler.c @ 50:72eb30262aac NGINX_0_1_25
nginx 0.1.25
*) Bugfix: nginx did run on Linux parisc.
*) Feature: nginx now does not start under FreeBSD if the sysctl
kern.ipc.somaxconn value is too big.
*) Bugfix: if a request was internally redirected by the
ngx_http_index_module module to the ngx_http_proxy_module or
ngx_http_fastcgi_module modules, then the index file was not closed
after request completion.
*) Feature: the "proxy_pass" can be used in location with regular
expression.
*) Feature: the ngx_http_rewrite_filter_module module supports the
condition like "if ($HTTP_USER_AGENT ~ MSIE)".
*) Bugfix: nginx started too slow if the large number of addresses and
text values were used in the "geo" directive.
*) Change: a variable name must be declared as "$name" in the "geo"
directive. The previous variant without "$" is still supported, but
will be removed soon.
*) Feature: the "%{VARIABLE}v" logging parameter.
*) Feature: the "set $name value" directive.
*) Bugfix: gcc 4.0 compatibility.
*) Feature: the --with-openssl-opt=OPTIONS autoconfiguration directive.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Sat, 19 Mar 2005 00:00:00 +0300 |
parents | a39d1b793287 |
children | 0d75d65c642f |
comparison
equal
deleted
inserted
replaced
49:93dabbc9efb9 | 50:72eb30262aac |
---|---|
9 #include <ngx_http.h> | 9 #include <ngx_http.h> |
10 #include <ngx_http_proxy_handler.h> | 10 #include <ngx_http_proxy_handler.h> |
11 | 11 |
12 | 12 |
13 static ngx_int_t ngx_http_proxy_handler(ngx_http_request_t *r); | 13 static ngx_int_t ngx_http_proxy_handler(ngx_http_request_t *r); |
14 #if 0 | |
14 static ngx_int_t ngx_http_proxy_cache_get(ngx_http_proxy_ctx_t *p); | 15 static ngx_int_t ngx_http_proxy_cache_get(ngx_http_proxy_ctx_t *p); |
16 #endif | |
15 | 17 |
16 static size_t ngx_http_proxy_log_proxy_state_getlen(ngx_http_request_t *r, | 18 static size_t ngx_http_proxy_log_proxy_state_getlen(ngx_http_request_t *r, |
17 uintptr_t data); | 19 uintptr_t data); |
18 static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, | 20 static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, |
19 u_char *buf, | 21 u_char *buf, |
31 static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, | 33 static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, |
32 void *parent, void *child); | 34 void *parent, void *child); |
33 | 35 |
34 static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, | 36 static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, |
35 void *conf); | 37 void *conf); |
36 static char *ngx_http_proxy_parse_upstream(ngx_str_t *url, | |
37 ngx_http_proxy_upstream_conf_t *u); | |
38 | 38 |
39 static char *ngx_http_proxy_set_x_var(ngx_conf_t *cf, ngx_command_t *cmd, | 39 static char *ngx_http_proxy_set_x_var(ngx_conf_t *cf, ngx_command_t *cmd, |
40 void *conf); | 40 void *conf); |
41 static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data); | 41 static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data); |
42 | 42 |
360 ngx_string("LMF"), | 360 ngx_string("LMF"), |
361 ngx_string("PDE") | 361 ngx_string("PDE") |
362 }; | 362 }; |
363 | 363 |
364 | 364 |
365 static ngx_str_t ngx_http_proxy_uri = ngx_string("/"); | |
366 | |
367 | |
365 static ngx_int_t ngx_http_proxy_handler(ngx_http_request_t *r) | 368 static ngx_int_t ngx_http_proxy_handler(ngx_http_request_t *r) |
366 { | 369 { |
367 ngx_http_proxy_ctx_t *p; | 370 ngx_http_proxy_ctx_t *p; |
368 | 371 |
369 ngx_http_create_ctx(r, p, ngx_http_proxy_module, | 372 p = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_ctx_t)); |
370 sizeof(ngx_http_proxy_ctx_t), | 373 if (p == NULL) { |
371 NGX_HTTP_INTERNAL_SERVER_ERROR); | 374 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
375 } | |
376 | |
377 ngx_http_set_ctx(r, p, ngx_http_proxy_module); | |
378 | |
372 | 379 |
373 p->lcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module); | 380 p->lcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module); |
374 p->request = r; | 381 p->request = r; |
375 | 382 |
376 /* TODO: we currently support reverse proxy only */ | 383 /* TODO: we currently support reverse proxy only */ |
380 sizeof(ngx_http_proxy_state_t)) == NGX_ERROR) | 387 sizeof(ngx_http_proxy_state_t)) == NGX_ERROR) |
381 { | 388 { |
382 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 389 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
383 } | 390 } |
384 | 391 |
385 if (!(p->state = ngx_array_push(&p->states))) { | 392 p->state = ngx_array_push(&p->states); |
393 if (p->state == NULL) { | |
386 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 394 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
387 } | 395 } |
388 | 396 |
389 ngx_memzero(p->state, sizeof(ngx_http_proxy_state_t)); | 397 ngx_memzero(p->state, sizeof(ngx_http_proxy_state_t)); |
390 | 398 |
437 | 445 |
438 r = p->request; | 446 r = p->request; |
439 u = p->lcf->upstream; | 447 u = p->lcf->upstream; |
440 | 448 |
441 ctx.key.len = u->url.len + r->uri.len - u->location->len + r->args.len; | 449 ctx.key.len = u->url.len + r->uri.len - u->location->len + r->args.len; |
442 if (!(ctx.key.data = ngx_palloc(r->pool, ctx.key.len))) { | 450 ctx.key.data = ngx_palloc(r->pool, ctx.key.len); |
451 if (ctx.key.data == NULL) { | |
443 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 452 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
444 } | 453 } |
445 | 454 |
446 last = ngx_cpymem(ctx.key.data, u->url.data, u->url.len); | 455 last = ngx_cpymem(ctx.key.data, u->url.data, u->url.len); |
447 | 456 |
1070 | 1079 |
1071 static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf) | 1080 static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf) |
1072 { | 1081 { |
1073 ngx_http_proxy_loc_conf_t *conf; | 1082 ngx_http_proxy_loc_conf_t *conf; |
1074 | 1083 |
1075 if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_loc_conf_t)))) { | 1084 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_loc_conf_t)); |
1085 if (conf == NULL) { | |
1076 return NGX_CONF_ERROR; | 1086 return NGX_CONF_ERROR; |
1077 } | 1087 } |
1078 | 1088 |
1079 /* | 1089 /* |
1080 * set by ngx_pcalloc(): | 1090 * set by ngx_pcalloc(): |
1330 unix_upstream.name = *url; | 1340 unix_upstream.name = *url; |
1331 unix_upstream.url.len = url->len - 7; | 1341 unix_upstream.url.len = url->len - 7; |
1332 unix_upstream.url.data = url->data + 7; | 1342 unix_upstream.url.data = url->data + 7; |
1333 unix_upstream.uri_part = 1; | 1343 unix_upstream.uri_part = 1; |
1334 | 1344 |
1335 if (!(lcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream))) { | 1345 lcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream); |
1346 if (lcf->peers == NULL) { | |
1336 return NGX_CONF_ERROR; | 1347 return NGX_CONF_ERROR; |
1337 } | 1348 } |
1338 | 1349 |
1339 lcf->upstream->host_header.len = sizeof("localhost") - 1; | 1350 lcf->upstream->host_header.len = sizeof("localhost") - 1; |
1340 lcf->upstream->host_header.data = (u_char *) "localhost"; | 1351 lcf->upstream->host_header.data = (u_char *) "localhost"; |
1357 inet_upstream.url.len = url->len - 7; | 1368 inet_upstream.url.len = url->len - 7; |
1358 inet_upstream.url.data = url->data + 7; | 1369 inet_upstream.url.data = url->data + 7; |
1359 inet_upstream.default_port_value = 80; | 1370 inet_upstream.default_port_value = 80; |
1360 inet_upstream.uri_part = 1; | 1371 inet_upstream.uri_part = 1; |
1361 | 1372 |
1362 if (!(lcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream))) { | 1373 lcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream); |
1374 if (lcf->peers == NULL) { | |
1363 return NGX_CONF_ERROR; | 1375 return NGX_CONF_ERROR; |
1364 } | 1376 } |
1365 | 1377 |
1366 lcf->upstream->host_header = inet_upstream.host_header; | 1378 lcf->upstream->host_header = inet_upstream.host_header; |
1367 lcf->upstream->port_text = inet_upstream.port_text; | 1379 lcf->upstream->port_text = inet_upstream.port_text; |
1370 lcf->upstream->default_port = inet_upstream.default_port; | 1382 lcf->upstream->default_port = inet_upstream.default_port; |
1371 } | 1383 } |
1372 | 1384 |
1373 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | 1385 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); |
1374 | 1386 |
1387 clcf->handler = ngx_http_proxy_handler; | |
1388 | |
1389 #if (NGX_PCRE) | |
1390 lcf->upstream->location = clcf->regex ? &ngx_http_proxy_uri : &clcf->name; | |
1391 #else | |
1375 lcf->upstream->location = &clcf->name; | 1392 lcf->upstream->location = &clcf->name; |
1376 clcf->handler = ngx_http_proxy_handler; | 1393 #endif |
1377 | 1394 |
1378 if (clcf->name.data[clcf->name.len - 1] == '/') { | 1395 if (clcf->name.data[clcf->name.len - 1] == '/') { |
1379 clcf->auto_redirect = 1; | 1396 clcf->auto_redirect = 1; |
1380 } | 1397 } |
1381 | 1398 |
1407 | 1424 |
1408 var = cmcf->variables.elts; | 1425 var = cmcf->variables.elts; |
1409 for (i = 0; i < cmcf->variables.nelts; i++) { | 1426 for (i = 0; i < cmcf->variables.nelts; i++) { |
1410 if (ngx_strcasecmp(var[i].name.data, value[1].data) == 0) { | 1427 if (ngx_strcasecmp(var[i].name.data, value[1].data) == 0) { |
1411 | 1428 |
1412 if (!(index = ngx_array_push(lcf->x_vars))) { | 1429 index = ngx_array_push(lcf->x_vars); |
1430 if (index == NULL) { | |
1413 return NGX_CONF_ERROR; | 1431 return NGX_CONF_ERROR; |
1414 } | 1432 } |
1415 | 1433 |
1416 *index = var[i].index; | 1434 *index = var[i].index; |
1417 return NGX_CONF_OK; | 1435 return NGX_CONF_OK; |