comparison src/http/ngx_http_request.c @ 2261:07bf557a2e40

*) log_subrequest *) flush variables in access log
author Igor Sysoev <igor@sysoev.ru>
date Sat, 27 Sep 2008 15:08:02 +0000
parents 8c17cfe63d2c
children c31f46332e80
comparison
equal deleted inserted replaced
2260:4f1616b32744 2261:07bf557a2e40
45 static void ngx_http_set_lingering_close(ngx_http_request_t *r); 45 static void ngx_http_set_lingering_close(ngx_http_request_t *r);
46 static void ngx_http_lingering_close_handler(ngx_event_t *ev); 46 static void ngx_http_lingering_close_handler(ngx_event_t *ev);
47 static ngx_int_t ngx_http_post_action(ngx_http_request_t *r); 47 static ngx_int_t ngx_http_post_action(ngx_http_request_t *r);
48 static void ngx_http_close_request(ngx_http_request_t *r, ngx_int_t error); 48 static void ngx_http_close_request(ngx_http_request_t *r, ngx_int_t error);
49 static void ngx_http_request_done(ngx_http_request_t *r, ngx_int_t error); 49 static void ngx_http_request_done(ngx_http_request_t *r, ngx_int_t error);
50 static void ngx_http_log_request(ngx_http_request_t *r);
50 static void ngx_http_close_connection(ngx_connection_t *c); 51 static void ngx_http_close_connection(ngx_connection_t *c);
51 52
52 static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len); 53 static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len);
53 static u_char *ngx_http_log_error_handler(ngx_http_request_t *r, 54 static u_char *ngx_http_log_error_handler(ngx_http_request_t *r,
54 ngx_http_request_t *sr, u_char *buf, size_t len); 55 ngx_http_request_t *sr, u_char *buf, size_t len);
1772 "http finalize non-active request: \"%V?%V\"", 1773 "http finalize non-active request: \"%V?%V\"",
1773 &r->uri, &r->args); 1774 &r->uri, &r->args);
1774 return; 1775 return;
1775 } 1776 }
1776 1777
1778 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1779
1777 if (r != r->main) { 1780 if (r != r->main) {
1778 1781
1779 pr = r->parent; 1782 pr = r->parent;
1780 1783
1781 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, 1784 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1805 } 1808 }
1806 1809
1807 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, 1810 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1808 "http fast subrequest: \"%V?%V\" done", 1811 "http fast subrequest: \"%V?%V\" done",
1809 &r->uri, &r->args); 1812 &r->uri, &r->args);
1813
1814 if (clcf->log_subrequest) {
1815 ngx_http_log_request(r);
1816 }
1817
1810 return; 1818 return;
1811 } 1819 }
1812 1820
1813 if (rc != NGX_AGAIN) { 1821 if (rc != NGX_AGAIN) {
1814 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, 1822 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1817 1825
1818 pr->write_event_handler(pr); 1826 pr->write_event_handler(pr);
1819 } 1827 }
1820 } 1828 }
1821 1829
1830 if (clcf->log_subrequest) {
1831 ngx_http_log_request(r);
1832 }
1833
1822 return; 1834 return;
1823 } 1835 }
1824 1836
1825 if (rc == NGX_AGAIN) { 1837 if (rc == NGX_AGAIN) {
1826 return; 1838 return;
1854 1866
1855 if (c->read->eof) { 1867 if (c->read->eof) {
1856 ngx_http_close_request(r, 0); 1868 ngx_http_close_request(r, 0);
1857 return; 1869 return;
1858 } 1870 }
1859
1860 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1861 1871
1862 if (!ngx_terminate 1872 if (!ngx_terminate
1863 && !ngx_exiting 1873 && !ngx_exiting
1864 && r->keepalive 1874 && r->keepalive
1865 && clcf->keepalive_timeout > 0) 1875 && clcf->keepalive_timeout > 0)
2602 2612
2603 2613
2604 static void 2614 static void
2605 ngx_http_request_done(ngx_http_request_t *r, ngx_int_t error) 2615 ngx_http_request_done(ngx_http_request_t *r, ngx_int_t error)
2606 { 2616 {
2607 ngx_log_t *log; 2617 ngx_log_t *log;
2608 ngx_uint_t i, n; 2618 struct linger linger;
2609 struct linger linger; 2619 ngx_http_cleanup_t *cln;
2610 ngx_http_cleanup_t *cln; 2620 ngx_http_log_ctx_t *ctx;
2611 ngx_http_log_ctx_t *ctx; 2621 ngx_http_core_loc_conf_t *clcf;
2612 ngx_http_handler_pt *log_handler;
2613 ngx_http_core_loc_conf_t *clcf;
2614 ngx_http_core_main_conf_t *cmcf;
2615 2622
2616 log = r->connection->log; 2623 log = r->connection->log;
2617 2624
2618 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "http close request"); 2625 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "http close request");
2619 2626
2644 r->headers_out.status = error; 2651 r->headers_out.status = error;
2645 } 2652 }
2646 2653
2647 log->action = "logging request"; 2654 log->action = "logging request";
2648 2655
2649 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); 2656 ngx_http_log_request(r);
2650
2651 log_handler = cmcf->phases[NGX_HTTP_LOG_PHASE].handlers.elts;
2652 n = cmcf->phases[NGX_HTTP_LOG_PHASE].handlers.nelts;
2653 for (i = 0; i < n; i++) {
2654 log_handler[i](r);
2655 }
2656 2657
2657 log->action = "closing request"; 2658 log->action = "closing request";
2658 2659
2659 if (r->connection->timedout) { 2660 if (r->connection->timedout) {
2660 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 2661 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
2683 ngx_destroy_pool(r->pool); 2684 ngx_destroy_pool(r->pool);
2684 } 2685 }
2685 2686
2686 2687
2687 static void 2688 static void
2689 ngx_http_log_request(ngx_http_request_t *r)
2690 {
2691 ngx_uint_t i, n;
2692 ngx_http_handler_pt *log_handler;
2693 ngx_http_core_main_conf_t *cmcf;
2694
2695 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
2696
2697 log_handler = cmcf->phases[NGX_HTTP_LOG_PHASE].handlers.elts;
2698 n = cmcf->phases[NGX_HTTP_LOG_PHASE].handlers.nelts;
2699
2700 for (i = 0; i < n; i++) {
2701 log_handler[i](r);
2702 }
2703 }
2704
2705
2706 static void
2688 ngx_http_close_connection(ngx_connection_t *c) 2707 ngx_http_close_connection(ngx_connection_t *c)
2689 { 2708 {
2690 ngx_pool_t *pool; 2709 ngx_pool_t *pool;
2691 2710
2692 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, 2711 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,