nginx-0.0.12-2004-09-24-20:12:19 import
Igor Sysoev
17 years ago
872 | 872 | |
873 | 873 | ngx_http_handler_pt *h; |
874 | 874 | |
875 | ngx_test_null(h, ngx_push_array( | |
876 | &cmcf->phases[NGX_HTTP_TRANSLATE_PHASE].handlers), | |
877 | NGX_ERROR); | |
875 | if (!(h = ngx_array_push(&cmcf->phases[NGX_HTTP_TRANSLATE_PHASE].handlers))) | |
876 | return NGX_ERROR; | |
877 | } | |
878 | 878 | *h = ngx_http_delay_handler; |
879 | 879 | #endif |
880 | 880 | |
903 | 903 | ngx_http_core_main_conf_t *cmcf; |
904 | 904 | ngx_http_core_srv_conf_t *cscf, **cscfp; |
905 | 905 | |
906 | ngx_test_null(ctx, | |
907 | ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)), | |
908 | NGX_CONF_ERROR); | |
906 | if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) { | |
907 | return NGX_CONF_ERROR; | |
908 | } | |
909 | 909 | |
910 | 910 | http_ctx = cf->ctx; |
911 | 911 | ctx->main_conf = http_ctx->main_conf; |
912 | 912 | |
913 | 913 | /* the server{}'s srv_conf */ |
914 | 914 | |
915 | ngx_test_null(ctx->srv_conf, | |
916 | ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), | |
917 | NGX_CONF_ERROR); | |
915 | ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
916 | if (ctx->srv_conf == NULL) { | |
917 | return NGX_CONF_ERROR; | |
918 | } | |
918 | 919 | |
919 | 920 | /* the server{}'s loc_conf */ |
920 | 921 | |
921 | ngx_test_null(ctx->loc_conf, | |
922 | ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), | |
923 | NGX_CONF_ERROR); | |
922 | ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
923 | if (ctx->loc_conf == NULL) { | |
924 | return NGX_CONF_ERROR; | |
925 | } | |
924 | 926 | |
925 | 927 | for (m = 0; ngx_modules[m]; m++) { |
926 | 928 | if (ngx_modules[m]->type != NGX_HTTP_MODULE) { |
1324 | 1326 | } |
1325 | 1327 | |
1326 | 1328 | ngx_conf_merge_size_value(conf->connection_pool_size, |
1327 | prev->connection_pool_size, 2048); | |
1329 | prev->connection_pool_size, 256); | |
1328 | 1330 | ngx_conf_merge_msec_value(conf->post_accept_timeout, |
1329 | prev->post_accept_timeout, 30000); | |
1331 | prev->post_accept_timeout, 60000); | |
1330 | 1332 | ngx_conf_merge_size_value(conf->request_pool_size, |
1331 | prev->request_pool_size, 16384); | |
1333 | prev->request_pool_size, (size_t) ngx_pagesize); | |
1332 | 1334 | ngx_conf_merge_msec_value(conf->client_header_timeout, |
1333 | 1335 | prev->client_header_timeout, 60000); |
1334 | 1336 | ngx_conf_merge_size_value(conf->client_header_buffer_size, |
1461 | 1463 | ngx_conf_merge_size_value(conf->client_max_body_size, |
1462 | 1464 | prev->client_max_body_size, 10 * 1024 * 1024); |
1463 | 1465 | ngx_conf_merge_size_value(conf->client_body_buffer_size, |
1464 | prev->client_body_buffer_size, 8192); | |
1466 | prev->client_body_buffer_size, | |
1467 | (size_t) 4 * ngx_pagesize); | |
1465 | 1468 | ngx_conf_merge_msec_value(conf->client_body_timeout, |
1466 | 1469 | prev->client_body_timeout, 60000); |
1467 | 1470 | ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0); |
245 | 245 | * Konqueror keeps the connection alive for about N seconds. |
246 | 246 | */ |
247 | 247 | |
248 | if (clcf->keepalive_header | |
249 | && (r->headers_in.gecko || r->headers_in.konqueror)) | |
250 | { | |
248 | if (clcf->keepalive_header) { | |
251 | 249 | len += sizeof("Keep-Alive: timeout=") - 1 + TIME_T_LEN + 2; |
252 | 250 | } |
253 | 251 | |
379 | 377 | b->last = ngx_cpymem(b->last, "Connection: keep-alive" CRLF, |
380 | 378 | sizeof("Connection: keep-alive" CRLF) - 1); |
381 | 379 | |
382 | if (clcf->keepalive_header | |
383 | && (r->headers_in.gecko || r->headers_in.konqueror)) | |
384 | { | |
380 | if (clcf->keepalive_header) { | |
385 | 381 | b->last += ngx_snprintf((char *) b->last, |
386 | 382 | sizeof("Keep-Alive: timeout=") + TIME_T_LEN + 2, |
387 | 383 | "Keep-Alive: timeout=" TIME_T_FMT CRLF, |
483 | 483 | { |
484 | 484 | u_char *p; |
485 | 485 | ssize_t n; |
486 | ngx_int_t rc, rv, offset; | |
486 | ngx_int_t rc, rv; | |
487 | 487 | ngx_connection_t *c; |
488 | 488 | ngx_http_request_t *r; |
489 | 489 | ngx_http_log_ctx_t *ctx; |
707 | 707 | static void ngx_http_process_request_headers(ngx_event_t *rev) |
708 | 708 | { |
709 | 709 | ssize_t n; |
710 | ngx_int_t rc, rv, i, offset; | |
710 | ngx_int_t rc, rv, i; | |
711 | 711 | ngx_table_elt_t *h, **cookie; |
712 | 712 | ngx_connection_t *c; |
713 | 713 | ngx_http_request_t *r; |
938 | 938 | ngx_uint_t request_line) |
939 | 939 | { |
940 | 940 | u_char *old, *new; |
941 | ngx_int_t offset; | |
942 | 941 | ngx_buf_t *b; |
943 | 942 | ngx_http_connection_t *hc; |
944 | 943 | ngx_http_core_srv_conf_t *cscf; |
1544 | 1543 | static void ngx_http_set_keepalive(ngx_http_request_t *r) |
1545 | 1544 | { |
1546 | 1545 | ngx_int_t i; |
1547 | size_t len; | |
1548 | 1546 | ngx_buf_t *b, *f; |
1549 | 1547 | ngx_event_t *rev, *wev; |
1550 | 1548 | ngx_connection_t *c; |
1570 | 1568 | |
1571 | 1569 | if (b != c->buffer) { |
1572 | 1570 | |
1573 | /* move the large header buffers to the free list */ | |
1571 | /* | |
1572 | * If the large header buffers were allocated while the previous | |
1573 | * request processing then we do not use c->buffer for | |
1574 | * the pipelined request (see ngx_http_init_request()). | |
1575 | * | |
1576 | * Now we would move the large header buffers to the free list. | |
1577 | */ | |
1574 | 1578 | |
1575 | 1579 | cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
1576 | 1580 | |
1622 | 1626 | |
1623 | 1627 | hc->pipeline = 0; |
1624 | 1628 | |
1629 | ||
1630 | /* | |
1631 | * To keep a memory footprint as small as possible for an idle | |
1632 | * keepalive connection we try to free the ngx_http_request_t and | |
1633 | * c->buffer's memory if they were allocated outside the c->pool. | |
1634 | * The large header buffers are always allocated outside the c->pool and | |
1635 | * are freed too. | |
1636 | */ | |
1637 | ||
1625 | 1638 | if (ngx_pfree(c->pool, r) == NGX_OK) { |
1626 | 1639 | hc->request = NULL; |
1627 | 1640 | } |
1629 | 1642 | b = c->buffer; |
1630 | 1643 | |
1631 | 1644 | if (ngx_pfree(c->pool, b->start) == NGX_OK) { |
1645 | ||
1646 | /* | |
1647 | * the special note for ngx_http_keepalive_handler() that | |
1648 | * c->buffer's memory was freed | |
1649 | */ | |
1650 | ||
1632 | 1651 | b->pos = NULL; |
1633 | 1652 | |
1634 | 1653 | } else { |
1691 | 1710 | } |
1692 | 1711 | |
1693 | 1712 | #if 0 |
1694 | /* if "keepalive_buffers off" then we need some other place */ | |
1713 | /* if ngx_http_request_t was freed then we need some other place */ | |
1695 | 1714 | r->http_state = NGX_HTTP_KEEPALIVE_STATE; |
1696 | 1715 | #endif |
1697 | 1716 | |
1740 | 1759 | size = b->end - b->start; |
1741 | 1760 | |
1742 | 1761 | if (b->pos == NULL) { |
1762 | ||
1763 | /* | |
1764 | * The c->buffer's memory was freed by ngx_http_set_keepalive(). | |
1765 | * However, the c->buffer->start and c->buffer->end were not changed | |
1766 | * to keep the buffer size. | |
1767 | */ | |
1768 | ||
1743 | 1769 | if (!(b->pos = ngx_palloc(c->pool, size))) { |
1744 | 1770 | ngx_http_close_connection(c); |
1745 | 1771 | return; |