comparison src/http/ngx_http_request.c @ 8208:4ae9ac69ab93 quic

HTTP/QUIC interface reworked. - events handling moved into src/event/ngx_event_quic.c - http invokes once ngx_quic_run() and passes stream callback (diff to original http_request.c is now minimal) - streams are stored in rbtree using ID as a key - when a new stream is registered, appropriate callback is called - ngx_quic_stream_t type represents STREAM and stored in c->qs
author Vladimir Homutov <vl@nginx.com>
date Thu, 12 Mar 2020 16:54:43 +0300
parents b28ea685a56e
children b761ca7df7d0
comparison
equal deleted inserted replaced
8207:cc8d211cb45c 8208:4ae9ac69ab93
60 ngx_http_request_t *sr, u_char *buf, size_t len); 60 ngx_http_request_t *sr, u_char *buf, size_t len);
61 61
62 #if (NGX_HTTP_SSL) 62 #if (NGX_HTTP_SSL)
63 static void ngx_http_ssl_handshake(ngx_event_t *rev); 63 static void ngx_http_ssl_handshake(ngx_event_t *rev);
64 static void ngx_http_ssl_handshake_handler(ngx_connection_t *c); 64 static void ngx_http_ssl_handshake_handler(ngx_connection_t *c);
65 65 #endif
66 static void ngx_http_quic_handshake(ngx_event_t *rev); 66
67 static void ngx_http_quic_handshake_handler(ngx_event_t *rev); 67 static void ngx_http_quic_stream_handler(ngx_connection_t *c);
68 #endif
69
70 68
71 static char *ngx_http_client_errors[] = { 69 static char *ngx_http_client_errors[] = {
72 70
73 /* NGX_HTTP_PARSE_INVALID_METHOD */ 71 /* NGX_HTTP_PARSE_INVALID_METHOD */
74 "client sent invalid method", 72 "client sent invalid method",
331 rev->ready = 1; 329 rev->ready = 1;
332 } 330 }
333 331
334 #if (NGX_HTTP_SSL) 332 #if (NGX_HTTP_SSL)
335 if (hc->addr_conf->http3) { 333 if (hc->addr_conf->http3) {
334 ngx_http_ssl_srv_conf_t *sscf;
335
336 hc->quic = 1; 336 hc->quic = 1;
337 c->log->action = "QUIC handshaking"; 337
338 rev->handler = ngx_http_quic_handshake; 338 sscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_ssl_module);
339
340 ngx_quic_run(c, &sscf->ssl, c->listening->post_accept_timeout,
341 ngx_http_quic_stream_handler);
342 return;
339 } 343 }
340 #endif 344 #endif
341 345
342 #if (NGX_HTTP_V2) 346 #if (NGX_HTTP_V2)
343 if (hc->addr_conf->http2) { 347 if (hc->addr_conf->http2) {
381 385
382 if (ngx_handle_read_event(rev, 0) != NGX_OK) { 386 if (ngx_handle_read_event(rev, 0) != NGX_OK) {
383 ngx_http_close_connection(c); 387 ngx_http_close_connection(c);
384 return; 388 return;
385 } 389 }
390 }
391
392
393 static void
394 ngx_http_quic_stream_handler(ngx_connection_t *c)
395 {
396 ngx_quic_stream_t *qs = c->qs;
397
398 printf("quic stream: 0x%lx\n", qs->id);
386 } 399 }
387 400
388 401
389 static void 402 static void
390 ngx_http_wait_request_handler(ngx_event_t *rev) 403 ngx_http_wait_request_handler(ngx_event_t *rev)
399 412
400 c = rev->data; 413 c = rev->data;
401 414
402 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http wait request handler"); 415 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http wait request handler");
403 416
404 if (c->shared) {
405 goto request;
406 }
407
408 if (rev->timedout) { 417 if (rev->timedout) {
409 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); 418 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
410 ngx_http_close_connection(c); 419 ngx_http_close_connection(c);
411 return; 420 return;
412 } 421 }
503 ngx_post_event(rev, &ngx_posted_events); 512 ngx_post_event(rev, &ngx_posted_events);
504 return; 513 return;
505 } 514 }
506 } 515 }
507 516
508 request:
509
510 c->log->action = "reading client request line"; 517 c->log->action = "reading client request line";
511 518
512 ngx_reusable_connection(c, 0); 519 ngx_reusable_connection(c, 0);
513 520
514 c->data = ngx_http_create_request(c); 521 c->data = ngx_http_create_request(c);
655 return r; 662 return r;
656 } 663 }
657 664
658 665
659 #if (NGX_HTTP_SSL) 666 #if (NGX_HTTP_SSL)
660
661 static void
662 ngx_http_quic_handshake(ngx_event_t *rev)
663 {
664 ngx_connection_t *c;
665 ngx_http_connection_t *hc;
666 ngx_http_ssl_srv_conf_t *sscf;
667
668 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "quic handshake");
669
670 c = rev->data;
671 hc = c->data;
672
673 sscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_ssl_module);
674
675 if (ngx_quic_input(c, &sscf->ssl, c->buffer) != NGX_OK) {
676 ngx_http_close_connection(c);
677 return;
678 }
679
680 if (!rev->timer_set) {
681 ngx_add_timer(rev, c->listening->post_accept_timeout);
682 }
683
684 rev->handler = ngx_http_quic_handshake_handler;
685 return;
686 }
687
688
689 static void
690 ngx_http_quic_handshake_handler(ngx_event_t *rev)
691 {
692 ssize_t n;
693 ngx_connection_t *c;
694 u_char buf[512];
695 ngx_buf_t b;
696
697 b.start = buf;
698 b.end = buf + 512;
699 b.pos = b.last = b.start;
700
701 c = rev->data;
702
703 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "quic handshake handler");
704
705 if (rev->timedout) {
706 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
707 ngx_http_close_connection(c);
708 return;
709 }
710
711 if (c->close) {
712 ngx_http_close_connection(c);
713 return;
714 }
715
716 n = c->recv(c, b.start, b.end - b.start);
717
718 if (n == NGX_AGAIN) {
719 return;
720 }
721
722 if (n == NGX_ERROR) {
723 c->read->eof = 1;
724 ngx_http_close_connection(c);
725 return;
726 }
727
728 b.last += n;
729
730 if (ngx_quic_input(c, NULL, &b) != NGX_OK) {
731 ngx_http_close_connection(c);
732 return;
733 }
734 }
735
736 667
737 static void 668 static void
738 ngx_http_ssl_handshake(ngx_event_t *rev) 669 ngx_http_ssl_handshake(ngx_event_t *rev)
739 { 670 {
740 u_char *p, buf[NGX_PROXY_PROTOCOL_MAX_HEADER + 1]; 671 u_char *p, buf[NGX_PROXY_PROTOCOL_MAX_HEADER + 1];