Mercurial > hg > nginx-quic
comparison src/http/ngx_http_request.c @ 5105:4d67b696388f
Refactored ngx_http_init_request().
Now it can be used as the request object factory with minimal impact on the
connection object. Therefore it was renamed to ngx_http_create_request().
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Thu, 07 Mar 2013 18:14:27 +0000 |
parents | 93713d4b99c3 |
children | 44bd04fbbb4f |
comparison
equal
deleted
inserted
replaced
5104:93713d4b99c3 | 5105:4d67b696388f |
---|---|
9 #include <ngx_core.h> | 9 #include <ngx_core.h> |
10 #include <ngx_http.h> | 10 #include <ngx_http.h> |
11 | 11 |
12 | 12 |
13 static void ngx_http_wait_request_handler(ngx_event_t *ev); | 13 static void ngx_http_wait_request_handler(ngx_event_t *ev); |
14 static void ngx_http_init_request(ngx_event_t *ev); | 14 static ngx_http_request_t *ngx_http_create_request(ngx_connection_t *c); |
15 static void ngx_http_process_request_line(ngx_event_t *rev); | 15 static void ngx_http_process_request_line(ngx_event_t *rev); |
16 static void ngx_http_process_request_headers(ngx_event_t *rev); | 16 static void ngx_http_process_request_headers(ngx_event_t *rev); |
17 static ssize_t ngx_http_read_request_header(ngx_http_request_t *r); | 17 static ssize_t ngx_http_read_request_header(ngx_http_request_t *r); |
18 static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r, | 18 static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r, |
19 ngx_uint_t request_line); | 19 ngx_uint_t request_line); |
464 | 464 |
465 b->last += n; | 465 b->last += n; |
466 | 466 |
467 c->log->action = "reading client request line"; | 467 c->log->action = "reading client request line"; |
468 | 468 |
469 ngx_http_init_request(rev); | 469 c->data = ngx_http_create_request(c); |
470 } | 470 if (c->data == NULL) { |
471 | 471 ngx_http_close_connection(c); |
472 | 472 return; |
473 static void | 473 } |
474 ngx_http_init_request(ngx_event_t *rev) | 474 |
475 rev->handler = ngx_http_process_request_line; | |
476 ngx_http_process_request_line(rev); | |
477 } | |
478 | |
479 | |
480 static ngx_http_request_t * | |
481 ngx_http_create_request(ngx_connection_t *c) | |
475 { | 482 { |
476 ngx_pool_t *pool; | 483 ngx_pool_t *pool; |
477 ngx_time_t *tp; | 484 ngx_time_t *tp; |
478 ngx_connection_t *c; | |
479 ngx_http_request_t *r; | 485 ngx_http_request_t *r; |
480 ngx_http_log_ctx_t *ctx; | 486 ngx_http_log_ctx_t *ctx; |
481 ngx_http_connection_t *hc; | 487 ngx_http_connection_t *hc; |
482 ngx_http_core_srv_conf_t *cscf; | 488 ngx_http_core_srv_conf_t *cscf; |
483 ngx_http_core_loc_conf_t *clcf; | 489 ngx_http_core_loc_conf_t *clcf; |
484 ngx_http_core_main_conf_t *cmcf; | 490 ngx_http_core_main_conf_t *cmcf; |
485 | 491 |
486 c = rev->data; | |
487 | |
488 c->requests++; | 492 c->requests++; |
489 | 493 |
490 hc = c->data; | 494 hc = c->data; |
491 | 495 |
492 cscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_core_module); | 496 cscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_core_module); |
493 | 497 |
494 pool = ngx_create_pool(cscf->request_pool_size, c->log); | 498 pool = ngx_create_pool(cscf->request_pool_size, c->log); |
495 if (pool == NULL) { | 499 if (pool == NULL) { |
496 ngx_http_close_connection(c); | 500 return NULL; |
497 return; | |
498 } | 501 } |
499 | 502 |
500 r = ngx_pcalloc(pool, sizeof(ngx_http_request_t)); | 503 r = ngx_pcalloc(pool, sizeof(ngx_http_request_t)); |
501 if (r == NULL) { | 504 if (r == NULL) { |
502 ngx_destroy_pool(pool); | 505 ngx_destroy_pool(pool); |
503 ngx_http_close_connection(c); | 506 return NULL; |
504 return; | |
505 } | 507 } |
506 | 508 |
507 r->pool = pool; | 509 r->pool = pool; |
508 | 510 |
509 r->pipeline = hc->pipeline; | |
510 | |
511 c->data = r; | |
512 r->http_connection = hc; | 511 r->http_connection = hc; |
513 | |
514 c->sent = 0; | |
515 r->signature = NGX_HTTP_MODULE; | 512 r->signature = NGX_HTTP_MODULE; |
516 | |
517 r->connection = c; | 513 r->connection = c; |
518 | 514 |
519 r->main_conf = hc->conf_ctx->main_conf; | 515 r->main_conf = hc->conf_ctx->main_conf; |
520 r->srv_conf = hc->conf_ctx->srv_conf; | 516 r->srv_conf = hc->conf_ctx->srv_conf; |
521 r->loc_conf = hc->conf_ctx->loc_conf; | 517 r->loc_conf = hc->conf_ctx->loc_conf; |
531 if (ngx_list_init(&r->headers_out.headers, r->pool, 20, | 527 if (ngx_list_init(&r->headers_out.headers, r->pool, 20, |
532 sizeof(ngx_table_elt_t)) | 528 sizeof(ngx_table_elt_t)) |
533 != NGX_OK) | 529 != NGX_OK) |
534 { | 530 { |
535 ngx_destroy_pool(r->pool); | 531 ngx_destroy_pool(r->pool); |
536 ngx_http_close_connection(c); | 532 return NULL; |
537 return; | |
538 } | 533 } |
539 | 534 |
540 r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module); | 535 r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module); |
541 if (r->ctx == NULL) { | 536 if (r->ctx == NULL) { |
542 ngx_destroy_pool(r->pool); | 537 ngx_destroy_pool(r->pool); |
543 ngx_http_close_connection(c); | 538 return NULL; |
544 return; | |
545 } | 539 } |
546 | 540 |
547 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | 541 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); |
548 | 542 |
549 r->variables = ngx_pcalloc(r->pool, cmcf->variables.nelts | 543 r->variables = ngx_pcalloc(r->pool, cmcf->variables.nelts |
550 * sizeof(ngx_http_variable_value_t)); | 544 * sizeof(ngx_http_variable_value_t)); |
551 if (r->variables == NULL) { | 545 if (r->variables == NULL) { |
552 ngx_destroy_pool(r->pool); | 546 ngx_destroy_pool(r->pool); |
553 ngx_http_close_connection(c); | 547 return NULL; |
554 return; | 548 } |
555 } | |
556 | |
557 c->destroyed = 0; | |
558 | 549 |
559 #if (NGX_HTTP_SSL) | 550 #if (NGX_HTTP_SSL) |
560 if (c->ssl) { | 551 if (c->ssl) { |
561 r->main_filter_need_in_memory = 1; | 552 r->main_filter_need_in_memory = 1; |
562 } | 553 } |
590 (void) ngx_atomic_fetch_add(ngx_stat_reading, 1); | 581 (void) ngx_atomic_fetch_add(ngx_stat_reading, 1); |
591 r->stat_reading = 1; | 582 r->stat_reading = 1; |
592 (void) ngx_atomic_fetch_add(ngx_stat_requests, 1); | 583 (void) ngx_atomic_fetch_add(ngx_stat_requests, 1); |
593 #endif | 584 #endif |
594 | 585 |
595 rev->handler = ngx_http_process_request_line; | 586 return r; |
596 ngx_http_process_request_line(rev); | |
597 } | 587 } |
598 | 588 |
599 | 589 |
600 #if (NGX_HTTP_SSL) | 590 #if (NGX_HTTP_SSL) |
601 | 591 |
2720 if (b != c->buffer) { | 2710 if (b != c->buffer) { |
2721 | 2711 |
2722 /* | 2712 /* |
2723 * If the large header buffers were allocated while the previous | 2713 * If the large header buffers were allocated while the previous |
2724 * request processing then we do not use c->buffer for | 2714 * request processing then we do not use c->buffer for |
2725 * the pipelined request (see ngx_http_init_request()). | 2715 * the pipelined request (see ngx_http_create_request()). |
2726 * | 2716 * |
2727 * Now we would move the large header buffers to the free list. | 2717 * Now we would move the large header buffers to the free list. |
2728 */ | 2718 */ |
2729 | 2719 |
2730 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | 2720 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
2768 | 2758 |
2769 if (b->pos < b->last) { | 2759 if (b->pos < b->last) { |
2770 | 2760 |
2771 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "pipelined request"); | 2761 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "pipelined request"); |
2772 | 2762 |
2773 hc->pipeline = 1; | |
2774 c->log->action = "reading client pipelined request line"; | 2763 c->log->action = "reading client pipelined request line"; |
2764 | |
2765 r = ngx_http_create_request(c); | |
2766 if (r == NULL) { | |
2767 ngx_http_close_connection(c); | |
2768 return; | |
2769 } | |
2770 | |
2771 r->pipeline = 1; | |
2772 | |
2773 c->data = r; | |
2774 | |
2775 c->sent = 0; | |
2776 c->destroyed = 0; | |
2775 | 2777 |
2776 if (rev->timer_set) { | 2778 if (rev->timer_set) { |
2777 ngx_del_timer(rev); | 2779 ngx_del_timer(rev); |
2778 } | 2780 } |
2779 | 2781 |
2780 rev->handler = ngx_http_init_request; | 2782 rev->handler = ngx_http_process_request_line; |
2781 ngx_post_event(rev, &ngx_posted_events); | 2783 ngx_post_event(rev, &ngx_posted_events); |
2782 return; | 2784 return; |
2783 } | 2785 } |
2784 | |
2785 hc->pipeline = 0; | |
2786 | 2786 |
2787 /* | 2787 /* |
2788 * To keep a memory footprint as small as possible for an idle keepalive | 2788 * To keep a memory footprint as small as possible for an idle keepalive |
2789 * connection we try to free c->buffer's memory if it was allocated outside | 2789 * connection we try to free c->buffer's memory if it was allocated outside |
2790 * the c->pool. The large header buffers are always allocated outside the | 2790 * the c->pool. The large header buffers are always allocated outside the |
3017 c->log->action = "reading client request line"; | 3017 c->log->action = "reading client request line"; |
3018 | 3018 |
3019 c->idle = 0; | 3019 c->idle = 0; |
3020 ngx_reusable_connection(c, 0); | 3020 ngx_reusable_connection(c, 0); |
3021 | 3021 |
3022 c->data = ngx_http_create_request(c); | |
3023 if (c->data == NULL) { | |
3024 ngx_http_close_connection(c); | |
3025 return; | |
3026 } | |
3027 | |
3028 c->sent = 0; | |
3029 c->destroyed = 0; | |
3030 | |
3022 ngx_del_timer(rev); | 3031 ngx_del_timer(rev); |
3023 | 3032 |
3024 ngx_http_init_request(rev); | 3033 rev->handler = ngx_http_process_request_line; |
3034 ngx_http_process_request_line(rev); | |
3025 } | 3035 } |
3026 | 3036 |
3027 | 3037 |
3028 static void | 3038 static void |
3029 ngx_http_set_lingering_close(ngx_http_request_t *r) | 3039 ngx_http_set_lingering_close(ngx_http_request_t *r) |