nginx-0.0.12-2004-09-26-23:01:48 import
Igor Sysoev
17 years ago
872 | 872 | |
873 | 873 | ngx_http_handler_pt *h; |
874 | 874 | |
875 | if (!(h = ngx_array_push(&cmcf->phases[NGX_HTTP_TRANSLATE_PHASE].handlers))) | |
876 | return NGX_ERROR; | |
877 | } | |
875 | ngx_test_null(h, ngx_push_array( | |
876 | &cmcf->phases[NGX_HTTP_TRANSLATE_PHASE].handlers), | |
877 | NGX_ERROR); | |
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 | if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) { | |
907 | return NGX_CONF_ERROR; | |
908 | } | |
906 | ngx_test_null(ctx, | |
907 | ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)), | |
908 | NGX_CONF_ERROR); | |
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 | 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 | } | |
915 | ngx_test_null(ctx->srv_conf, | |
916 | ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), | |
917 | NGX_CONF_ERROR); | |
919 | 918 | |
920 | 919 | /* the server{}'s loc_conf */ |
921 | 920 | |
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 | } | |
921 | ngx_test_null(ctx->loc_conf, | |
922 | ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), | |
923 | NGX_CONF_ERROR); | |
926 | 924 | |
927 | 925 | for (m = 0; ngx_modules[m]; m++) { |
928 | 926 | if (ngx_modules[m]->type != NGX_HTTP_MODULE) { |
1326 | 1324 | } |
1327 | 1325 | |
1328 | 1326 | ngx_conf_merge_size_value(conf->connection_pool_size, |
1329 | prev->connection_pool_size, 256); | |
1327 | prev->connection_pool_size, 2048); | |
1330 | 1328 | ngx_conf_merge_msec_value(conf->post_accept_timeout, |
1331 | prev->post_accept_timeout, 60000); | |
1329 | prev->post_accept_timeout, 30000); | |
1332 | 1330 | ngx_conf_merge_size_value(conf->request_pool_size, |
1333 | prev->request_pool_size, (size_t) ngx_pagesize); | |
1331 | prev->request_pool_size, 16384); | |
1334 | 1332 | ngx_conf_merge_msec_value(conf->client_header_timeout, |
1335 | 1333 | prev->client_header_timeout, 60000); |
1336 | 1334 | ngx_conf_merge_size_value(conf->client_header_buffer_size, |
1463 | 1461 | ngx_conf_merge_size_value(conf->client_max_body_size, |
1464 | 1462 | prev->client_max_body_size, 10 * 1024 * 1024); |
1465 | 1463 | ngx_conf_merge_size_value(conf->client_body_buffer_size, |
1466 | prev->client_body_buffer_size, | |
1467 | (size_t) 4 * ngx_pagesize); | |
1464 | prev->client_body_buffer_size, 8192); | |
1468 | 1465 | ngx_conf_merge_msec_value(conf->client_body_timeout, |
1469 | 1466 | prev->client_body_timeout, 60000); |
1470 | 1467 | 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) { | |
248 | if (clcf->keepalive_header | |
249 | && (r->headers_in.gecko || r->headers_in.konqueror)) | |
250 | { | |
249 | 251 | len += sizeof("Keep-Alive: timeout=") - 1 + TIME_T_LEN + 2; |
250 | 252 | } |
251 | 253 | |
377 | 379 | b->last = ngx_cpymem(b->last, "Connection: keep-alive" CRLF, |
378 | 380 | sizeof("Connection: keep-alive" CRLF) - 1); |
379 | 381 | |
380 | if (clcf->keepalive_header) { | |
382 | if (clcf->keepalive_header | |
383 | && (r->headers_in.gecko || r->headers_in.konqueror)) | |
384 | { | |
381 | 385 | b->last += ngx_snprintf((char *) b->last, |
382 | 386 | sizeof("Keep-Alive: timeout=") + TIME_T_LEN + 2, |
383 | 387 | "Keep-Alive: timeout=" TIME_T_FMT CRLF, |
1568 | 1568 | |
1569 | 1569 | if (b != c->buffer) { |
1570 | 1570 | |
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 | */ | |
1571 | /* move the large header buffers to the free list */ | |
1578 | 1572 | |
1579 | 1573 | cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
1580 | 1574 | |
1626 | 1620 | |
1627 | 1621 | hc->pipeline = 0; |
1628 | 1622 | |
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 | ||
1638 | 1623 | if (ngx_pfree(c->pool, r) == NGX_OK) { |
1639 | 1624 | hc->request = NULL; |
1640 | 1625 | } |
1642 | 1627 | b = c->buffer; |
1643 | 1628 | |
1644 | 1629 | 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 | ||
1651 | 1630 | b->pos = NULL; |
1652 | 1631 | |
1653 | 1632 | } else { |
1710 | 1689 | } |
1711 | 1690 | |
1712 | 1691 | #if 0 |
1713 | /* if ngx_http_request_t was freed then we need some other place */ | |
1692 | /* if "keepalive_buffers off" then we need some other place */ | |
1714 | 1693 | r->http_state = NGX_HTTP_KEEPALIVE_STATE; |
1715 | 1694 | #endif |
1716 | 1695 | |
1759 | 1738 | size = b->end - b->start; |
1760 | 1739 | |
1761 | 1740 | 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 | ||
1769 | 1741 | if (!(b->pos = ngx_palloc(c->pool, size))) { |
1770 | 1742 | ngx_http_close_connection(c); |
1771 | 1743 | return; |