comparison src/http/ngx_http_request.c @ 8481:0d2b2664b41c quic

QUIC: added "quic" listen parameter. The parameter allows processing HTTP/0.9-2 over QUIC. Also, introduced ngx_http_quic_module and moved QUIC settings there
author Roman Arutyunyan <arut@nginx.com>
date Tue, 21 Jul 2020 23:09:22 +0300
parents b3c07aa021f6
children 2da9c4fddd44
comparison
equal deleted inserted replaced
8480:f537f99b86ee 8481:0d2b2664b41c
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 #endif 65 #endif
66 66
67 #if (NGX_HTTP_V3)
68 static void ngx_http_quic_stream_handler(ngx_connection_t *c);
69 #endif
70 67
71 static char *ngx_http_client_errors[] = { 68 static char *ngx_http_client_errors[] = {
72 69
73 /* NGX_HTTP_PARSE_INVALID_METHOD */ 70 /* NGX_HTTP_PARSE_INVALID_METHOD */
74 "client sent invalid method", 71 "client sent invalid method",
219 #if (NGX_HAVE_INET6) 216 #if (NGX_HAVE_INET6)
220 struct sockaddr_in6 *sin6; 217 struct sockaddr_in6 *sin6;
221 ngx_http_in6_addr_t *addr6; 218 ngx_http_in6_addr_t *addr6;
222 #endif 219 #endif
223 220
224 #if (NGX_HTTP_V3) 221 hc = ngx_pcalloc(c->pool, sizeof(ngx_http_connection_t));
225 if (c->type == SOCK_DGRAM) {
226 ngx_http_v3_connection_t *h3c;
227
228 h3c = ngx_pcalloc(c->pool, sizeof(ngx_http_v3_connection_t));
229 if (h3c == NULL) {
230 ngx_http_close_connection(c);
231 return;
232 }
233
234 ngx_queue_init(&h3c->blocked);
235
236 hc = &h3c->hc;
237 hc->quic = 1;
238 hc->ssl = 1;
239
240 } else
241 #endif
242 hc = ngx_pcalloc(c->pool, sizeof(ngx_http_connection_t));
243
244 if (hc == NULL) { 222 if (hc == NULL) {
245 ngx_http_close_connection(c); 223 ngx_http_close_connection(c);
246 return; 224 return;
247 } 225 }
248 226
323 } 301 }
324 302
325 /* the default server configuration for the address:port */ 303 /* the default server configuration for the address:port */
326 hc->conf_ctx = hc->addr_conf->default_server->ctx; 304 hc->conf_ctx = hc->addr_conf->default_server->ctx;
327 305
306 #if (NGX_HTTP_QUIC)
307
308 if (hc->addr_conf->quic) {
309 ngx_quic_conf_t *qcf;
310 ngx_http_ssl_srv_conf_t *sscf;
311
312 #if (NGX_HTTP_V3)
313
314 if (hc->addr_conf->http3) {
315 ngx_int_t rc;
316
317 rc = ngx_http_v3_init_connection(c);
318
319 if (rc == NGX_ERROR) {
320 ngx_http_close_connection(c);
321 return;
322 }
323
324 if (rc == NGX_DONE) {
325 return;
326 }
327 }
328
329 #endif
330
331 if (c->qs == NULL) {
332 c->log->connection = c->number;
333
334 qcf = ngx_http_get_module_srv_conf(hc->conf_ctx,
335 ngx_http_quic_module);
336 sscf = ngx_http_get_module_srv_conf(hc->conf_ctx,
337 ngx_http_ssl_module);
338
339 ngx_quic_run(c, &sscf->ssl, qcf, ngx_http_init_connection);
340 return;
341 }
342 }
343
344 #endif
345
328 ctx = ngx_palloc(c->pool, sizeof(ngx_http_log_ctx_t)); 346 ctx = ngx_palloc(c->pool, sizeof(ngx_http_log_ctx_t));
329 if (ctx == NULL) { 347 if (ctx == NULL) {
330 ngx_http_close_connection(c); 348 ngx_http_close_connection(c);
331 return; 349 return;
332 } 350 }
344 362
345 rev = c->read; 363 rev = c->read;
346 rev->handler = ngx_http_wait_request_handler; 364 rev->handler = ngx_http_wait_request_handler;
347 c->write->handler = ngx_http_empty_handler; 365 c->write->handler = ngx_http_empty_handler;
348 366
349 if (c->shared) {
350 rev->ready = 1;
351 }
352
353 #if (NGX_HTTP_V3)
354 if (hc->quic) {
355 ngx_http_v3_srv_conf_t *v3cf;
356 ngx_http_ssl_srv_conf_t *sscf;
357
358 v3cf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_v3_module);
359 sscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_ssl_module);
360
361 ngx_quic_run(c, &sscf->ssl, &v3cf->quic, ngx_http_quic_stream_handler);
362 return;
363 }
364 #endif
365
366 #if (NGX_HTTP_V2) 367 #if (NGX_HTTP_V2)
367 if (hc->addr_conf->http2) { 368 if (hc->addr_conf->http2) {
368 rev->handler = ngx_http_v2_init; 369 rev->handler = ngx_http_v2_init;
369 } 370 }
370 #endif 371 #endif
406 if (ngx_handle_read_event(rev, 0) != NGX_OK) { 407 if (ngx_handle_read_event(rev, 0) != NGX_OK) {
407 ngx_http_close_connection(c); 408 ngx_http_close_connection(c);
408 return; 409 return;
409 } 410 }
410 } 411 }
411
412
413 #if (NGX_HTTP_V3)
414
415 static void
416 ngx_http_quic_stream_handler(ngx_connection_t *c)
417 {
418 ngx_event_t *rev;
419 ngx_http_log_ctx_t *ctx;
420 ngx_http_connection_t *hc;
421 ngx_http_v3_connection_t *h3c;
422
423 h3c = c->qs->parent->data;
424
425 if (!h3c->settings_sent) {
426 h3c->settings_sent = 1;
427
428 if (ngx_http_v3_send_settings(c) != NGX_OK) {
429 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_INTERNAL_ERROR,
430 "could not send settings");
431 ngx_http_close_connection(c);
432 return;
433 }
434 }
435
436 if (c->qs->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) {
437 ngx_http_v3_handle_client_uni_stream(c);
438 return;
439 }
440
441 hc = ngx_pcalloc(c->pool, sizeof(ngx_http_connection_t));
442 if (hc == NULL) {
443 ngx_http_close_connection(c);
444 return;
445 }
446
447 ngx_memcpy(hc, h3c, sizeof(ngx_http_connection_t));
448 c->data = hc;
449
450 ctx = ngx_palloc(c->pool, sizeof(ngx_http_log_ctx_t));
451 if (ctx == NULL) {
452 ngx_http_close_connection(c);
453 return;
454 }
455
456 ctx->connection = c;
457 ctx->request = NULL;
458 ctx->current_request = NULL;
459
460 c->log->handler = ngx_http_log_error;
461 c->log->data = ctx;
462 c->log->action = "waiting for request";
463
464 c->log_error = NGX_ERROR_INFO;
465
466 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
467 "http3 new stream id:0x%uXL", c->qs->id);
468
469 rev = c->read;
470 rev->handler = ngx_http_wait_request_handler;
471 c->write->handler = ngx_http_empty_handler;
472
473 rev->handler(rev);
474 }
475
476 #endif
477 412
478 413
479 static void 414 static void
480 ngx_http_wait_request_handler(ngx_event_t *rev) 415 ngx_http_wait_request_handler(ngx_event_t *rev)
481 { 416 {
723 658
724 r->method = NGX_HTTP_UNKNOWN; 659 r->method = NGX_HTTP_UNKNOWN;
725 r->http_version = NGX_HTTP_VERSION_10; 660 r->http_version = NGX_HTTP_VERSION_10;
726 661
727 #if (NGX_HTTP_V3) 662 #if (NGX_HTTP_V3)
728 if (hc->quic) { 663 if (hc->addr_conf->http3) {
729 r->http_version = NGX_HTTP_VERSION_30; 664 r->http_version = NGX_HTTP_VERSION_30;
730 } 665 }
731 #endif 666 #endif
732 667
733 r->headers_in.content_length_n = -1; 668 r->headers_in.content_length_n = -1;