Mercurial > hg > nginx-vendor-0-8
comparison src/http/modules/ngx_http_fastcgi_module.c @ 130:82d695e3d662 NGINX_0_3_12
nginx 0.3.12
*) Security: if nginx was built with the ngx_http_realip_module and the
"satisfy_any on" directive was used, then access and authorization
directives did not work. The ngx_http_realip_module was not built
and is not built by default.
*) Change: the "$time_gmt" variable name was changed to "$time_local".
*) Change: the "proxy_header_buffer_size" and
"fastcgi_header_buffer_size" directives was renamed to the
"proxy_buffer_size" and "fastcgi_buffer_size" directives.
*) Feature: the ngx_http_memcached_module.
*) Feature: the "proxy_buffering" directive.
*) Bugfix: the changes in accept mutex handling when the "rtsig" method
was used; bug appeared in 0.3.0.
*) Bugfix: if the client sent the "Transfer-Encoding: chunked" header
line, then nginx returns the 411 error.
*) Bugfix: if the "auth_basic" directive was inherited from the http
level, then the realm in the "WWW-Authenticate" header line was
without the "Basic realm" text.
*) Bugfix: if the "combined" format was explicitly specified in the
"access_log" directive, then the empty lines was written to the log;
bug appeared in 0.3.8.
*) Bugfix: nginx did not run on the sparc platform under any OS except
Solaris.
*) Bugfix: now it is not necessary to place space between the quoted
string and closing bracket in the "if" directive.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Sat, 26 Nov 2005 00:00:00 +0300 |
parents | df17fbafec8f |
children | 91372f004adf |
comparison
equal
deleted
inserted
replaced
129:a27c77ef3ad8 | 130:82d695e3d662 |
---|---|
9 #include <ngx_http.h> | 9 #include <ngx_http.h> |
10 #include <nginx.h> | 10 #include <nginx.h> |
11 | 11 |
12 | 12 |
13 typedef struct { | 13 typedef struct { |
14 ngx_http_upstream_conf_t upstream; | 14 ngx_http_upstream_conf_t upstream; |
15 | 15 |
16 ngx_peers_t *peers; | 16 ngx_peers_t *peers; |
17 | 17 |
18 ngx_str_t index; | 18 ngx_str_t index; |
19 | 19 |
20 ngx_array_t *flushes; | 20 ngx_array_t *flushes; |
21 ngx_array_t *params_len; | 21 ngx_array_t *params_len; |
22 ngx_array_t *params; | 22 ngx_array_t *params; |
23 ngx_array_t *params_source; | 23 ngx_array_t *params_source; |
24 } ngx_http_fastcgi_loc_conf_t; | 24 } ngx_http_fastcgi_loc_conf_t; |
25 | 25 |
26 | 26 |
27 typedef enum { | 27 typedef enum { |
28 ngx_http_fastcgi_st_version = 0, | 28 ngx_http_fastcgi_st_version = 0, |
37 ngx_http_fastcgi_st_padding | 37 ngx_http_fastcgi_st_padding |
38 } ngx_http_fastcgi_state_e; | 38 } ngx_http_fastcgi_state_e; |
39 | 39 |
40 | 40 |
41 typedef struct { | 41 typedef struct { |
42 ngx_http_fastcgi_state_e state; | 42 ngx_http_fastcgi_state_e state; |
43 u_char *pos; | 43 u_char *pos; |
44 u_char *last; | 44 u_char *last; |
45 ngx_uint_t type; | 45 ngx_uint_t type; |
46 size_t length; | 46 size_t length; |
47 size_t padding; | 47 size_t padding; |
48 | 48 |
49 ngx_uint_t header; | 49 ngx_uint_t header; |
50 } ngx_http_fastcgi_ctx_t; | 50 } ngx_http_fastcgi_ctx_t; |
51 | 51 |
52 | 52 |
53 #define NGX_HTTP_FASTCGI_RESPONDER 1 | 53 #define NGX_HTTP_FASTCGI_RESPONDER 1 |
54 | 54 |
149 | 149 |
150 | 150 |
151 static ngx_conf_post_t ngx_http_fastcgi_lowat_post = | 151 static ngx_conf_post_t ngx_http_fastcgi_lowat_post = |
152 { ngx_http_fastcgi_lowat_check }; | 152 { ngx_http_fastcgi_lowat_check }; |
153 | 153 |
154 static ngx_conf_deprecated_t ngx_conf_deprecated_fastcgi_header_buffer_size = { | |
155 ngx_conf_deprecated, "fastcgi_header_buffer_size", "fastcgi_buffer_size" | |
156 }; | |
157 | |
154 | 158 |
155 static ngx_conf_bitmask_t ngx_http_fastcgi_next_upstream_masks[] = { | 159 static ngx_conf_bitmask_t ngx_http_fastcgi_next_upstream_masks[] = { |
156 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR }, | 160 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR }, |
157 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT }, | 161 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT }, |
158 { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER }, | 162 { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER }, |
197 ngx_conf_set_size_slot, | 201 ngx_conf_set_size_slot, |
198 NGX_HTTP_LOC_CONF_OFFSET, | 202 NGX_HTTP_LOC_CONF_OFFSET, |
199 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.send_lowat), | 203 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.send_lowat), |
200 &ngx_http_fastcgi_lowat_post }, | 204 &ngx_http_fastcgi_lowat_post }, |
201 | 205 |
206 { ngx_string("fastcgi_buffer_size"), | |
207 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
208 ngx_conf_set_size_slot, | |
209 NGX_HTTP_LOC_CONF_OFFSET, | |
210 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.buffer_size), | |
211 NULL }, | |
212 | |
202 { ngx_string("fastcgi_header_buffer_size"), | 213 { ngx_string("fastcgi_header_buffer_size"), |
203 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 214 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
204 ngx_conf_set_size_slot, | 215 ngx_conf_set_size_slot, |
205 NGX_HTTP_LOC_CONF_OFFSET, | 216 NGX_HTTP_LOC_CONF_OFFSET, |
206 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.header_buffer_size), | 217 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.buffer_size), |
207 NULL }, | 218 &ngx_conf_deprecated_fastcgi_header_buffer_size }, |
208 | 219 |
209 { ngx_string("fastcgi_pass_request_headers"), | 220 { ngx_string("fastcgi_pass_request_headers"), |
210 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | 221 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
211 ngx_conf_set_flag_slot, | 222 ngx_conf_set_flag_slot, |
212 NGX_HTTP_LOC_CONF_OFFSET, | 223 NGX_HTTP_LOC_CONF_OFFSET, |
369 u->reinit_request = ngx_http_fastcgi_reinit_request; | 380 u->reinit_request = ngx_http_fastcgi_reinit_request; |
370 u->process_header = ngx_http_fastcgi_process_header; | 381 u->process_header = ngx_http_fastcgi_process_header; |
371 u->abort_request = ngx_http_fastcgi_abort_request; | 382 u->abort_request = ngx_http_fastcgi_abort_request; |
372 u->finalize_request = ngx_http_fastcgi_finalize_request; | 383 u->finalize_request = ngx_http_fastcgi_finalize_request; |
373 | 384 |
374 u->pipe.input_filter = ngx_http_fastcgi_input_filter; | 385 u->pipe = ngx_pcalloc(r->pool, sizeof(ngx_event_pipe_t)); |
375 u->pipe.input_ctx = r; | 386 if (u->pipe == NULL) { |
387 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
388 } | |
389 | |
390 u->pipe->input_filter = ngx_http_fastcgi_input_filter; | |
391 u->pipe->input_ctx = r; | |
376 | 392 |
377 r->upstream = u; | 393 r->upstream = u; |
378 | 394 |
379 rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init); | 395 rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init); |
380 | 396 |
797 | 813 |
798 for ( ;; ) { | 814 for ( ;; ) { |
799 | 815 |
800 if (f->state < ngx_http_fastcgi_st_data) { | 816 if (f->state < ngx_http_fastcgi_st_data) { |
801 | 817 |
802 f->pos = u->header_in.pos; | 818 f->pos = u->buffer.pos; |
803 f->last = u->header_in.last; | 819 f->last = u->buffer.last; |
804 | 820 |
805 rc = ngx_http_fastcgi_process_record(r, f); | 821 rc = ngx_http_fastcgi_process_record(r, f); |
806 | 822 |
807 u->header_in.pos = f->pos; | 823 u->buffer.pos = f->pos; |
808 u->header_in.last = f->last; | 824 u->buffer.last = f->last; |
809 | 825 |
810 if (rc == NGX_AGAIN) { | 826 if (rc == NGX_AGAIN) { |
811 return NGX_AGAIN; | 827 return NGX_AGAIN; |
812 } | 828 } |
813 | 829 |
833 } | 849 } |
834 } | 850 } |
835 | 851 |
836 if (f->state == ngx_http_fastcgi_st_padding) { | 852 if (f->state == ngx_http_fastcgi_st_padding) { |
837 | 853 |
838 if (u->header_in.pos + f->padding < u->header_in.last) { | 854 if (u->buffer.pos + f->padding < u->buffer.last) { |
839 f->state = ngx_http_fastcgi_st_version; | 855 f->state = ngx_http_fastcgi_st_version; |
840 u->header_in.pos += f->padding; | 856 u->buffer.pos += f->padding; |
841 | 857 |
842 continue; | 858 continue; |
843 } | 859 } |
844 | 860 |
845 if (u->header_in.pos + f->padding == u->header_in.last) { | 861 if (u->buffer.pos + f->padding == u->buffer.last) { |
846 f->state = ngx_http_fastcgi_st_version; | 862 f->state = ngx_http_fastcgi_st_version; |
847 u->header_in.pos = u->header_in.last; | 863 u->buffer.pos = u->buffer.last; |
848 | 864 |
849 return NGX_AGAIN; | 865 return NGX_AGAIN; |
850 } | 866 } |
851 | 867 |
852 f->padding -= u->header_in.last - u->header_in.pos; | 868 f->padding -= u->buffer.last - u->buffer.pos; |
853 u->header_in.pos = u->header_in.last; | 869 u->buffer.pos = u->buffer.last; |
854 | 870 |
855 return NGX_AGAIN; | 871 return NGX_AGAIN; |
856 } | 872 } |
857 | 873 |
858 | 874 |
866 | 882 |
867 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | 883 return NGX_HTTP_UPSTREAM_INVALID_HEADER; |
868 } | 884 } |
869 | 885 |
870 if (f->length) { | 886 if (f->length) { |
871 line.data = u->header_in.pos; | 887 line.data = u->buffer.pos; |
872 | 888 |
873 if (u->header_in.pos + f->length <= u->header_in.last) { | 889 if (u->buffer.pos + f->length <= u->buffer.last) { |
874 line.len = f->length; | 890 line.len = f->length; |
875 u->header_in.pos += f->length; | 891 u->buffer.pos += f->length; |
876 f->length = 0; | 892 f->length = 0; |
877 f->state = ngx_http_fastcgi_st_padding; | 893 f->state = ngx_http_fastcgi_st_padding; |
878 | 894 |
879 } else { | 895 } else { |
880 line.len = u->header_in.last - u->header_in.pos; | 896 line.len = u->buffer.last - u->buffer.pos; |
881 f->length -= u->header_in.last - u->header_in.pos; | 897 f->length -= u->buffer.last - u->buffer.pos; |
882 u->header_in.pos = u->header_in.last; | 898 u->buffer.pos = u->buffer.last; |
883 } | 899 } |
884 | 900 |
885 while (line.data[line.len - 1] == LF | 901 while (line.data[line.len - 1] == LF |
886 || line.data[line.len - 1] == CR | 902 || line.data[line.len - 1] == CR |
887 || line.data[line.len - 1] == '.' | 903 || line.data[line.len - 1] == '.' |
891 } | 907 } |
892 | 908 |
893 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 909 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
894 "FastCGI sent in stderr: \"%V\"", &line); | 910 "FastCGI sent in stderr: \"%V\"", &line); |
895 | 911 |
896 if (u->header_in.pos == u->header_in.last) { | 912 if (u->buffer.pos == u->buffer.last) { |
897 return NGX_AGAIN; | 913 return NGX_AGAIN; |
898 } | 914 } |
899 | 915 |
900 } else { | 916 } else { |
901 f->state = ngx_http_fastcgi_st_version; | 917 f->state = ngx_http_fastcgi_st_version; |
905 } | 921 } |
906 | 922 |
907 | 923 |
908 /* f->type == NGX_HTTP_FASTCGI_STDOUT */ | 924 /* f->type == NGX_HTTP_FASTCGI_STDOUT */ |
909 | 925 |
910 start = u->header_in.pos; | 926 start = u->buffer.pos; |
911 | 927 |
912 if (u->header_in.pos + f->length < u->header_in.last) { | 928 if (u->buffer.pos + f->length < u->buffer.last) { |
913 | 929 |
914 /* | 930 /* |
915 * set u->header_in.last to the end of the FastCGI record data | 931 * set u->buffer.last to the end of the FastCGI record data |
916 * for ngx_http_parse_header_line() | 932 * for ngx_http_parse_header_line() |
917 */ | 933 */ |
918 | 934 |
919 last = u->header_in.last; | 935 last = u->buffer.last; |
920 u->header_in.last = u->header_in.pos + f->length; | 936 u->buffer.last = u->buffer.pos + f->length; |
921 | 937 |
922 } else { | 938 } else { |
923 last = NULL; | 939 last = NULL; |
924 } | 940 } |
925 | 941 |
926 f->header = 1; | 942 f->header = 1; |
927 | 943 |
928 for ( ;; ) { | 944 for ( ;; ) { |
929 | 945 |
930 rc = ngx_http_parse_header_line(r, &u->header_in); | 946 rc = ngx_http_parse_header_line(r, &u->buffer); |
931 | 947 |
932 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 948 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
933 "http fastcgi parser: %d", rc); | 949 "http fastcgi parser: %d", rc); |
934 | 950 |
935 if (rc == NGX_AGAIN) { | 951 if (rc == NGX_AGAIN) { |
1022 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | 1038 return NGX_HTTP_UPSTREAM_INVALID_HEADER; |
1023 | 1039 |
1024 } | 1040 } |
1025 | 1041 |
1026 if (last) { | 1042 if (last) { |
1027 u->header_in.last = last; | 1043 u->buffer.last = last; |
1028 } | 1044 } |
1029 | 1045 |
1030 f->length -= u->header_in.pos - start; | 1046 f->length -= u->buffer.pos - start; |
1031 | 1047 |
1032 if (rc == NGX_AGAIN) { | 1048 if (rc == NGX_AGAIN) { |
1033 if (u->header_in.pos == u->header_in.last) { | 1049 if (u->buffer.pos == u->buffer.last) { |
1034 return NGX_AGAIN; | 1050 return NGX_AGAIN; |
1035 } | 1051 } |
1036 | 1052 |
1037 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | 1053 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
1038 "upstream split a header in FastCGI records"); | 1054 "upstream split a header in FastCGI records"); |
1437 * | 1453 * |
1438 * conf->index.len = 0; | 1454 * conf->index.len = 0; |
1439 * conf->index.data = NULL; | 1455 * conf->index.data = NULL; |
1440 */ | 1456 */ |
1441 | 1457 |
1458 conf->upstream.buffering = NGX_CONF_UNSET; | |
1459 | |
1442 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC; | 1460 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC; |
1443 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC; | 1461 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC; |
1444 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC; | 1462 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC; |
1445 | 1463 |
1446 conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE; | 1464 conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE; |
1447 conf->upstream.header_buffer_size = NGX_CONF_UNSET_SIZE; | 1465 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE; |
1448 | 1466 |
1449 conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE; | 1467 conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE; |
1450 conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE; | 1468 conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE; |
1451 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE; | 1469 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE; |
1452 | 1470 |
1483 ngx_uint_t i; | 1501 ngx_uint_t i; |
1484 ngx_table_elt_t *src; | 1502 ngx_table_elt_t *src; |
1485 ngx_http_script_compile_t sc; | 1503 ngx_http_script_compile_t sc; |
1486 ngx_http_script_copy_code_t *copy; | 1504 ngx_http_script_copy_code_t *copy; |
1487 | 1505 |
1506 ngx_conf_merge_value(conf->upstream.buffering, | |
1507 prev->upstream.buffering, 1); | |
1508 | |
1488 ngx_conf_merge_msec_value(conf->upstream.connect_timeout, | 1509 ngx_conf_merge_msec_value(conf->upstream.connect_timeout, |
1489 prev->upstream.connect_timeout, 60000); | 1510 prev->upstream.connect_timeout, 60000); |
1490 | 1511 |
1491 ngx_conf_merge_msec_value(conf->upstream.send_timeout, | 1512 ngx_conf_merge_msec_value(conf->upstream.send_timeout, |
1492 prev->upstream.send_timeout, 60000); | 1513 prev->upstream.send_timeout, 60000); |
1495 prev->upstream.read_timeout, 60000); | 1516 prev->upstream.read_timeout, 60000); |
1496 | 1517 |
1497 ngx_conf_merge_size_value(conf->upstream.send_lowat, | 1518 ngx_conf_merge_size_value(conf->upstream.send_lowat, |
1498 prev->upstream.send_lowat, 0); | 1519 prev->upstream.send_lowat, 0); |
1499 | 1520 |
1500 ngx_conf_merge_size_value(conf->upstream.header_buffer_size, | 1521 ngx_conf_merge_size_value(conf->upstream.buffer_size, |
1501 prev->upstream.header_buffer_size, | 1522 prev->upstream.buffer_size, |
1502 (size_t) ngx_pagesize); | 1523 (size_t) ngx_pagesize); |
1503 | 1524 |
1504 | 1525 |
1505 ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs, | 1526 ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs, |
1506 8, ngx_pagesize); | 1527 8, ngx_pagesize); |
1510 "there must be at least 2 \"fastcgi_buffers\""); | 1531 "there must be at least 2 \"fastcgi_buffers\""); |
1511 return NGX_CONF_ERROR; | 1532 return NGX_CONF_ERROR; |
1512 } | 1533 } |
1513 | 1534 |
1514 | 1535 |
1515 size = conf->upstream.header_buffer_size; | 1536 size = conf->upstream.buffer_size; |
1516 if (size < conf->upstream.bufs.size) { | 1537 if (size < conf->upstream.bufs.size) { |
1517 size = conf->upstream.bufs.size; | 1538 size = conf->upstream.bufs.size; |
1518 } | 1539 } |
1519 | 1540 |
1520 | 1541 |