Mercurial > hg > nginx-vendor-0-7
comparison src/http/ngx_http_request.c @ 118:644a7935144b NGINX_0_3_6
nginx 0.3.6
*) Change: now the IMAP/POP3 proxy do not send the empty login to
authorization server.
*) Feature: the "log_format" supports the variables in the $name form.
*) Bugfix: if at least in one server was no the "listen" directive,
then nginx did not listen on the 80 port; bug appeared in 0.3.3.
*) Bugfix: if the URI part is omitted in "proxy_pass" directive, the
the 80 port was always used.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 24 Oct 2005 00:00:00 +0400 |
parents | e38f51cd0905 |
children | d25a1d6034f1 |
comparison
equal
deleted
inserted
replaced
117:0821ea4ccfc5 | 118:644a7935144b |
---|---|
39 static void ngx_http_set_keepalive(ngx_http_request_t *r); | 39 static void ngx_http_set_keepalive(ngx_http_request_t *r); |
40 static void ngx_http_keepalive_handler(ngx_event_t *ev); | 40 static void ngx_http_keepalive_handler(ngx_event_t *ev); |
41 static void ngx_http_set_lingering_close(ngx_http_request_t *r); | 41 static void ngx_http_set_lingering_close(ngx_http_request_t *r); |
42 static void ngx_http_lingering_close_handler(ngx_event_t *ev); | 42 static void ngx_http_lingering_close_handler(ngx_event_t *ev); |
43 static void ngx_http_close_request(ngx_http_request_t *r, ngx_int_t error); | 43 static void ngx_http_close_request(ngx_http_request_t *r, ngx_int_t error); |
44 static void ngx_http_request_done(ngx_http_request_t *r, ngx_int_t error); | |
44 static void ngx_http_close_connection(ngx_connection_t *c); | 45 static void ngx_http_close_connection(ngx_connection_t *c); |
45 | 46 |
46 static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len); | 47 static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len); |
47 static u_char *ngx_http_log_error_handler(ngx_http_request_t *r, u_char *buf, | 48 static u_char *ngx_http_log_error_handler(ngx_http_request_t *r, u_char *buf, |
48 size_t len); | 49 size_t len); |
154 | 155 |
155 c->log_error = NGX_ERROR_INFO; | 156 c->log_error = NGX_ERROR_INFO; |
156 | 157 |
157 rev = c->read; | 158 rev = c->read; |
158 rev->handler = ngx_http_init_request; | 159 rev->handler = ngx_http_init_request; |
159 | 160 c->write->handler = ngx_http_empty_handler; |
160 /* STUB: epoll edge */ c->write->handler = ngx_http_empty_handler; | |
161 | 161 |
162 #if (NGX_STAT_STUB) | 162 #if (NGX_STAT_STUB) |
163 ngx_atomic_fetch_add(ngx_stat_reading, 1); | 163 ngx_atomic_fetch_add(ngx_stat_reading, 1); |
164 #endif | 164 #endif |
165 | 165 |
372 | 372 |
373 if (ngx_list_init(&r->headers_out.headers, r->pool, 20, | 373 if (ngx_list_init(&r->headers_out.headers, r->pool, 20, |
374 sizeof(ngx_table_elt_t)) == NGX_ERROR) | 374 sizeof(ngx_table_elt_t)) == NGX_ERROR) |
375 { | 375 { |
376 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 376 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
377 ngx_http_close_connection(c); | |
378 return; | 377 return; |
379 } | 378 } |
380 | 379 |
381 | 380 |
382 r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module); | 381 r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module); |
383 if (r->ctx == NULL) { | 382 if (r->ctx == NULL) { |
384 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 383 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
385 ngx_http_close_connection(c); | |
386 return; | 384 return; |
387 } | 385 } |
388 | 386 |
389 c->single_connection = 1; | 387 c->single_connection = 1; |
390 r->connection = c; | 388 r->connection = c; |
433 | 431 |
434 if (rev->timedout) { | 432 if (rev->timedout) { |
435 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); | 433 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); |
436 c->timedout = 1; | 434 c->timedout = 1; |
437 ngx_http_close_request(r, NGX_HTTP_REQUEST_TIME_OUT); | 435 ngx_http_close_request(r, NGX_HTTP_REQUEST_TIME_OUT); |
438 ngx_http_close_connection(c); | |
439 return; | 436 return; |
440 } | 437 } |
441 | 438 |
442 n = recv(c->fd, buf, 1, MSG_PEEK); | 439 n = recv(c->fd, buf, 1, MSG_PEEK); |
443 | 440 |
500 } | 497 } |
501 | 498 |
502 r = c->data; | 499 r = c->data; |
503 | 500 |
504 ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST); | 501 ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST); |
505 ngx_http_close_connection(r->connection); | |
506 | 502 |
507 return; | 503 return; |
508 } | 504 } |
509 | 505 |
510 | 506 |
528 | 524 |
529 if (rev->timedout) { | 525 if (rev->timedout) { |
530 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); | 526 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); |
531 c->timedout = 1; | 527 c->timedout = 1; |
532 ngx_http_close_request(r, NGX_HTTP_REQUEST_TIME_OUT); | 528 ngx_http_close_request(r, NGX_HTTP_REQUEST_TIME_OUT); |
533 ngx_http_close_connection(c); | |
534 return; | 529 return; |
535 } | 530 } |
536 | 531 |
537 rc = NGX_AGAIN; | 532 rc = NGX_AGAIN; |
538 | 533 |
566 if (r->complex_uri || r->quoted_uri) { | 561 if (r->complex_uri || r->quoted_uri) { |
567 | 562 |
568 r->uri.data = ngx_palloc(r->pool, r->uri.len + 1); | 563 r->uri.data = ngx_palloc(r->pool, r->uri.len + 1); |
569 if (r->uri.data == NULL) { | 564 if (r->uri.data == NULL) { |
570 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 565 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
571 ngx_http_close_connection(c); | |
572 return; | 566 return; |
573 } | 567 } |
574 | 568 |
575 rc = ngx_http_parse_complex_uri(r); | 569 rc = ngx_http_parse_complex_uri(r); |
576 | 570 |
653 | 647 |
654 if (ngx_list_init(&r->headers_in.headers, r->pool, 20, | 648 if (ngx_list_init(&r->headers_in.headers, r->pool, 20, |
655 sizeof(ngx_table_elt_t)) == NGX_ERROR) | 649 sizeof(ngx_table_elt_t)) == NGX_ERROR) |
656 { | 650 { |
657 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 651 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
658 ngx_http_close_connection(c); | |
659 return; | 652 return; |
660 } | 653 } |
661 | 654 |
662 | 655 |
663 if (ngx_array_init(&r->headers_in.cookies, r->pool, 2, | 656 if (ngx_array_init(&r->headers_in.cookies, r->pool, 2, |
664 sizeof(ngx_table_elt_t *)) == NGX_ERROR) | 657 sizeof(ngx_table_elt_t *)) == NGX_ERROR) |
665 { | 658 { |
666 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 659 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
667 ngx_http_close_connection(c); | |
668 return; | 660 return; |
669 } | 661 } |
670 | 662 |
671 c->log->action = "reading client request headers"; | 663 c->log->action = "reading client request headers"; |
672 | 664 |
692 | 684 |
693 rv = ngx_http_alloc_large_header_buffer(r, 1); | 685 rv = ngx_http_alloc_large_header_buffer(r, 1); |
694 | 686 |
695 if (rv == NGX_ERROR) { | 687 if (rv == NGX_ERROR) { |
696 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 688 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
697 ngx_http_close_connection(c); | |
698 return; | 689 return; |
699 } | 690 } |
700 | 691 |
701 if (rv == NGX_DECLINED) { | 692 if (rv == NGX_DECLINED) { |
702 ctx = c->log->data; | 693 ctx = c->log->data; |
737 | 728 |
738 if (rev->timedout) { | 729 if (rev->timedout) { |
739 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); | 730 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); |
740 c->timedout = 1; | 731 c->timedout = 1; |
741 ngx_http_close_request(r, NGX_HTTP_REQUEST_TIME_OUT); | 732 ngx_http_close_request(r, NGX_HTTP_REQUEST_TIME_OUT); |
742 ngx_http_close_connection(c); | |
743 return; | 733 return; |
744 } | 734 } |
745 | 735 |
746 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | 736 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); |
747 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | 737 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
757 | 747 |
758 rv = ngx_http_alloc_large_header_buffer(r, 0); | 748 rv = ngx_http_alloc_large_header_buffer(r, 0); |
759 | 749 |
760 if (rv == NGX_ERROR) { | 750 if (rv == NGX_ERROR) { |
761 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 751 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
762 ngx_http_close_connection(c); | |
763 return; | 752 return; |
764 } | 753 } |
765 | 754 |
766 if (rv == NGX_DECLINED) { | 755 if (rv == NGX_DECLINED) { |
767 header.len = r->header_in->end - r->header_name_start; | 756 header.len = r->header_in->end - r->header_name_start; |
776 | 765 |
777 ngx_log_error(NGX_LOG_INFO, c->log, 0, | 766 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
778 "client sent too long header line: \"%V\"", | 767 "client sent too long header line: \"%V\"", |
779 &header); | 768 &header); |
780 ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST); | 769 ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST); |
781 ngx_http_close_connection(c); | |
782 return; | 770 return; |
783 } | 771 } |
784 } | 772 } |
785 | 773 |
786 n = ngx_http_read_request_header(r); | 774 n = ngx_http_read_request_header(r); |
810 /* a header line has been parsed successfully */ | 798 /* a header line has been parsed successfully */ |
811 | 799 |
812 h = ngx_list_push(&r->headers_in.headers); | 800 h = ngx_list_push(&r->headers_in.headers); |
813 if (h == NULL) { | 801 if (h == NULL) { |
814 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 802 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
815 ngx_http_close_connection(c); | |
816 return; | 803 return; |
817 } | 804 } |
818 | 805 |
819 h->hash = r->header_hash; | 806 h->hash = r->header_hash; |
820 | 807 |
893 header.data = r->header_name_start; | 880 header.data = r->header_name_start; |
894 ngx_log_error(NGX_LOG_INFO, c->log, 0, | 881 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
895 "client sent invalid header line: \"%V\\r...\"", | 882 "client sent invalid header line: \"%V\\r...\"", |
896 &header); | 883 &header); |
897 ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST); | 884 ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST); |
898 ngx_http_close_connection(c); | |
899 return; | 885 return; |
900 } | 886 } |
901 } | 887 } |
902 | 888 |
903 | 889 |
930 r->header_timeout_set = 1; | 916 r->header_timeout_set = 1; |
931 } | 917 } |
932 | 918 |
933 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { | 919 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { |
934 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 920 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
935 ngx_http_close_connection(r->connection); | |
936 return NGX_ERROR; | 921 return NGX_ERROR; |
937 } | 922 } |
938 | 923 |
939 return NGX_AGAIN; | 924 return NGX_AGAIN; |
940 } | 925 } |
944 "client closed prematurely connection"); | 929 "client closed prematurely connection"); |
945 } | 930 } |
946 | 931 |
947 if (n == 0 || n == NGX_ERROR) { | 932 if (n == 0 || n == NGX_ERROR) { |
948 ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST); | 933 ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST); |
949 ngx_http_close_connection(r->connection); | |
950 return NGX_ERROR; | 934 return NGX_ERROR; |
951 } | 935 } |
952 | 936 |
953 r->header_in->last += n; | 937 r->header_in->last += n; |
954 | 938 |
1150 *cookie = h; | 1134 *cookie = h; |
1151 return NGX_OK; | 1135 return NGX_OK; |
1152 } | 1136 } |
1153 | 1137 |
1154 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 1138 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
1155 ngx_http_close_connection(r->connection); | |
1156 | 1139 |
1157 return NGX_ERROR; | 1140 return NGX_ERROR; |
1158 } | 1141 } |
1159 | 1142 |
1160 | 1143 |
1188 | 1171 |
1189 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | 1172 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
1190 | 1173 |
1191 if (cscf->restrict_host_names == NGX_HTTP_RESTRICT_HOST_CLOSE) { | 1174 if (cscf->restrict_host_names == NGX_HTTP_RESTRICT_HOST_CLOSE) { |
1192 ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST); | 1175 ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST); |
1193 ngx_http_close_connection(r->connection); | |
1194 return NGX_ERROR; | 1176 return NGX_ERROR; |
1195 } | 1177 } |
1196 | 1178 |
1197 ngx_http_finalize_request(r, NGX_HTTP_INVALID_HOST); | 1179 ngx_http_finalize_request(r, NGX_HTTP_INVALID_HOST); |
1198 return NGX_ERROR; | 1180 return NGX_ERROR; |
1430 { | 1412 { |
1431 ngx_http_request_t *pr; | 1413 ngx_http_request_t *pr; |
1432 ngx_http_core_loc_conf_t *clcf; | 1414 ngx_http_core_loc_conf_t *clcf; |
1433 | 1415 |
1434 if (rc == NGX_DONE) { | 1416 if (rc == NGX_DONE) { |
1435 /* r may be already destroyed when rc == NGX_DONE */ | 1417 /* the request pool may be already destroyed */ |
1436 return; | 1418 return; |
1437 } | 1419 } |
1438 | 1420 |
1439 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1421 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1440 "http finalize request: %d, \"%V\"", rc, &r->uri); | 1422 "http finalize request: %d, \"%V\"", rc, &r->uri); |
1441 | 1423 |
1442 if (r->parent | 1424 if (rc == NGX_ERROR || r->connection->closed) { |
1443 && (rc >= NGX_HTTP_SPECIAL_RESPONSE || rc == NGX_HTTP_NO_CONTENT)) | 1425 ngx_http_close_request(r, 0); |
1444 { | 1426 return; |
1427 } | |
1428 | |
1429 if (rc >= NGX_HTTP_SPECIAL_RESPONSE || rc == NGX_HTTP_NO_CONTENT) { | |
1430 | |
1431 if (r->main == r) { | |
1432 if (r->connection->read->timer_set) { | |
1433 ngx_del_timer(r->connection->read); | |
1434 } | |
1435 | |
1436 if (r->connection->write->timer_set) { | |
1437 ngx_del_timer(r->connection->write); | |
1438 } | |
1439 } | |
1440 | |
1445 ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc)); | 1441 ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc)); |
1446 return; | 1442 |
1447 } | 1443 return; |
1448 | 1444 } |
1449 if (r->parent || rc == NGX_AGAIN) { | 1445 |
1446 if (r->main != r || rc == NGX_AGAIN) { | |
1450 if (ngx_http_set_write_handler(r) != NGX_OK) { | 1447 if (ngx_http_set_write_handler(r) != NGX_OK) { |
1451 return; | 1448 return; |
1452 } | 1449 } |
1453 } | 1450 } |
1454 | 1451 |
1458 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1455 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1459 "http finalize non-active request: \"%V\"", &r->uri); | 1456 "http finalize non-active request: \"%V\"", &r->uri); |
1460 return; | 1457 return; |
1461 } | 1458 } |
1462 | 1459 |
1463 if (r->parent) { | 1460 if (r->main != r) { |
1464 | 1461 |
1465 pr = r->parent; | 1462 pr = r->parent; |
1466 | 1463 |
1467 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1464 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1468 "http parent request: \"%V\"", &pr->uri); | 1465 "http parent request: \"%V\"", &pr->uri); |
1497 } | 1494 } |
1498 | 1495 |
1499 return; | 1496 return; |
1500 } | 1497 } |
1501 | 1498 |
1502 if (rc >= NGX_HTTP_SPECIAL_RESPONSE || rc == NGX_HTTP_NO_CONTENT) { | 1499 if (rc == NGX_AGAIN) { |
1503 | 1500 return; |
1504 if (r->connection->read->timer_set) { | 1501 } |
1505 ngx_del_timer(r->connection->read); | 1502 |
1506 } | 1503 if (r->out) { |
1507 | |
1508 if (r->connection->write->timer_set) { | |
1509 ngx_del_timer(r->connection->write); | |
1510 } | |
1511 | |
1512 if (r->connection->closed) { | |
1513 ngx_http_close_request(r, 0); | |
1514 ngx_http_close_connection(r->connection); | |
1515 return; | |
1516 } | |
1517 | |
1518 ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc)); | |
1519 | |
1520 return; | |
1521 } | |
1522 | |
1523 if (rc == NGX_ERROR || r->connection->closed) { | |
1524 ngx_http_close_request(r, 0); | |
1525 ngx_http_close_connection(r->connection); | |
1526 return; | |
1527 } | |
1528 | |
1529 if (rc == NGX_AGAIN || r->out) { | |
1530 (void) ngx_http_set_write_handler(r); | 1504 (void) ngx_http_set_write_handler(r); |
1531 return; | 1505 return; |
1532 } | 1506 } |
1533 | 1507 |
1534 if (r->connection->read->timer_set) { | 1508 if (r->connection->read->timer_set) { |
1545 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, | 1519 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, |
1546 r->connection->read->kq_errno, | 1520 r->connection->read->kq_errno, |
1547 "kevent() reported about an closed connection"); | 1521 "kevent() reported about an closed connection"); |
1548 #endif | 1522 #endif |
1549 ngx_http_close_request(r, 0); | 1523 ngx_http_close_request(r, 0); |
1550 ngx_http_close_connection(r->connection); | |
1551 return; | 1524 return; |
1552 } | 1525 } |
1553 | 1526 |
1554 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 1527 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
1555 | 1528 |
1565 ngx_http_set_lingering_close(r); | 1538 ngx_http_set_lingering_close(r); |
1566 return; | 1539 return; |
1567 } | 1540 } |
1568 | 1541 |
1569 ngx_http_close_request(r, 0); | 1542 ngx_http_close_request(r, 0); |
1570 ngx_http_close_connection(r->connection); | |
1571 } | 1543 } |
1572 | 1544 |
1573 | 1545 |
1574 static ngx_int_t | 1546 static ngx_int_t |
1575 ngx_http_set_write_handler(ngx_http_request_t *r) | 1547 ngx_http_set_write_handler(ngx_http_request_t *r) |
1578 ngx_http_core_loc_conf_t *clcf; | 1550 ngx_http_core_loc_conf_t *clcf; |
1579 | 1551 |
1580 r->http_state = NGX_HTTP_WRITING_REQUEST_STATE; | 1552 r->http_state = NGX_HTTP_WRITING_REQUEST_STATE; |
1581 | 1553 |
1582 r->write_event_handler = ngx_http_writer; | 1554 r->write_event_handler = ngx_http_writer; |
1583 | |
1584 if (r->connection->closed) { | |
1585 return NGX_OK; | |
1586 } | |
1587 | 1555 |
1588 wev = r->connection->write; | 1556 wev = r->connection->write; |
1589 | 1557 |
1590 if (wev->ready && wev->delayed) { | 1558 if (wev->ready && wev->delayed) { |
1591 return NGX_OK; | 1559 return NGX_OK; |
1596 ngx_add_timer(wev, clcf->send_timeout); | 1564 ngx_add_timer(wev, clcf->send_timeout); |
1597 } | 1565 } |
1598 | 1566 |
1599 if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) { | 1567 if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) { |
1600 ngx_http_close_request(r, 0); | 1568 ngx_http_close_request(r, 0); |
1601 ngx_http_close_connection(r->connection); | |
1602 return NGX_ERROR; | 1569 return NGX_ERROR; |
1603 } | 1570 } |
1604 | 1571 |
1605 return NGX_OK; | 1572 return NGX_OK; |
1606 } | 1573 } |
1624 if (!wev->delayed) { | 1591 if (!wev->delayed) { |
1625 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, | 1592 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, |
1626 "client timed out"); | 1593 "client timed out"); |
1627 c->timedout = 1; | 1594 c->timedout = 1; |
1628 | 1595 |
1629 #if 0 | 1596 ngx_http_close_request(r, NGX_HTTP_REQUEST_TIME_OUT); |
1630 ngx_http_close_request(r->main, NGX_HTTP_REQUEST_TIME_OUT); | |
1631 ngx_http_close_connection(c); | |
1632 #endif | |
1633 | |
1634 c->closed = 1; | |
1635 ngx_http_finalize_request(r, 0); | |
1636 | |
1637 return; | 1597 return; |
1638 } | 1598 } |
1639 | 1599 |
1640 wev->timedout = 0; | 1600 wev->timedout = 0; |
1641 wev->delayed = 0; | 1601 wev->delayed = 0; |
1643 if (!wev->ready) { | 1603 if (!wev->ready) { |
1644 clcf = ngx_http_get_module_loc_conf(r->main, ngx_http_core_module); | 1604 clcf = ngx_http_get_module_loc_conf(r->main, ngx_http_core_module); |
1645 ngx_add_timer(wev, clcf->send_timeout); | 1605 ngx_add_timer(wev, clcf->send_timeout); |
1646 | 1606 |
1647 if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) { | 1607 if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) { |
1648 ngx_http_close_request(r->main, 0); | 1608 ngx_http_close_request(r, 0); |
1649 ngx_http_close_connection(r->connection); | |
1650 } | 1609 } |
1651 | 1610 |
1652 return; | 1611 return; |
1653 } | 1612 } |
1654 | 1613 |
1658 "http writer delayed"); | 1617 "http writer delayed"); |
1659 | 1618 |
1660 clcf = ngx_http_get_module_loc_conf(r->main, ngx_http_core_module); | 1619 clcf = ngx_http_get_module_loc_conf(r->main, ngx_http_core_module); |
1661 | 1620 |
1662 if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) { | 1621 if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) { |
1663 ngx_http_close_request(r->main, 0); | 1622 ngx_http_close_request(r, 0); |
1664 ngx_http_close_connection(r->connection); | |
1665 } | 1623 } |
1666 | 1624 |
1667 return; | 1625 return; |
1668 } | 1626 } |
1669 } | 1627 } |
1670 | 1628 |
1671 if (r->postponed) { | 1629 if (r->postponed) { |
1672 rc = ngx_http_postponed_handler(r); | 1630 rc = ngx_http_postponed_handler(r); |
1673 | 1631 |
1674 if (rc == NGX_DONE) { | 1632 if (rc == NGX_DONE) { |
1675 /* r may be already destroyed when rc == NGX_DONE */ | 1633 /* the request pool may be already destroyed */ |
1676 return; | 1634 return; |
1677 } | 1635 } |
1678 | 1636 |
1679 } else { | 1637 } else { |
1680 rc = ngx_http_output_filter(r, NULL); | 1638 rc = ngx_http_output_filter(r, NULL); |
1689 if (!wev->ready && !wev->delayed) { | 1647 if (!wev->ready && !wev->delayed) { |
1690 ngx_add_timer(wev, clcf->send_timeout); | 1648 ngx_add_timer(wev, clcf->send_timeout); |
1691 } | 1649 } |
1692 | 1650 |
1693 if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) { | 1651 if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) { |
1694 ngx_http_close_request(r->main, 0); | 1652 ngx_http_close_request(r, 0); |
1695 ngx_http_close_connection(r->connection); | |
1696 } | 1653 } |
1697 | 1654 |
1698 return; | 1655 return; |
1699 } | 1656 } |
1700 | 1657 |
1720 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1677 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1721 "http postponed data \"%V\" %p", &r->uri, pr->out); | 1678 "http postponed data \"%V\" %p", &r->uri, pr->out); |
1722 | 1679 |
1723 rc = ngx_http_output_filter(r, NULL); | 1680 rc = ngx_http_output_filter(r, NULL); |
1724 | 1681 |
1682 if (rc == NGX_DONE) { | |
1683 /* the request pool is already destroyed */ | |
1684 return NGX_DONE; | |
1685 } | |
1686 | |
1725 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1687 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1726 "http postponed output filter: %d", rc); | 1688 "http postponed output filter: %d", rc); |
1727 | 1689 |
1728 /* | 1690 if (rc == NGX_ERROR) { |
1729 * we treat NGX_ERROR as NGX_OK, because we need to complete | 1691 ngx_http_close_request(r, 0); |
1730 * all postponed requests | 1692 return NGX_DONE; |
1731 */ | 1693 } |
1732 | 1694 |
1733 pr = r->postponed; | 1695 pr = r->postponed; |
1734 | 1696 |
1735 if (pr == NULL) { | 1697 if (pr == NULL) { |
1736 | 1698 |
1767 { | 1729 { |
1768 if (ngx_del_event(r->connection->read, NGX_READ_EVENT, 0) | 1730 if (ngx_del_event(r->connection->read, NGX_READ_EVENT, 0) |
1769 == NGX_ERROR) | 1731 == NGX_ERROR) |
1770 { | 1732 { |
1771 ngx_http_close_request(r, 0); | 1733 ngx_http_close_request(r, 0); |
1772 ngx_http_close_connection(r->connection); | |
1773 } | 1734 } |
1774 } | 1735 } |
1775 } | 1736 } |
1776 | 1737 |
1777 | 1738 |
1830 rc = ngx_http_read_discarded_body(r); | 1791 rc = ngx_http_read_discarded_body(r); |
1831 | 1792 |
1832 if (rc == NGX_AGAIN) { | 1793 if (rc == NGX_AGAIN) { |
1833 if (ngx_handle_read_event(r->connection->read, 0) == NGX_ERROR) { | 1794 if (ngx_handle_read_event(r->connection->read, 0) == NGX_ERROR) { |
1834 ngx_http_close_request(r, rc); | 1795 ngx_http_close_request(r, rc); |
1835 ngx_http_close_connection(r->connection); | |
1836 return; | 1796 return; |
1837 } | 1797 } |
1838 } | 1798 } |
1839 | 1799 |
1840 if (rc != NGX_OK) { | 1800 if (rc != NGX_OK) { |
1841 ngx_http_close_request(r, rc); | 1801 ngx_http_close_request(r, rc); |
1842 ngx_http_close_connection(r->connection); | |
1843 } | 1802 } |
1844 } | 1803 } |
1845 | 1804 |
1846 | 1805 |
1847 static ngx_int_t | 1806 static ngx_int_t |
1930 hc->free = ngx_palloc(c->pool, | 1889 hc->free = ngx_palloc(c->pool, |
1931 cscf->large_client_header_buffers.num * sizeof(ngx_buf_t *)); | 1890 cscf->large_client_header_buffers.num * sizeof(ngx_buf_t *)); |
1932 | 1891 |
1933 if (hc->free == NULL) { | 1892 if (hc->free == NULL) { |
1934 ngx_http_close_request(r, 0); | 1893 ngx_http_close_request(r, 0); |
1935 ngx_http_close_connection(c); | |
1936 return; | 1894 return; |
1937 } | 1895 } |
1938 } | 1896 } |
1939 | 1897 |
1940 for (i = 0; i < hc->nbusy - 1; i++) { | 1898 for (i = 0; i < hc->nbusy - 1; i++) { |
1949 } | 1907 } |
1950 } | 1908 } |
1951 | 1909 |
1952 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 1910 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
1953 | 1911 |
1954 ngx_http_close_request(r, 0); | 1912 ngx_http_request_done(r, 0); |
1913 | |
1955 c->data = hc; | 1914 c->data = hc; |
1956 | 1915 |
1957 ngx_add_timer(rev, clcf->keepalive_timeout); | 1916 ngx_add_timer(rev, clcf->keepalive_timeout); |
1958 | 1917 |
1959 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { | 1918 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { |
2219 r->lingering_time = ngx_time() + (time_t) (clcf->lingering_time / 1000); | 2178 r->lingering_time = ngx_time() + (time_t) (clcf->lingering_time / 1000); |
2220 ngx_add_timer(rev, clcf->lingering_timeout); | 2179 ngx_add_timer(rev, clcf->lingering_timeout); |
2221 | 2180 |
2222 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { | 2181 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { |
2223 ngx_http_close_request(r, 0); | 2182 ngx_http_close_request(r, 0); |
2224 ngx_http_close_connection(c); | |
2225 return; | 2183 return; |
2226 } | 2184 } |
2227 | 2185 |
2228 wev = c->write; | 2186 wev = c->write; |
2229 wev->handler = ngx_http_empty_handler; | 2187 wev->handler = ngx_http_empty_handler; |
2232 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { | 2190 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { |
2233 if (ngx_del_event(wev, NGX_WRITE_EVENT, NGX_DISABLE_EVENT) | 2191 if (ngx_del_event(wev, NGX_WRITE_EVENT, NGX_DISABLE_EVENT) |
2234 == NGX_ERROR) | 2192 == NGX_ERROR) |
2235 { | 2193 { |
2236 ngx_http_close_request(r, 0); | 2194 ngx_http_close_request(r, 0); |
2237 ngx_http_close_connection(c); | |
2238 return; | 2195 return; |
2239 } | 2196 } |
2240 | 2197 |
2241 } else if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { | 2198 } else if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { |
2242 if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) == NGX_ERROR) { | 2199 if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) == NGX_ERROR) { |
2243 ngx_http_close_request(r, 0); | 2200 ngx_http_close_request(r, 0); |
2244 ngx_http_close_connection(c); | |
2245 return; | 2201 return; |
2246 } | 2202 } |
2247 } | 2203 } |
2248 } | 2204 } |
2249 | 2205 |
2250 if (ngx_shutdown_socket(c->fd, NGX_WRITE_SHUTDOWN) == -1) { | 2206 if (ngx_shutdown_socket(c->fd, NGX_WRITE_SHUTDOWN) == -1) { |
2251 ngx_connection_error(c, ngx_socket_errno, | 2207 ngx_connection_error(c, ngx_socket_errno, |
2252 ngx_shutdown_socket_n " failed"); | 2208 ngx_shutdown_socket_n " failed"); |
2253 ngx_http_close_request(r, 0); | 2209 ngx_http_close_request(r, 0); |
2254 ngx_http_close_connection(c); | |
2255 return; | 2210 return; |
2256 } | 2211 } |
2257 | 2212 |
2258 if (rev->ready) { | 2213 if (rev->ready) { |
2259 ngx_http_lingering_close_handler(rev); | 2214 ngx_http_lingering_close_handler(rev); |
2277 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | 2232 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
2278 "http lingering close handler"); | 2233 "http lingering close handler"); |
2279 | 2234 |
2280 if (rev->timedout) { | 2235 if (rev->timedout) { |
2281 ngx_http_close_request(r, 0); | 2236 ngx_http_close_request(r, 0); |
2282 ngx_http_close_connection(c); | |
2283 return; | 2237 return; |
2284 } | 2238 } |
2285 | 2239 |
2286 timer = r->lingering_time - ngx_time(); | 2240 timer = r->lingering_time - ngx_time(); |
2287 if (timer <= 0) { | 2241 if (timer <= 0) { |
2288 ngx_http_close_request(r, 0); | 2242 ngx_http_close_request(r, 0); |
2289 ngx_http_close_connection(c); | |
2290 return; | 2243 return; |
2291 } | 2244 } |
2292 | 2245 |
2293 do { | 2246 do { |
2294 n = c->recv(c, buffer, NGX_HTTP_LINGERING_BUFFER_SIZE); | 2247 n = c->recv(c, buffer, NGX_HTTP_LINGERING_BUFFER_SIZE); |
2295 | 2248 |
2296 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "lingering read: %d", n); | 2249 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "lingering read: %d", n); |
2297 | 2250 |
2298 if (n == NGX_ERROR || n == 0) { | 2251 if (n == NGX_ERROR || n == 0) { |
2299 ngx_http_close_request(r, 0); | 2252 ngx_http_close_request(r, 0); |
2300 ngx_http_close_connection(c); | |
2301 return; | 2253 return; |
2302 } | 2254 } |
2303 | 2255 |
2304 } while (rev->ready); | 2256 } while (rev->ready); |
2305 | 2257 |
2306 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { | 2258 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { |
2307 ngx_http_close_request(r, 0); | 2259 ngx_http_close_request(r, 0); |
2308 ngx_http_close_connection(c); | |
2309 return; | 2260 return; |
2310 } | 2261 } |
2311 | 2262 |
2312 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 2263 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
2313 | 2264 |
2360 | 2311 |
2361 | 2312 |
2362 void | 2313 void |
2363 ngx_http_close_request(ngx_http_request_t *r, ngx_int_t error) | 2314 ngx_http_close_request(ngx_http_request_t *r, ngx_int_t error) |
2364 { | 2315 { |
2365 ngx_log_t *log; | 2316 ngx_connection_t *c; |
2366 struct linger linger; | 2317 ngx_http_cleanup_t *cln; |
2367 ngx_http_log_ctx_t *ctx; | 2318 |
2368 ngx_http_core_loc_conf_t *clcf; | 2319 c = r->connection; |
2320 r = r->main; | |
2321 | |
2322 for (cln = r->cleanup; cln; cln = cln->next) { | |
2323 if (cln->handler) { | |
2324 cln->handler(cln->data); | |
2325 } | |
2326 } | |
2327 | |
2328 ngx_http_request_done(r, error); | |
2329 ngx_http_close_connection(c); | |
2330 } | |
2331 | |
2332 | |
2333 void | |
2334 ngx_http_request_done(ngx_http_request_t *r, ngx_int_t error) | |
2335 { | |
2336 ngx_log_t *log; | |
2337 struct linger linger; | |
2338 ngx_http_log_ctx_t *ctx; | |
2339 ngx_http_core_loc_conf_t *clcf; | |
2340 ngx_http_core_main_conf_t *cmcf; | |
2369 | 2341 |
2370 log = r->connection->log; | 2342 log = r->connection->log; |
2371 | 2343 |
2372 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "http close request"); | 2344 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "http close request"); |
2373 | 2345 |
2390 | 2362 |
2391 if (error && r->headers_out.status == 0) { | 2363 if (error && r->headers_out.status == 0) { |
2392 r->headers_out.status = error; | 2364 r->headers_out.status = error; |
2393 } | 2365 } |
2394 | 2366 |
2395 ngx_http_log_handler(r); | 2367 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); |
2368 | |
2369 if (cmcf->log_handler) { | |
2370 cmcf->log_handler(r); | |
2371 } | |
2396 | 2372 |
2397 if (r->connection->timedout) { | 2373 if (r->connection->timedout) { |
2398 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 2374 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
2399 | 2375 |
2400 if (clcf->reset_timedout_connection) { | 2376 if (clcf->reset_timedout_connection) { |