Mercurial > hg > nginx
comparison src/http/ngx_http_request.c @ 501:d4ea69372b94 release-0.1.25
nginx-0.1.25-RELEASE import
*) 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 <igor@sysoev.ru> |
---|---|
date | Sat, 19 Mar 2005 12:38:37 +0000 |
parents | 64d9afb209da |
children | b1648294f693 |
comparison
equal
deleted
inserted
replaced
500:9a0f304470f5 | 501:d4ea69372b94 |
---|---|
16 #endif | 16 #endif |
17 static void ngx_http_process_request_line(ngx_event_t *rev); | 17 static void ngx_http_process_request_line(ngx_event_t *rev); |
18 static void ngx_http_process_request_headers(ngx_event_t *rev); | 18 static void ngx_http_process_request_headers(ngx_event_t *rev); |
19 static ssize_t ngx_http_read_request_header(ngx_http_request_t *r); | 19 static ssize_t ngx_http_read_request_header(ngx_http_request_t *r); |
20 static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r, | 20 static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r, |
21 ngx_uint_t request_line); | 21 ngx_uint_t request_line); |
22 static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r); | 22 static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r); |
23 static ngx_int_t ngx_http_find_virtual_server(ngx_http_request_t *r); | 23 static ngx_int_t ngx_http_find_virtual_server(ngx_http_request_t *r); |
24 | 24 |
25 static void ngx_http_set_write_handler(ngx_http_request_t *r); | 25 static void ngx_http_set_write_handler(ngx_http_request_t *r); |
26 | 26 |
32 static void ngx_http_keepalive_handler(ngx_event_t *ev); | 32 static void ngx_http_keepalive_handler(ngx_event_t *ev); |
33 static void ngx_http_set_lingering_close(ngx_http_request_t *r); | 33 static void ngx_http_set_lingering_close(ngx_http_request_t *r); |
34 static void ngx_http_lingering_close_handler(ngx_event_t *ev); | 34 static void ngx_http_lingering_close_handler(ngx_event_t *ev); |
35 | 35 |
36 static void ngx_http_client_error(ngx_http_request_t *r, | 36 static void ngx_http_client_error(ngx_http_request_t *r, |
37 int client_error, int error); | 37 int client_error, int error); |
38 static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len); | 38 static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len); |
39 | 39 |
40 | 40 |
41 /* NGX_HTTP_PARSE_... errors */ | 41 /* NGX_HTTP_PARSE_... errors */ |
42 | 42 |
98 { ngx_null_string, 0 } | 98 { ngx_null_string, 0 } |
99 }; | 99 }; |
100 | 100 |
101 | 101 |
102 #if 0 | 102 #if 0 |
103 static void ngx_http_dummy(ngx_event_t *wev) | 103 static void |
104 ngx_http_dummy(ngx_event_t *wev) | |
104 { | 105 { |
105 return; | 106 return; |
106 } | 107 } |
107 #endif | 108 #endif |
108 | 109 |
109 | 110 |
110 void ngx_http_init_connection(ngx_connection_t *c) | 111 void |
112 ngx_http_init_connection(ngx_connection_t *c) | |
111 { | 113 { |
112 ngx_event_t *rev; | 114 ngx_event_t *rev; |
113 ngx_http_log_ctx_t *ctx; | 115 ngx_http_log_ctx_t *ctx; |
114 | 116 |
115 if (!(ctx = ngx_palloc(c->pool, sizeof(ngx_http_log_ctx_t)))) { | 117 ctx = ngx_palloc(c->pool, sizeof(ngx_http_log_ctx_t)); |
118 if (ctx == NULL) { | |
116 ngx_http_close_connection(c); | 119 ngx_http_close_connection(c); |
117 return; | 120 return; |
118 } | 121 } |
119 | 122 |
120 ctx->client = &c->addr_text; | 123 ctx->client = &c->addr_text; |
184 #endif | 187 #endif |
185 | 188 |
186 } | 189 } |
187 | 190 |
188 | 191 |
189 static void ngx_http_init_request(ngx_event_t *rev) | 192 static |
193 void ngx_http_init_request(ngx_event_t *rev) | |
190 { | 194 { |
191 ngx_uint_t i; | 195 ngx_uint_t i; |
192 socklen_t len; | 196 socklen_t len; |
193 struct sockaddr_in sin; | 197 struct sockaddr_in sin; |
194 ngx_connection_t *c; | 198 ngx_connection_t *c; |
223 #if (NGX_STAT_STUB) | 227 #if (NGX_STAT_STUB) |
224 ngx_atomic_inc(ngx_stat_reading); | 228 ngx_atomic_inc(ngx_stat_reading); |
225 #endif | 229 #endif |
226 | 230 |
227 } else { | 231 } else { |
228 if (!(hc = ngx_pcalloc(c->pool, sizeof(ngx_http_connection_t)))) { | 232 hc = ngx_pcalloc(c->pool, sizeof(ngx_http_connection_t)); |
233 if (hc == NULL) { | |
229 | 234 |
230 #if (NGX_STAT_STUB) | 235 #if (NGX_STAT_STUB) |
231 ngx_atomic_dec(ngx_stat_reading); | 236 ngx_atomic_dec(ngx_stat_reading); |
232 #endif | 237 #endif |
233 | 238 |
246 if (hc->nbusy) { | 251 if (hc->nbusy) { |
247 r->header_in = hc->busy[0]; | 252 r->header_in = hc->busy[0]; |
248 } | 253 } |
249 | 254 |
250 } else { | 255 } else { |
251 if (!(r = ngx_pcalloc(c->pool, sizeof(ngx_http_request_t)))) { | 256 r = ngx_pcalloc(c->pool, sizeof(ngx_http_request_t)); |
257 if (r == NULL) { | |
252 | 258 |
253 #if (NGX_STAT_STUB) | 259 #if (NGX_STAT_STUB) |
254 ngx_atomic_dec(ngx_stat_reading); | 260 ngx_atomic_dec(ngx_stat_reading); |
255 #endif | 261 #endif |
256 | 262 |
386 | 392 |
387 if (r->header_in == NULL) { | 393 if (r->header_in == NULL) { |
388 r->header_in = c->buffer; | 394 r->header_in = c->buffer; |
389 } | 395 } |
390 | 396 |
391 if (!(r->pool = ngx_create_pool(cscf->request_pool_size, c->log))) { | 397 r->pool = ngx_create_pool(cscf->request_pool_size, c->log); |
398 if (r->pool == NULL) { | |
392 ngx_http_close_connection(c); | 399 ngx_http_close_connection(c); |
393 return; | 400 return; |
394 } | 401 } |
395 | 402 |
396 if (ngx_array_init(&r->cleanup, r->pool, 4, sizeof(ngx_http_cleanup_t)) | 403 if (ngx_array_init(&r->cleanup, r->pool, 4, sizeof(ngx_http_cleanup_t)) |
442 } | 449 } |
443 | 450 |
444 | 451 |
445 #if (NGX_HTTP_SSL) | 452 #if (NGX_HTTP_SSL) |
446 | 453 |
447 static void ngx_http_ssl_handshake(ngx_event_t *rev) | 454 static void |
455 ngx_http_ssl_handshake(ngx_event_t *rev) | |
448 { | 456 { |
449 u_char buf[1]; | 457 u_char buf[1]; |
450 ssize_t n; | 458 ssize_t n; |
451 ngx_int_t rc; | 459 ngx_int_t rc; |
452 ngx_connection_t *c; | 460 ngx_connection_t *c; |
502 } | 510 } |
503 | 511 |
504 #endif | 512 #endif |
505 | 513 |
506 | 514 |
507 static void ngx_http_process_request_line(ngx_event_t *rev) | 515 static void |
516 ngx_http_process_request_line(ngx_event_t *rev) | |
508 { | 517 { |
509 ssize_t n; | 518 ssize_t n; |
510 ngx_int_t rc, rv; | 519 ngx_int_t rc, rv; |
511 ngx_connection_t *c; | 520 ngx_connection_t *c; |
512 ngx_http_request_t *r; | 521 ngx_http_request_t *r; |
552 } | 561 } |
553 | 562 |
554 | 563 |
555 if (r->complex_uri || r->quoted_uri) { | 564 if (r->complex_uri || r->quoted_uri) { |
556 | 565 |
557 if (!(r->uri.data = ngx_palloc(r->pool, r->uri.len + 1))) { | 566 r->uri.data = ngx_palloc(r->pool, r->uri.len + 1); |
567 if (r->uri.data == NULL) { | |
558 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 568 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
559 ngx_http_close_connection(c); | 569 ngx_http_close_connection(c); |
560 return; | 570 return; |
561 } | 571 } |
562 | 572 |
705 } | 715 } |
706 } | 716 } |
707 } | 717 } |
708 | 718 |
709 | 719 |
710 static void ngx_http_process_request_headers(ngx_event_t *rev) | 720 static void |
721 ngx_http_process_request_headers(ngx_event_t *rev) | |
711 { | 722 { |
712 ssize_t n; | 723 ssize_t n; |
713 ngx_int_t rc, rv, i; | 724 ngx_int_t rc, rv, i; |
714 ngx_table_elt_t *h, **cookie; | 725 ngx_table_elt_t *h, **cookie; |
715 ngx_connection_t *c; | 726 ngx_connection_t *c; |
762 | 773 |
763 /* a header line has been parsed successfully */ | 774 /* a header line has been parsed successfully */ |
764 | 775 |
765 r->headers_n++; | 776 r->headers_n++; |
766 | 777 |
767 if (!(h = ngx_list_push(&r->headers_in.headers))) { | 778 h = ngx_list_push(&r->headers_in.headers); |
779 if (h == NULL) { | |
768 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 780 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
769 ngx_http_close_connection(c); | 781 ngx_http_close_connection(c); |
770 return; | 782 return; |
771 } | 783 } |
772 | 784 |
779 h->value.data[h->value.len] = '\0'; | 791 h->value.data[h->value.len] = '\0'; |
780 | 792 |
781 if (h->key.len == sizeof("Cookie") - 1 | 793 if (h->key.len == sizeof("Cookie") - 1 |
782 && ngx_strcasecmp(h->key.data, "Cookie") == 0) | 794 && ngx_strcasecmp(h->key.data, "Cookie") == 0) |
783 { | 795 { |
784 if (!(cookie = ngx_array_push(&r->headers_in.cookies))) { | 796 cookie = ngx_array_push(&r->headers_in.cookies); |
797 if (cookie == NULL) { | |
785 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 798 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
786 ngx_http_close_connection(c); | 799 ngx_http_close_connection(c); |
787 return; | 800 return; |
788 } | 801 } |
789 | 802 |
877 | 890 |
878 } | 891 } |
879 } | 892 } |
880 | 893 |
881 | 894 |
882 static ssize_t ngx_http_read_request_header(ngx_http_request_t *r) | 895 static ssize_t |
896 ngx_http_read_request_header(ngx_http_request_t *r) | |
883 { | 897 { |
884 ssize_t n; | 898 ssize_t n; |
885 ngx_event_t *rev; | 899 ngx_event_t *rev; |
886 ngx_http_core_srv_conf_t *cscf; | 900 ngx_http_core_srv_conf_t *cscf; |
887 | 901 |
931 | 945 |
932 return n; | 946 return n; |
933 } | 947 } |
934 | 948 |
935 | 949 |
936 static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r, | 950 static ngx_int_t |
937 ngx_uint_t request_line) | 951 ngx_http_alloc_large_header_buffer(ngx_http_request_t *r, |
952 ngx_uint_t request_line) | |
938 { | 953 { |
939 u_char *old, *new; | 954 u_char *old, *new; |
940 ngx_buf_t *b; | 955 ngx_buf_t *b; |
941 ngx_http_connection_t *hc; | 956 ngx_http_connection_t *hc; |
942 ngx_http_core_srv_conf_t *cscf; | 957 ngx_http_core_srv_conf_t *cscf; |
1074 | 1089 |
1075 return NGX_OK; | 1090 return NGX_OK; |
1076 } | 1091 } |
1077 | 1092 |
1078 | 1093 |
1079 static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r) | 1094 static ngx_int_t |
1095 ngx_http_process_request_header(ngx_http_request_t *r) | |
1080 { | 1096 { |
1081 u_char *ua, *user_agent, ch; | 1097 u_char *ua, *user_agent, ch; |
1082 size_t len; | 1098 size_t len; |
1083 | 1099 |
1084 if (r->headers_in.host) { | 1100 if (r->headers_in.host) { |
1104 r->headers_in.host_name_len = 0; | 1120 r->headers_in.host_name_len = 0; |
1105 } | 1121 } |
1106 | 1122 |
1107 if (r->headers_in.content_length) { | 1123 if (r->headers_in.content_length) { |
1108 r->headers_in.content_length_n = | 1124 r->headers_in.content_length_n = |
1109 ngx_atoi(r->headers_in.content_length->value.data, | 1125 ngx_atosz(r->headers_in.content_length->value.data, |
1110 r->headers_in.content_length->value.len); | 1126 r->headers_in.content_length->value.len); |
1111 | 1127 |
1112 if (r->headers_in.content_length_n == NGX_ERROR) { | 1128 if (r->headers_in.content_length_n == NGX_ERROR) { |
1113 return NGX_HTTP_PARSE_INVALID_CL_HEADER; | 1129 return NGX_HTTP_PARSE_INVALID_CL_HEADER; |
1114 } | 1130 } |
1135 { | 1151 { |
1136 r->headers_in.connection_type = NGX_HTTP_CONNECTION_KEEP_ALIVE; | 1152 r->headers_in.connection_type = NGX_HTTP_CONNECTION_KEEP_ALIVE; |
1137 | 1153 |
1138 if (r->headers_in.keep_alive) { | 1154 if (r->headers_in.keep_alive) { |
1139 r->headers_in.keep_alive_n = | 1155 r->headers_in.keep_alive_n = |
1140 ngx_atoi(r->headers_in.keep_alive->value.data, | 1156 ngx_atotm(r->headers_in.keep_alive->value.data, |
1141 r->headers_in.keep_alive->value.len); | 1157 r->headers_in.keep_alive->value.len); |
1142 } | 1158 } |
1143 } | 1159 } |
1144 } | 1160 } |
1145 | 1161 |
1189 | 1205 |
1190 return NGX_OK; | 1206 return NGX_OK; |
1191 } | 1207 } |
1192 | 1208 |
1193 | 1209 |
1194 static ngx_int_t ngx_http_find_virtual_server(ngx_http_request_t *r) | 1210 static ngx_int_t |
1211 ngx_http_find_virtual_server(ngx_http_request_t *r) | |
1195 { | 1212 { |
1196 ngx_int_t rc; | 1213 ngx_int_t rc; |
1197 ngx_uint_t i, n, key, found; | 1214 ngx_uint_t i, n, key, found; |
1198 ngx_http_server_name_t *name; | 1215 ngx_http_server_name_t *name; |
1199 ngx_http_core_main_conf_t *cmcf; | 1216 ngx_http_core_main_conf_t *cmcf; |
1295 | 1312 |
1296 return NGX_OK; | 1313 return NGX_OK; |
1297 } | 1314 } |
1298 | 1315 |
1299 | 1316 |
1300 void ngx_http_finalize_request(ngx_http_request_t *r, int rc) | 1317 void |
1318 ngx_http_finalize_request(ngx_http_request_t *r, int rc) | |
1301 { | 1319 { |
1302 ngx_http_core_loc_conf_t *clcf; | 1320 ngx_http_core_loc_conf_t *clcf; |
1303 | 1321 |
1304 /* r may be already destroyed when rc == NGX_DONE */ | 1322 /* r may be already destroyed when rc == NGX_DONE */ |
1305 | 1323 |
1378 ngx_http_close_request(r, 0); | 1396 ngx_http_close_request(r, 0); |
1379 ngx_http_close_connection(r->connection); | 1397 ngx_http_close_connection(r->connection); |
1380 } | 1398 } |
1381 | 1399 |
1382 | 1400 |
1383 static void ngx_http_set_write_handler(ngx_http_request_t *r) | 1401 static void |
1402 ngx_http_set_write_handler(ngx_http_request_t *r) | |
1384 { | 1403 { |
1385 ngx_event_t *wev; | 1404 ngx_event_t *wev; |
1386 ngx_http_core_loc_conf_t *clcf; | 1405 ngx_http_core_loc_conf_t *clcf; |
1387 | 1406 |
1388 wev = r->connection->write; | 1407 wev = r->connection->write; |
1407 | 1426 |
1408 return; | 1427 return; |
1409 } | 1428 } |
1410 | 1429 |
1411 | 1430 |
1412 void ngx_http_writer(ngx_event_t *wev) | 1431 void |
1432 ngx_http_writer(ngx_event_t *wev) | |
1413 { | 1433 { |
1414 int rc; | 1434 int rc; |
1415 ngx_connection_t *c; | 1435 ngx_connection_t *c; |
1416 ngx_http_request_t *r; | 1436 ngx_http_request_t *r; |
1417 ngx_http_core_loc_conf_t *clcf; | 1437 ngx_http_core_loc_conf_t *clcf; |
1484 | 1504 |
1485 ngx_http_finalize_request(r, rc); | 1505 ngx_http_finalize_request(r, rc); |
1486 } | 1506 } |
1487 | 1507 |
1488 | 1508 |
1489 static void ngx_http_block_read(ngx_event_t *rev) | 1509 static void |
1510 ngx_http_block_read(ngx_event_t *rev) | |
1490 { | 1511 { |
1491 ngx_connection_t *c; | 1512 ngx_connection_t *c; |
1492 ngx_http_request_t *r; | 1513 ngx_http_request_t *r; |
1493 | 1514 |
1494 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http read blocked"); | 1515 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http read blocked"); |
1504 } | 1525 } |
1505 } | 1526 } |
1506 } | 1527 } |
1507 | 1528 |
1508 | 1529 |
1509 ngx_int_t ngx_http_discard_body(ngx_http_request_t *r) | 1530 ngx_int_t |
1531 ngx_http_discard_body(ngx_http_request_t *r) | |
1510 { | 1532 { |
1511 ssize_t size; | 1533 ssize_t size; |
1512 ngx_event_t *rev; | 1534 ngx_event_t *rev; |
1513 | 1535 |
1514 rev = r->connection->read; | 1536 rev = r->connection->read; |
1544 | 1566 |
1545 return ngx_http_read_discarded_body(r); | 1567 return ngx_http_read_discarded_body(r); |
1546 } | 1568 } |
1547 | 1569 |
1548 | 1570 |
1549 static void ngx_http_read_discarded_body_event(ngx_event_t *rev) | 1571 static void |
1572 ngx_http_read_discarded_body_event(ngx_event_t *rev) | |
1550 { | 1573 { |
1551 ngx_int_t rc; | 1574 ngx_int_t rc; |
1552 ngx_connection_t *c; | 1575 ngx_connection_t *c; |
1553 ngx_http_request_t *r; | 1576 ngx_http_request_t *r; |
1554 | 1577 |
1570 ngx_http_close_connection(c); | 1593 ngx_http_close_connection(c); |
1571 } | 1594 } |
1572 } | 1595 } |
1573 | 1596 |
1574 | 1597 |
1575 static ngx_int_t ngx_http_read_discarded_body(ngx_http_request_t *r) | 1598 static ngx_int_t |
1599 ngx_http_read_discarded_body(ngx_http_request_t *r) | |
1576 { | 1600 { |
1577 ssize_t size, n; | 1601 ssize_t size, n; |
1578 u_char buffer[NGX_HTTP_DISCARD_BUFFER_SIZE]; | 1602 u_char buffer[NGX_HTTP_DISCARD_BUFFER_SIZE]; |
1579 | 1603 |
1580 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1604 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1613 | 1637 |
1614 return NGX_OK; | 1638 return NGX_OK; |
1615 } | 1639 } |
1616 | 1640 |
1617 | 1641 |
1618 static void ngx_http_set_keepalive(ngx_http_request_t *r) | 1642 static void |
1643 ngx_http_set_keepalive(ngx_http_request_t *r) | |
1619 { | 1644 { |
1620 int tcp_nodelay; | 1645 int tcp_nodelay; |
1621 ngx_int_t i; | 1646 ngx_int_t i; |
1622 ngx_buf_t *b, *f; | 1647 ngx_buf_t *b, *f; |
1623 ngx_event_t *rev, *wev; | 1648 ngx_event_t *rev, *wev; |
1774 } | 1799 } |
1775 | 1800 |
1776 c->log->action = "keepalive"; | 1801 c->log->action = "keepalive"; |
1777 | 1802 |
1778 if (c->tcp_nopush == NGX_TCP_NOPUSH_SET) { | 1803 if (c->tcp_nopush == NGX_TCP_NOPUSH_SET) { |
1779 if (ngx_tcp_push(c->fd) == NGX_ERROR) { | 1804 if (ngx_tcp_push(c->fd) == -1) { |
1780 ngx_connection_error(c, ngx_socket_errno, ngx_tcp_push_n " failed"); | 1805 ngx_connection_error(c, ngx_socket_errno, ngx_tcp_push_n " failed"); |
1781 ngx_http_close_connection(c); | 1806 ngx_http_close_connection(c); |
1782 return; | 1807 return; |
1783 } | 1808 } |
1784 | 1809 |
1816 ngx_http_keepalive_handler(rev); | 1841 ngx_http_keepalive_handler(rev); |
1817 } | 1842 } |
1818 } | 1843 } |
1819 | 1844 |
1820 | 1845 |
1821 static void ngx_http_keepalive_handler(ngx_event_t *rev) | 1846 static void |
1822 { | 1847 ngx_http_keepalive_handler(ngx_event_t *rev) |
1823 size_t size; | 1848 { |
1824 ssize_t n; | 1849 size_t size; |
1825 ngx_buf_t *b; | 1850 ssize_t n; |
1826 ngx_connection_t *c; | 1851 ngx_buf_t *b; |
1827 ngx_http_connection_t *hc; | 1852 ngx_connection_t *c; |
1828 | 1853 |
1829 c = rev->data; | 1854 c = rev->data; |
1830 | 1855 |
1831 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http keepalive handler"); | 1856 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http keepalive handler"); |
1832 | 1857 |
1853 } | 1878 } |
1854 } | 1879 } |
1855 | 1880 |
1856 #endif | 1881 #endif |
1857 | 1882 |
1858 hc = c->data; | |
1859 b = c->buffer; | 1883 b = c->buffer; |
1860 size = b->end - b->start; | 1884 size = b->end - b->start; |
1861 | 1885 |
1862 if (b->pos == NULL) { | 1886 if (b->pos == NULL) { |
1863 | 1887 |
1865 * The c->buffer's memory was freed by ngx_http_set_keepalive(). | 1889 * The c->buffer's memory was freed by ngx_http_set_keepalive(). |
1866 * However, the c->buffer->start and c->buffer->end were not changed | 1890 * However, the c->buffer->start and c->buffer->end were not changed |
1867 * to keep the buffer size. | 1891 * to keep the buffer size. |
1868 */ | 1892 */ |
1869 | 1893 |
1870 if (!(b->pos = ngx_palloc(c->pool, size))) { | 1894 b->pos = ngx_palloc(c->pool, size); |
1895 if (b->pos == NULL) { | |
1871 ngx_http_close_connection(c); | 1896 ngx_http_close_connection(c); |
1872 return; | 1897 return; |
1873 } | 1898 } |
1874 | 1899 |
1875 b->start = b->pos; | 1900 b->start = b->pos; |
1917 | 1942 |
1918 ngx_http_init_request(rev); | 1943 ngx_http_init_request(rev); |
1919 } | 1944 } |
1920 | 1945 |
1921 | 1946 |
1922 static void ngx_http_set_lingering_close(ngx_http_request_t *r) | 1947 static void |
1948 ngx_http_set_lingering_close(ngx_http_request_t *r) | |
1923 { | 1949 { |
1924 ngx_event_t *rev, *wev; | 1950 ngx_event_t *rev, *wev; |
1925 ngx_connection_t *c; | 1951 ngx_connection_t *c; |
1926 ngx_http_core_loc_conf_t *clcf; | 1952 ngx_http_core_loc_conf_t *clcf; |
1927 | 1953 |
1975 ngx_http_lingering_close_handler(rev); | 2001 ngx_http_lingering_close_handler(rev); |
1976 } | 2002 } |
1977 } | 2003 } |
1978 | 2004 |
1979 | 2005 |
1980 static void ngx_http_lingering_close_handler(ngx_event_t *rev) | 2006 static void |
2007 ngx_http_lingering_close_handler(ngx_event_t *rev) | |
1981 { | 2008 { |
1982 ssize_t n; | 2009 ssize_t n; |
1983 ngx_msec_t timer; | 2010 ngx_msec_t timer; |
1984 ngx_connection_t *c; | 2011 ngx_connection_t *c; |
1985 ngx_http_request_t *r; | 2012 ngx_http_request_t *r; |
2034 | 2061 |
2035 ngx_add_timer(rev, timer); | 2062 ngx_add_timer(rev, timer); |
2036 } | 2063 } |
2037 | 2064 |
2038 | 2065 |
2039 void ngx_http_empty_handler(ngx_event_t *wev) | 2066 void |
2067 ngx_http_empty_handler(ngx_event_t *wev) | |
2040 { | 2068 { |
2041 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0, "http empty handler"); | 2069 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0, "http empty handler"); |
2042 | 2070 |
2043 return; | 2071 return; |
2044 } | 2072 } |
2045 | 2073 |
2046 | 2074 |
2047 ngx_int_t ngx_http_send_last(ngx_http_request_t *r) | 2075 ngx_int_t |
2076 ngx_http_send_last(ngx_http_request_t *r) | |
2048 { | 2077 { |
2049 ngx_buf_t *b; | 2078 ngx_buf_t *b; |
2050 ngx_chain_t out; | 2079 ngx_chain_t out; |
2051 | 2080 |
2052 if (!(b = ngx_calloc_buf(r->pool))) { | 2081 b = ngx_calloc_buf(r->pool); |
2082 if (b == NULL) { | |
2053 return NGX_ERROR; | 2083 return NGX_ERROR; |
2054 } | 2084 } |
2055 | 2085 |
2056 b->last_buf = 1; | 2086 b->last_buf = 1; |
2057 out.buf = b; | 2087 out.buf = b; |
2059 | 2089 |
2060 return ngx_http_output_filter(r, &out); | 2090 return ngx_http_output_filter(r, &out); |
2061 } | 2091 } |
2062 | 2092 |
2063 | 2093 |
2064 void ngx_http_close_request(ngx_http_request_t *r, int error) | 2094 void |
2095 ngx_http_close_request(ngx_http_request_t *r, int error) | |
2065 { | 2096 { |
2066 ngx_uint_t i; | 2097 ngx_uint_t i; |
2067 ngx_log_t *log; | 2098 ngx_log_t *log; |
2068 ngx_http_log_ctx_t *ctx; | 2099 ngx_http_log_ctx_t *ctx; |
2069 ngx_http_cleanup_t *cleanup; | 2100 ngx_http_cleanup_t *cleanup; |
2169 } | 2200 } |
2170 | 2201 |
2171 | 2202 |
2172 #if (NGX_HTTP_SSL) | 2203 #if (NGX_HTTP_SSL) |
2173 | 2204 |
2174 void ngx_ssl_close_handler(ngx_event_t *ev) | 2205 void |
2206 ngx_ssl_close_handler(ngx_event_t *ev) | |
2175 { | 2207 { |
2176 ngx_connection_t *c; | 2208 ngx_connection_t *c; |
2177 | 2209 |
2178 c = ev->data; | 2210 c = ev->data; |
2179 | 2211 |
2187 } | 2219 } |
2188 | 2220 |
2189 #endif | 2221 #endif |
2190 | 2222 |
2191 | 2223 |
2192 void ngx_http_close_connection(ngx_connection_t *c) | 2224 void |
2225 ngx_http_close_connection(ngx_connection_t *c) | |
2193 { | 2226 { |
2194 ngx_pool_t *pool; | 2227 ngx_pool_t *pool; |
2195 | 2228 |
2196 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | 2229 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
2197 "close http connection: %d", c->fd); | 2230 "close http connection: %d", c->fd); |
2214 | 2247 |
2215 pool = c->pool; | 2248 pool = c->pool; |
2216 | 2249 |
2217 ngx_close_connection(c); | 2250 ngx_close_connection(c); |
2218 | 2251 |
2219 ngx_destroy_pool(c->pool); | 2252 ngx_destroy_pool(pool); |
2220 } | 2253 } |
2221 | 2254 |
2222 | 2255 |
2223 static void ngx_http_client_error(ngx_http_request_t *r, | 2256 static void |
2224 int client_error, int error) | 2257 ngx_http_client_error(ngx_http_request_t *r, int client_error, int error) |
2225 { | 2258 { |
2226 u_char *p; | 2259 u_char *p; |
2227 ngx_http_log_ctx_t *ctx; | 2260 ngx_http_log_ctx_t *ctx; |
2228 ngx_http_core_srv_conf_t *cscf; | 2261 ngx_http_core_srv_conf_t *cscf; |
2229 | 2262 |
2313 | 2346 |
2314 ngx_http_finalize_request(r, error); | 2347 ngx_http_finalize_request(r, error); |
2315 } | 2348 } |
2316 | 2349 |
2317 | 2350 |
2318 static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len) | 2351 static u_char * |
2352 ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len) | |
2319 { | 2353 { |
2320 u_char *p; | 2354 u_char *p; |
2321 ngx_http_log_ctx_t *ctx; | 2355 ngx_http_log_ctx_t *ctx; |
2322 | 2356 |
2323 p = buf; | 2357 p = buf; |