comparison src/http/v3/ngx_http_v3_uni.c @ 9108:f742b1b46901 quic

HTTP/3: removed server push support.
author Roman Arutyunyan <arut@nginx.com>
date Fri, 12 May 2023 10:02:10 +0400
parents 6c732b87ee10
children
comparison
equal deleted inserted replaced
9107:adcc6d8acfd4 9108:f742b1b46901
14 ngx_http_v3_parse_uni_t parse; 14 ngx_http_v3_parse_uni_t parse;
15 ngx_int_t index; 15 ngx_int_t index;
16 } ngx_http_v3_uni_stream_t; 16 } ngx_http_v3_uni_stream_t;
17 17
18 18
19 typedef struct {
20 ngx_queue_t queue;
21 uint64_t id;
22 ngx_connection_t *connection;
23 ngx_uint_t *npushing;
24 } ngx_http_v3_push_t;
25
26
27 static void ngx_http_v3_close_uni_stream(ngx_connection_t *c); 19 static void ngx_http_v3_close_uni_stream(ngx_connection_t *c);
28 static void ngx_http_v3_uni_read_handler(ngx_event_t *rev); 20 static void ngx_http_v3_uni_read_handler(ngx_event_t *rev);
29 static void ngx_http_v3_uni_dummy_read_handler(ngx_event_t *wev); 21 static void ngx_http_v3_uni_dummy_read_handler(ngx_event_t *wev);
30 static void ngx_http_v3_uni_dummy_write_handler(ngx_event_t *wev); 22 static void ngx_http_v3_uni_dummy_write_handler(ngx_event_t *wev);
31 static void ngx_http_v3_push_cleanup(void *data);
32 static ngx_connection_t *ngx_http_v3_get_uni_stream(ngx_connection_t *c, 23 static ngx_connection_t *ngx_http_v3_get_uni_stream(ngx_connection_t *c,
33 ngx_uint_t type); 24 ngx_uint_t type);
34 25
35 26
36 void 27 void
311 if (ngx_handle_write_event(wev, 0) != NGX_OK) { 302 if (ngx_handle_write_event(wev, 0) != NGX_OK) {
312 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_INTERNAL_ERROR, 303 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_INTERNAL_ERROR,
313 NULL); 304 NULL);
314 ngx_http_v3_close_uni_stream(c); 305 ngx_http_v3_close_uni_stream(c);
315 } 306 }
316 }
317
318
319 ngx_connection_t *
320 ngx_http_v3_create_push_stream(ngx_connection_t *c, uint64_t push_id)
321 {
322 u_char *p, buf[NGX_HTTP_V3_VARLEN_INT_LEN * 2];
323 size_t n;
324 ngx_connection_t *sc;
325 ngx_pool_cleanup_t *cln;
326 ngx_http_v3_push_t *push;
327 ngx_http_v3_session_t *h3c;
328
329 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
330 "http3 create push stream id:%uL", push_id);
331
332 sc = ngx_quic_open_stream(c, 0);
333 if (sc == NULL) {
334 goto failed;
335 }
336
337 p = buf;
338 p = (u_char *) ngx_http_v3_encode_varlen_int(p, NGX_HTTP_V3_STREAM_PUSH);
339 p = (u_char *) ngx_http_v3_encode_varlen_int(p, push_id);
340 n = p - buf;
341
342 h3c = ngx_http_v3_get_session(c);
343 h3c->total_bytes += n;
344
345 if (sc->send(sc, buf, n) != (ssize_t) n) {
346 goto failed;
347 }
348
349 cln = ngx_pool_cleanup_add(sc->pool, sizeof(ngx_http_v3_push_t));
350 if (cln == NULL) {
351 goto failed;
352 }
353
354 h3c->npushing++;
355
356 cln->handler = ngx_http_v3_push_cleanup;
357
358 push = cln->data;
359 push->id = push_id;
360 push->connection = sc;
361 push->npushing = &h3c->npushing;
362
363 ngx_queue_insert_tail(&h3c->pushing, &push->queue);
364
365 return sc;
366
367 failed:
368
369 ngx_log_error(NGX_LOG_ERR, c->log, 0, "failed to create push stream");
370
371 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR,
372 "failed to create push stream");
373 if (sc) {
374 ngx_http_v3_close_uni_stream(sc);
375 }
376
377 return NULL;
378 }
379
380
381 static void
382 ngx_http_v3_push_cleanup(void *data)
383 {
384 ngx_http_v3_push_t *push = data;
385
386 ngx_queue_remove(&push->queue);
387 (*push->npushing)--;
388 } 307 }
389 308
390 309
391 static ngx_connection_t * 310 static ngx_connection_t *
392 ngx_http_v3_get_uni_stream(ngx_connection_t *c, ngx_uint_t type) 311 ngx_http_v3_get_uni_stream(ngx_connection_t *c, ngx_uint_t type)
692 return NGX_ERROR; 611 return NGX_ERROR;
693 } 612 }
694 613
695 614
696 ngx_int_t 615 ngx_int_t
697 ngx_http_v3_set_max_push_id(ngx_connection_t *c, uint64_t max_push_id)
698 {
699 ngx_http_v3_session_t *h3c;
700
701 h3c = ngx_http_v3_get_session(c);
702
703 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
704 "http3 MAX_PUSH_ID:%uL", max_push_id);
705
706 if (h3c->max_push_id != (uint64_t) -1 && max_push_id < h3c->max_push_id) {
707 return NGX_HTTP_V3_ERR_ID_ERROR;
708 }
709
710 h3c->max_push_id = max_push_id;
711
712 return NGX_OK;
713 }
714
715
716 ngx_int_t
717 ngx_http_v3_goaway(ngx_connection_t *c, uint64_t push_id)
718 {
719 ngx_http_v3_session_t *h3c;
720
721 h3c = ngx_http_v3_get_session(c);
722
723 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 GOAWAY:%uL", push_id);
724
725 h3c->goaway_push_id = push_id;
726
727 return NGX_OK;
728 }
729
730
731 ngx_int_t
732 ngx_http_v3_cancel_push(ngx_connection_t *c, uint64_t push_id)
733 {
734 ngx_queue_t *q;
735 ngx_http_request_t *r;
736 ngx_http_v3_push_t *push;
737 ngx_http_v3_session_t *h3c;
738
739 h3c = ngx_http_v3_get_session(c);
740
741 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
742 "http3 CANCEL_PUSH:%uL", push_id);
743
744 if (push_id >= h3c->next_push_id) {
745 return NGX_HTTP_V3_ERR_ID_ERROR;
746 }
747
748 for (q = ngx_queue_head(&h3c->pushing);
749 q != ngx_queue_sentinel(&h3c->pushing);
750 q = ngx_queue_next(q))
751 {
752 push = (ngx_http_v3_push_t *) q;
753
754 if (push->id != push_id) {
755 continue;
756 }
757
758 r = push->connection->data;
759
760 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
761 "http3 cancel push");
762
763 ngx_http_finalize_request(r, NGX_HTTP_CLOSE);
764
765 break;
766 }
767
768 return NGX_OK;
769 }
770
771
772 ngx_int_t
773 ngx_http_v3_cancel_stream(ngx_connection_t *c, ngx_uint_t stream_id) 616 ngx_http_v3_cancel_stream(ngx_connection_t *c, ngx_uint_t stream_id)
774 { 617 {
775 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, 618 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
776 "http3 cancel stream %ui", stream_id); 619 "http3 cancel stream %ui", stream_id);
777 620