Mercurial > hg > nginx-quic
comparison src/http/ngx_http_request.c @ 5121:c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Wed, 20 Mar 2013 10:36:57 +0000 |
parents | f10108c92fef |
children | 9d83ec073c51 |
comparison
equal
deleted
inserted
replaced
5120:7956af6b6a02 | 5121:c0f7b94e88ba |
---|---|
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 ngx_http_request_t *ngx_http_create_request(ngx_connection_t *c); | |
15 static void ngx_http_process_request_line(ngx_event_t *rev); | 14 static void ngx_http_process_request_line(ngx_event_t *rev); |
16 static void ngx_http_process_request_headers(ngx_event_t *rev); | 15 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); | 16 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, | 17 static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r, |
19 ngx_uint_t request_line); | 18 ngx_uint_t request_line); |
29 static ngx_int_t ngx_http_process_connection(ngx_http_request_t *r, | 28 static ngx_int_t ngx_http_process_connection(ngx_http_request_t *r, |
30 ngx_table_elt_t *h, ngx_uint_t offset); | 29 ngx_table_elt_t *h, ngx_uint_t offset); |
31 static ngx_int_t ngx_http_process_user_agent(ngx_http_request_t *r, | 30 static ngx_int_t ngx_http_process_user_agent(ngx_http_request_t *r, |
32 ngx_table_elt_t *h, ngx_uint_t offset); | 31 ngx_table_elt_t *h, ngx_uint_t offset); |
33 | 32 |
34 static ngx_int_t ngx_http_process_request_uri(ngx_http_request_t *r); | |
35 static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r); | |
36 static void ngx_http_process_request(ngx_http_request_t *r); | |
37 static ngx_int_t ngx_http_validate_host(ngx_str_t *host, ngx_pool_t *pool, | 33 static ngx_int_t ngx_http_validate_host(ngx_str_t *host, ngx_pool_t *pool, |
38 ngx_uint_t alloc); | 34 ngx_uint_t alloc); |
39 static ngx_int_t ngx_http_set_virtual_server(ngx_http_request_t *r, | 35 static ngx_int_t ngx_http_set_virtual_server(ngx_http_request_t *r, |
40 ngx_str_t *host); | 36 ngx_str_t *host); |
41 static ngx_int_t ngx_http_find_virtual_server(ngx_connection_t *c, | 37 static ngx_int_t ngx_http_find_virtual_server(ngx_connection_t *c, |
54 static void ngx_http_keepalive_handler(ngx_event_t *ev); | 50 static void ngx_http_keepalive_handler(ngx_event_t *ev); |
55 static void ngx_http_set_lingering_close(ngx_http_request_t *r); | 51 static void ngx_http_set_lingering_close(ngx_http_request_t *r); |
56 static void ngx_http_lingering_close_handler(ngx_event_t *ev); | 52 static void ngx_http_lingering_close_handler(ngx_event_t *ev); |
57 static ngx_int_t ngx_http_post_action(ngx_http_request_t *r); | 53 static ngx_int_t ngx_http_post_action(ngx_http_request_t *r); |
58 static void ngx_http_close_request(ngx_http_request_t *r, ngx_int_t error); | 54 static void ngx_http_close_request(ngx_http_request_t *r, ngx_int_t error); |
59 static void ngx_http_free_request(ngx_http_request_t *r, ngx_int_t error); | |
60 static void ngx_http_log_request(ngx_http_request_t *r); | 55 static void ngx_http_log_request(ngx_http_request_t *r); |
61 static void ngx_http_close_connection(ngx_connection_t *c); | |
62 | 56 |
63 static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len); | 57 static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len); |
64 static u_char *ngx_http_log_error_handler(ngx_http_request_t *r, | 58 static u_char *ngx_http_log_error_handler(ngx_http_request_t *r, |
65 ngx_http_request_t *sr, u_char *buf, size_t len); | 59 ngx_http_request_t *sr, u_char *buf, size_t len); |
66 | 60 |
316 | 310 |
317 rev = c->read; | 311 rev = c->read; |
318 rev->handler = ngx_http_wait_request_handler; | 312 rev->handler = ngx_http_wait_request_handler; |
319 c->write->handler = ngx_http_empty_handler; | 313 c->write->handler = ngx_http_empty_handler; |
320 | 314 |
315 #if (NGX_HTTP_SPDY) | |
316 if (hc->addr_conf->spdy) { | |
317 rev->handler = ngx_http_spdy_init; | |
318 } | |
319 #endif | |
320 | |
321 #if (NGX_HTTP_SSL) | 321 #if (NGX_HTTP_SSL) |
322 { | 322 { |
323 ngx_http_ssl_srv_conf_t *sscf; | 323 ngx_http_ssl_srv_conf_t *sscf; |
324 | 324 |
325 sscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_ssl_module); | 325 sscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_ssl_module); |
485 rev->handler = ngx_http_process_request_line; | 485 rev->handler = ngx_http_process_request_line; |
486 ngx_http_process_request_line(rev); | 486 ngx_http_process_request_line(rev); |
487 } | 487 } |
488 | 488 |
489 | 489 |
490 static ngx_http_request_t * | 490 ngx_http_request_t * |
491 ngx_http_create_request(ngx_connection_t *c) | 491 ngx_http_create_request(ngx_connection_t *c) |
492 { | 492 { |
493 ngx_pool_t *pool; | 493 ngx_pool_t *pool; |
494 ngx_time_t *tp; | 494 ngx_time_t *tp; |
495 ngx_http_request_t *r; | 495 ngx_http_request_t *r; |
725 * Opera and recent Mozilla send the alert. | 725 * Opera and recent Mozilla send the alert. |
726 */ | 726 */ |
727 | 727 |
728 c->ssl->no_wait_shutdown = 1; | 728 c->ssl->no_wait_shutdown = 1; |
729 | 729 |
730 #if (NGX_HTTP_SPDY && defined TLSEXT_TYPE_next_proto_neg) | |
731 { | |
732 unsigned int len; | |
733 const unsigned char *data; | |
734 static const ngx_str_t spdy = ngx_string(NGX_SPDY_NPN_NEGOTIATED); | |
735 | |
736 SSL_get0_next_proto_negotiated(c->ssl->connection, &data, &len); | |
737 | |
738 if (len == spdy.len && ngx_strncmp(data, spdy.data, spdy.len) == 0) { | |
739 ngx_http_spdy_init(c->read); | |
740 return; | |
741 } | |
742 } | |
743 #endif | |
744 | |
730 c->log->action = "waiting for request"; | 745 c->log->action = "waiting for request"; |
731 | 746 |
732 c->read->handler = ngx_http_wait_request_handler; | 747 c->read->handler = ngx_http_wait_request_handler; |
733 /* STUB: epoll edge */ c->write->handler = ngx_http_empty_handler; | 748 /* STUB: epoll edge */ c->write->handler = ngx_http_empty_handler; |
734 | 749 |
983 } | 998 } |
984 } | 999 } |
985 } | 1000 } |
986 | 1001 |
987 | 1002 |
988 static ngx_int_t | 1003 ngx_int_t |
989 ngx_http_process_request_uri(ngx_http_request_t *r) | 1004 ngx_http_process_request_uri(ngx_http_request_t *r) |
990 { | 1005 { |
991 ngx_http_core_srv_conf_t *cscf; | 1006 ngx_http_core_srv_conf_t *cscf; |
992 | 1007 |
993 if (r->args_start) { | 1008 if (r->args_start) { |
1685 *ph = h; | 1700 *ph = h; |
1686 return NGX_OK; | 1701 return NGX_OK; |
1687 } | 1702 } |
1688 | 1703 |
1689 | 1704 |
1690 static ngx_int_t | 1705 ngx_int_t |
1691 ngx_http_process_request_header(ngx_http_request_t *r) | 1706 ngx_http_process_request_header(ngx_http_request_t *r) |
1692 { | 1707 { |
1693 if (r->headers_in.server.len == 0 | 1708 if (r->headers_in.server.len == 0 |
1694 && ngx_http_set_virtual_server(r, &r->headers_in.server) | 1709 && ngx_http_set_virtual_server(r, &r->headers_in.server) |
1695 == NGX_ERROR) | 1710 == NGX_ERROR) |
1755 | 1770 |
1756 return NGX_OK; | 1771 return NGX_OK; |
1757 } | 1772 } |
1758 | 1773 |
1759 | 1774 |
1760 static void | 1775 void |
1761 ngx_http_process_request(ngx_http_request_t *r) | 1776 ngx_http_process_request(ngx_http_request_t *r) |
1762 { | 1777 { |
1763 ngx_connection_t *c; | 1778 ngx_connection_t *c; |
1764 | 1779 |
1765 c = r->connection; | 1780 c = r->connection; |
2432 static void | 2447 static void |
2433 ngx_http_finalize_connection(ngx_http_request_t *r) | 2448 ngx_http_finalize_connection(ngx_http_request_t *r) |
2434 { | 2449 { |
2435 ngx_http_core_loc_conf_t *clcf; | 2450 ngx_http_core_loc_conf_t *clcf; |
2436 | 2451 |
2452 #if (NGX_HTTP_SPDY) | |
2453 if (r->spdy_stream) { | |
2454 ngx_http_close_request(r, 0); | |
2455 return; | |
2456 } | |
2457 #endif | |
2458 | |
2437 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 2459 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
2438 | 2460 |
2439 if (r->main->count != 1) { | 2461 if (r->main->count != 1) { |
2440 | 2462 |
2441 if (r->discard_body) { | 2463 if (r->discard_body) { |
2486 r->read_event_handler = r->discard_body ? | 2508 r->read_event_handler = r->discard_body ? |
2487 ngx_http_discarded_request_body_handler: | 2509 ngx_http_discarded_request_body_handler: |
2488 ngx_http_test_reading; | 2510 ngx_http_test_reading; |
2489 r->write_event_handler = ngx_http_writer; | 2511 r->write_event_handler = ngx_http_writer; |
2490 | 2512 |
2513 #if (NGX_HTTP_SPDY) | |
2514 if (r->spdy_stream) { | |
2515 return NGX_OK; | |
2516 } | |
2517 #endif | |
2518 | |
2491 wev = r->connection->write; | 2519 wev = r->connection->write; |
2492 | 2520 |
2493 if (wev->ready && wev->delayed) { | 2521 if (wev->ready && wev->delayed) { |
2494 return NGX_OK; | 2522 return NGX_OK; |
2495 } | 2523 } |
2632 | 2660 |
2633 c = r->connection; | 2661 c = r->connection; |
2634 rev = c->read; | 2662 rev = c->read; |
2635 | 2663 |
2636 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http test reading"); | 2664 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http test reading"); |
2665 | |
2666 #if (NGX_HTTP_SPDY) | |
2667 | |
2668 if (r->spdy_stream) { | |
2669 if (c->error) { | |
2670 err = 0; | |
2671 goto closed; | |
2672 } | |
2673 | |
2674 return; | |
2675 } | |
2676 | |
2677 #endif | |
2637 | 2678 |
2638 #if (NGX_HAVE_KQUEUE) | 2679 #if (NGX_HAVE_KQUEUE) |
2639 | 2680 |
2640 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { | 2681 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { |
2641 | 2682 |
3268 | 3309 |
3269 if (r->count || r->blocked) { | 3310 if (r->count || r->blocked) { |
3270 return; | 3311 return; |
3271 } | 3312 } |
3272 | 3313 |
3314 #if (NGX_HTTP_SPDY) | |
3315 if (r->spdy_stream) { | |
3316 ngx_http_spdy_close_stream(r->spdy_stream, rc); | |
3317 return; | |
3318 } | |
3319 #endif | |
3320 | |
3273 ngx_http_free_request(r, rc); | 3321 ngx_http_free_request(r, rc); |
3274 ngx_http_close_connection(c); | 3322 ngx_http_close_connection(c); |
3275 } | 3323 } |
3276 | 3324 |
3277 | 3325 |
3278 static void | 3326 void |
3279 ngx_http_free_request(ngx_http_request_t *r, ngx_int_t rc) | 3327 ngx_http_free_request(ngx_http_request_t *r, ngx_int_t rc) |
3280 { | 3328 { |
3281 ngx_log_t *log; | 3329 ngx_log_t *log; |
3282 ngx_pool_t *pool; | 3330 ngx_pool_t *pool; |
3283 struct linger linger; | 3331 struct linger linger; |
3374 log_handler[i](r); | 3422 log_handler[i](r); |
3375 } | 3423 } |
3376 } | 3424 } |
3377 | 3425 |
3378 | 3426 |
3379 static void | 3427 void |
3380 ngx_http_close_connection(ngx_connection_t *c) | 3428 ngx_http_close_connection(ngx_connection_t *c) |
3381 { | 3429 { |
3382 ngx_pool_t *pool; | 3430 ngx_pool_t *pool; |
3383 | 3431 |
3384 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | 3432 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |