Mercurial > hg > nginx
comparison src/http/v3/ngx_http_v3_streams.c @ 8679:e1eb7f4ca9f1 quic
HTTP/3: refactored request parser.
The change reduces diff to the default branch for
src/http/ngx_http_request.c and src/http/ngx_http_parse.c.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Fri, 22 Jan 2021 16:34:06 +0300 |
parents | 279ad36f2f4b |
children | 5cb5b568282b |
comparison
equal
deleted
inserted
replaced
8678:3443ee341cc1 | 8679:e1eb7f4ca9f1 |
---|---|
38 ngx_uint_t type); | 38 ngx_uint_t type); |
39 static ngx_int_t ngx_http_v3_send_settings(ngx_connection_t *c); | 39 static ngx_int_t ngx_http_v3_send_settings(ngx_connection_t *c); |
40 | 40 |
41 | 41 |
42 ngx_int_t | 42 ngx_int_t |
43 ngx_http_v3_init_connection(ngx_connection_t *c) | 43 ngx_http_v3_init_session(ngx_connection_t *c) |
44 { | 44 { |
45 ngx_http_connection_t *hc; | 45 ngx_connection_t *pc; |
46 ngx_http_connection_t *phc; | |
47 ngx_http_v3_connection_t *h3c; | |
48 | |
49 pc = c->quic->parent; | |
50 phc = pc->data; | |
51 | |
52 if (phc->http3) { | |
53 return NGX_OK; | |
54 } | |
55 | |
56 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init session"); | |
57 | |
58 h3c = ngx_pcalloc(pc->pool, sizeof(ngx_http_v3_connection_t)); | |
59 if (h3c == NULL) { | |
60 return NGX_ERROR; | |
61 } | |
62 | |
63 h3c->hc = *phc; | |
64 h3c->hc.http3 = 1; | |
65 | |
66 ngx_queue_init(&h3c->blocked); | |
67 ngx_queue_init(&h3c->pushing); | |
68 | |
69 pc->data = h3c; | |
70 | |
71 return ngx_http_v3_send_settings(c); | |
72 } | |
73 | |
74 | |
75 void | |
76 ngx_http_v3_init_uni_stream(ngx_connection_t *c) | |
77 { | |
46 ngx_http_v3_uni_stream_t *us; | 78 ngx_http_v3_uni_stream_t *us; |
47 ngx_http_v3_connection_t *h3c; | 79 |
48 | 80 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init uni stream"); |
49 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init connection"); | |
50 | |
51 hc = c->data; | |
52 | |
53 if (c->quic == NULL) { | |
54 h3c = ngx_pcalloc(c->pool, sizeof(ngx_http_v3_connection_t)); | |
55 if (h3c == NULL) { | |
56 return NGX_ERROR; | |
57 } | |
58 | |
59 h3c->hc = *hc; | |
60 | |
61 ngx_queue_init(&h3c->blocked); | |
62 ngx_queue_init(&h3c->pushing); | |
63 | |
64 c->data = h3c; | |
65 return NGX_OK; | |
66 } | |
67 | |
68 if (ngx_http_v3_send_settings(c) == NGX_ERROR) { | |
69 return NGX_ERROR; | |
70 } | |
71 | |
72 if ((c->quic->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) == 0) { | |
73 return NGX_OK; | |
74 } | |
75 | 81 |
76 us = ngx_pcalloc(c->pool, sizeof(ngx_http_v3_uni_stream_t)); | 82 us = ngx_pcalloc(c->pool, sizeof(ngx_http_v3_uni_stream_t)); |
77 if (us == NULL) { | 83 if (us == NULL) { |
78 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_INTERNAL_ERROR, | 84 ngx_http_close_connection(c); |
79 NULL); | 85 return; |
80 return NGX_ERROR; | |
81 } | 86 } |
82 | 87 |
83 us->index = -1; | 88 us->index = -1; |
84 | 89 |
85 c->data = us; | 90 c->data = us; |
86 | 91 |
87 c->read->handler = ngx_http_v3_read_uni_stream_type; | 92 c->read->handler = ngx_http_v3_read_uni_stream_type; |
88 c->write->handler = ngx_http_v3_dummy_write_handler; | 93 c->write->handler = ngx_http_v3_dummy_write_handler; |
89 | 94 |
90 ngx_http_v3_read_uni_stream_type(c->read); | 95 ngx_http_v3_read_uni_stream_type(c->read); |
91 | |
92 return NGX_DONE; | |
93 } | 96 } |
94 | 97 |
95 | 98 |
96 static void | 99 static void |
97 ngx_http_v3_close_uni_stream(ngx_connection_t *c) | 100 ngx_http_v3_close_uni_stream(ngx_connection_t *c) |
476 ngx_http_v3_srv_conf_t *h3scf; | 479 ngx_http_v3_srv_conf_t *h3scf; |
477 ngx_http_v3_connection_t *h3c; | 480 ngx_http_v3_connection_t *h3c; |
478 | 481 |
479 h3c = c->quic->parent->data; | 482 h3c = c->quic->parent->data; |
480 | 483 |
481 if (h3c->settings_sent) { | |
482 return NGX_OK; | |
483 } | |
484 | |
485 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 send settings"); | 484 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 send settings"); |
486 | 485 |
487 cc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_CONTROL); | 486 cc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_CONTROL); |
488 if (cc == NULL) { | 487 if (cc == NULL) { |
489 return NGX_DECLINED; | 488 return NGX_DECLINED; |
510 | 509 |
511 if (cc->send(cc, buf, n) != (ssize_t) n) { | 510 if (cc->send(cc, buf, n) != (ssize_t) n) { |
512 goto failed; | 511 goto failed; |
513 } | 512 } |
514 | 513 |
515 h3c->settings_sent = 1; | |
516 | |
517 return NGX_OK; | 514 return NGX_OK; |
518 | 515 |
519 failed: | 516 failed: |
520 | 517 |
521 ngx_http_v3_close_uni_stream(cc); | 518 ngx_http_v3_close_uni_stream(cc); |
522 | |
523 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_INTERNAL_ERROR, | |
524 "could not send settings"); | |
525 | 519 |
526 return NGX_ERROR; | 520 return NGX_ERROR; |
527 } | 521 } |
528 | 522 |
529 | 523 |