Mercurial > hg > nginx-vendor-0-6
comparison src/http/modules/ngx_http_fastcgi_handler.c @ 34:aab2ea7c0458 NGINX_0_1_17
nginx 0.1.17
*) Change: the ngx_http_rewrite_module was rewritten from the scratch.
Now it is possible to redirect, to return the error codes, to check
the variables and referrers. The directives can be used inside
locations. The redirect directive was canceled.
*) Feature: the ngx_http_geo_module.
*) Feature: the proxy_set_x_var and fastcgi_set_var directives.
*) Bugfix: the location configuration with "=" modifier may be used in
another location.
*) Bugfix: the correct content type was set only for requests that use
small caps letters in extension.
*) Bugfix: if the proxy_pass or fastcgi_pass directives were set in the
location, and access was denied, and the error was redirected to a
static page, then the segmentation fault occurred.
*) Bugfix: if in a proxied "Location" header was a relative URL, then a
host name and a slash were added to them; bug appeared in 0.1.14.
*) Bugfix: the system error message was not logged on Linux.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Thu, 03 Feb 2005 00:00:00 +0300 |
parents | da8c190bdaba |
children | a39d1b793287 |
comparison
equal
deleted
inserted
replaced
33:27f09a550803 | 34:aab2ea7c0458 |
---|---|
17 | 17 |
18 ngx_uint_t params; | 18 ngx_uint_t params; |
19 | 19 |
20 ngx_str_t root; | 20 ngx_str_t root; |
21 ngx_str_t index; | 21 ngx_str_t index; |
22 | |
23 ngx_array_t vars; | |
22 | 24 |
23 ngx_str_t *location; | 25 ngx_str_t *location; |
24 } ngx_http_fastcgi_loc_conf_t; | 26 } ngx_http_fastcgi_loc_conf_t; |
25 | 27 |
26 | 28 |
128 static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r, | 130 static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r, |
129 ngx_int_t rc); | 131 ngx_int_t rc); |
130 | 132 |
131 static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, | 133 static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, |
132 void *conf); | 134 void *conf); |
135 static char *ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd, | |
136 void *conf); | |
133 static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, | 137 static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, |
134 void *data); | 138 void *data); |
135 static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf); | 139 static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf); |
136 static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, | 140 static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, |
137 void *parent, void *child); | 141 void *parent, void *child); |
304 ngx_conf_set_bitmask_slot, | 308 ngx_conf_set_bitmask_slot, |
305 NGX_HTTP_LOC_CONF_OFFSET, | 309 NGX_HTTP_LOC_CONF_OFFSET, |
306 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.next_upstream), | 310 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.next_upstream), |
307 &ngx_http_fastcgi_next_upstream_masks }, | 311 &ngx_http_fastcgi_next_upstream_masks }, |
308 | 312 |
313 { ngx_string("fastcgi_set_var"), | |
314 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
315 ngx_http_fastcgi_set_var, | |
316 NGX_HTTP_LOC_CONF_OFFSET, | |
317 0, | |
318 NULL }, | |
319 | |
309 { ngx_string("fastcgi_params"), | 320 { ngx_string("fastcgi_params"), |
310 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_ANY, | 321 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_ANY, |
311 ngx_conf_set_bitmask_slot, | 322 ngx_conf_set_bitmask_slot, |
312 NGX_HTTP_LOC_CONF_OFFSET, | 323 NGX_HTTP_LOC_CONF_OFFSET, |
313 offsetof(ngx_http_fastcgi_loc_conf_t, params), | 324 offsetof(ngx_http_fastcgi_loc_conf_t, params), |
403 size_t size, len, index, padding, addr_len; | 414 size_t size, len, index, padding, addr_len; |
404 off_t file_pos; | 415 off_t file_pos; |
405 ngx_buf_t *b; | 416 ngx_buf_t *b; |
406 socklen_t slen; | 417 socklen_t slen; |
407 ngx_chain_t *cl, *body; | 418 ngx_chain_t *cl, *body; |
408 ngx_uint_t i, n, next; | 419 ngx_uint_t i, n, next, *vindex; |
409 ngx_list_part_t *part; | 420 ngx_list_part_t *part; |
410 ngx_table_elt_t *header; | 421 ngx_table_elt_t *header; |
411 struct sockaddr_in sin; | 422 struct sockaddr_in sin; |
423 ngx_http_variable_t *var; | |
424 ngx_http_variable_value_t *value; | |
425 ngx_http_core_main_conf_t *cmcf; | |
412 ngx_http_fastcgi_header_t *h; | 426 ngx_http_fastcgi_header_t *h; |
413 ngx_http_fastcgi_loc_conf_t *flcf; | 427 ngx_http_fastcgi_loc_conf_t *flcf; |
414 ngx_http_fastcgi_begin_request_t *br; | 428 ngx_http_fastcgi_begin_request_t *br; |
429 | |
415 | 430 |
416 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module); | 431 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module); |
417 | 432 |
418 if ((flcf->params & NGX_HTTP_FASTCGI_SERVER_ADDR) && r->in_addr == 0) { | 433 if ((flcf->params & NGX_HTTP_FASTCGI_SERVER_ADDR) && r->in_addr == 0) { |
419 | 434 |
513 len += 1 + 1 + sizeof("SERVER_SOFTWARE") - 1 + sizeof(NGINX_VER) - 1; | 528 len += 1 + 1 + sizeof("SERVER_SOFTWARE") - 1 + sizeof(NGINX_VER) - 1; |
514 } | 529 } |
515 | 530 |
516 if (flcf->params & NGX_HTTP_FASTCGI_GATEWAY_INTERFACE) { | 531 if (flcf->params & NGX_HTTP_FASTCGI_GATEWAY_INTERFACE) { |
517 len += 1 + 1 + sizeof("GATEWAY_INTERFACE") - 1 + sizeof("CGI/1.1") - 1; | 532 len += 1 + 1 + sizeof("GATEWAY_INTERFACE") - 1 + sizeof("CGI/1.1") - 1; |
533 } | |
534 | |
535 | |
536 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
537 | |
538 var = cmcf->variables.elts; | |
539 vindex = flcf->vars.elts; | |
540 | |
541 for (i = 0; i < flcf->vars.nelts; i++) { | |
542 | |
543 if (!(value = ngx_http_get_variable(r, vindex[i]))) { | |
544 continue; | |
545 } | |
546 | |
547 if (value->text.len) { | |
548 len += 1 + 1 + var[vindex[i]].name.len + value->text.len; | |
549 } | |
518 } | 550 } |
519 | 551 |
520 | 552 |
521 part = &r->headers_in.headers.part; | 553 part = &r->headers_in.headers.part; |
522 header = part->elts; | 554 header = part->elts; |
845 *b->last++ = sizeof("GATEWAY_INTERFACE") - 1; | 877 *b->last++ = sizeof("GATEWAY_INTERFACE") - 1; |
846 *b->last++ = (u_char) (sizeof("CGI/1.1") - 1); | 878 *b->last++ = (u_char) (sizeof("CGI/1.1") - 1); |
847 b->last = ngx_cpymem(b->last, "GATEWAY_INTERFACE", | 879 b->last = ngx_cpymem(b->last, "GATEWAY_INTERFACE", |
848 sizeof("GATEWAY_INTERFACE") - 1); | 880 sizeof("GATEWAY_INTERFACE") - 1); |
849 b->last = ngx_cpymem(b->last, "CGI/1.1", sizeof("CGI/1.1") - 1); | 881 b->last = ngx_cpymem(b->last, "CGI/1.1", sizeof("CGI/1.1") - 1); |
882 } | |
883 | |
884 | |
885 for (i = 0; i < flcf->vars.nelts; i++) { | |
886 | |
887 if (!(value = ngx_http_get_variable(r, vindex[i]))) { | |
888 continue; | |
889 } | |
890 | |
891 if (value->text.len == 0) { | |
892 continue; | |
893 } | |
894 | |
895 *b->last++ = (u_char) var[vindex[i]].name.len; | |
896 *b->last++ = (u_char) value->text.len; | |
897 | |
898 b->last = ngx_cpymem(b->last, var[vindex[i]].name.data, | |
899 var[vindex[i]].name.len); | |
900 | |
901 b->last = ngx_cpymem(b->last, value->text.data, value->text.len); | |
850 } | 902 } |
851 | 903 |
852 | 904 |
853 part = &r->headers_in.headers.part; | 905 part = &r->headers_in.headers.part; |
854 header = part->elts; | 906 header = part->elts; |
1761 | 1813 |
1762 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | 1814 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); |
1763 | 1815 |
1764 clcf->handler = ngx_http_fastcgi_handler; | 1816 clcf->handler = ngx_http_fastcgi_handler; |
1765 | 1817 |
1818 #if (NGX_PCRE) | |
1766 lcf->location = clcf->regex ? &ngx_http_fastcgi_uri: &clcf->name; | 1819 lcf->location = clcf->regex ? &ngx_http_fastcgi_uri: &clcf->name; |
1820 #else | |
1821 lcf->location = &clcf->name; | |
1822 #endif | |
1767 | 1823 |
1768 if (clcf->name.data[clcf->name.len - 1] == '/') { | 1824 if (clcf->name.data[clcf->name.len - 1] == '/') { |
1769 clcf->auto_redirect = 1; | 1825 clcf->auto_redirect = 1; |
1770 } | 1826 } |
1771 | 1827 |
1772 return NGX_CONF_OK; | 1828 return NGX_CONF_OK; |
1829 } | |
1830 | |
1831 | |
1832 static char *ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd, | |
1833 void *conf) | |
1834 { | |
1835 ngx_http_fastcgi_loc_conf_t *lcf = conf; | |
1836 | |
1837 ngx_uint_t i, *index; | |
1838 ngx_str_t *value; | |
1839 ngx_http_variable_t *var; | |
1840 ngx_http_core_main_conf_t *cmcf; | |
1841 | |
1842 if (lcf->vars.elts == NULL) { | |
1843 if (ngx_array_init(&lcf->vars, cf->pool, 4, | |
1844 sizeof(ngx_http_variable_t *)) == NGX_ERROR) | |
1845 { | |
1846 return NGX_CONF_ERROR; | |
1847 } | |
1848 } | |
1849 | |
1850 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
1851 | |
1852 value = cf->args->elts; | |
1853 | |
1854 var = cmcf->variables.elts; | |
1855 for (i = 0; i < cmcf->variables.nelts; i++) { | |
1856 if (ngx_strcasecmp(var[i].name.data, value[1].data) == 0) { | |
1857 | |
1858 if (!(index = ngx_array_push(&lcf->vars))) { | |
1859 return NGX_CONF_ERROR; | |
1860 } | |
1861 | |
1862 *index = var[i].index; | |
1863 return NGX_CONF_OK; | |
1864 } | |
1865 } | |
1866 | |
1867 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1868 "unknown variable name \"%V\"", &value[1]); | |
1869 return NGX_CONF_ERROR; | |
1773 } | 1870 } |
1774 | 1871 |
1775 | 1872 |
1776 static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, | 1873 static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, |
1777 void *data) | 1874 void *data) |