Mercurial > hg > nginx
comparison src/http/v3/ngx_http_v3_request.c @ 8847:e29c1ede905f quic
HTTP/3: reading body buffering in filters.
This change follows similar changes in HTTP/1 and HTTP/2 in 9cf043a5d9ca.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Thu, 09 Sep 2021 15:47:29 +0300 |
parents | d6e191a583cc |
children | 7416d3b2fac5 |
comparison
equal
deleted
inserted
replaced
8846:cbbe901c199d | 8847:e29c1ede905f |
---|---|
820 rc = ngx_http_v3_request_body_filter(r, cl); | 820 rc = ngx_http_v3_request_body_filter(r, cl); |
821 if (rc != NGX_OK) { | 821 if (rc != NGX_OK) { |
822 return rc; | 822 return rc; |
823 } | 823 } |
824 | 824 |
825 if (rb->rest == 0) { | 825 if (rb->rest == 0 && rb->last_saved) { |
826 /* the whole request body was pre-read */ | 826 /* the whole request body was pre-read */ |
827 r->request_body_no_buffering = 0; | 827 r->request_body_no_buffering = 0; |
828 rb->post_handler(r); | 828 rb->post_handler(r); |
829 return NGX_OK; | 829 return NGX_OK; |
830 } | 830 } |
893 { | 893 { |
894 off_t rest; | 894 off_t rest; |
895 size_t size; | 895 size_t size; |
896 ssize_t n; | 896 ssize_t n; |
897 ngx_int_t rc; | 897 ngx_int_t rc; |
898 ngx_uint_t flush; | |
898 ngx_chain_t out; | 899 ngx_chain_t out; |
899 ngx_connection_t *c; | 900 ngx_connection_t *c; |
900 ngx_http_request_body_t *rb; | 901 ngx_http_request_body_t *rb; |
901 ngx_http_core_loc_conf_t *clcf; | 902 ngx_http_core_loc_conf_t *clcf; |
902 | 903 |
903 c = r->connection; | 904 c = r->connection; |
904 rb = r->request_body; | 905 rb = r->request_body; |
906 flush = 1; | |
905 | 907 |
906 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | 908 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
907 "http3 read client request body"); | 909 "http3 read client request body"); |
908 | 910 |
909 for ( ;; ) { | 911 for ( ;; ) { |
910 for ( ;; ) { | 912 for ( ;; ) { |
913 if (rb->rest == 0) { | |
914 break; | |
915 } | |
916 | |
911 if (rb->buf->last == rb->buf->end) { | 917 if (rb->buf->last == rb->buf->end) { |
912 | 918 |
913 /* update chains */ | 919 /* update chains */ |
914 | 920 |
915 rc = ngx_http_v3_request_body_filter(r, NULL); | 921 rc = ngx_http_v3_request_body_filter(r, NULL); |
929 } | 935 } |
930 | 936 |
931 return NGX_AGAIN; | 937 return NGX_AGAIN; |
932 } | 938 } |
933 | 939 |
940 if (rb->filter_need_buffering) { | |
941 clcf = ngx_http_get_module_loc_conf(r, | |
942 ngx_http_core_module); | |
943 ngx_add_timer(c->read, clcf->client_body_timeout); | |
944 | |
945 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { | |
946 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
947 } | |
948 | |
949 return NGX_AGAIN; | |
950 } | |
951 | |
934 ngx_log_error(NGX_LOG_ALERT, c->log, 0, | 952 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
935 "busy buffers after request body flush"); | 953 "busy buffers after request body flush"); |
936 | 954 |
937 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 955 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
938 } | 956 } |
939 | 957 |
958 flush = 0; | |
940 rb->buf->pos = rb->buf->start; | 959 rb->buf->pos = rb->buf->start; |
941 rb->buf->last = rb->buf->start; | 960 rb->buf->last = rb->buf->start; |
942 } | 961 } |
943 | 962 |
944 size = rb->buf->end - rb->buf->last; | 963 size = rb->buf->end - rb->buf->last; |
945 rest = rb->rest - (rb->buf->last - rb->buf->pos); | 964 rest = rb->rest - (rb->buf->last - rb->buf->pos); |
946 | 965 |
947 if ((off_t) size > rest) { | 966 if ((off_t) size > rest) { |
948 size = (size_t) rest; | 967 size = (size_t) rest; |
968 } | |
969 | |
970 if (size == 0) { | |
971 break; | |
949 } | 972 } |
950 | 973 |
951 n = c->recv(c, rb->buf->last, size); | 974 n = c->recv(c, rb->buf->last, size); |
952 | 975 |
953 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | 976 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
968 | 991 |
969 rb->buf->last += n; | 992 rb->buf->last += n; |
970 | 993 |
971 /* pass buffer to request body filter chain */ | 994 /* pass buffer to request body filter chain */ |
972 | 995 |
996 flush = 0; | |
973 out.buf = rb->buf; | 997 out.buf = rb->buf; |
974 out.next = NULL; | 998 out.next = NULL; |
975 | 999 |
976 rc = ngx_http_v3_request_body_filter(r, &out); | 1000 rc = ngx_http_v3_request_body_filter(r, &out); |
977 | 1001 |
989 } | 1013 } |
990 | 1014 |
991 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | 1015 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
992 "http3 client request body rest %O", rb->rest); | 1016 "http3 client request body rest %O", rb->rest); |
993 | 1017 |
994 if (rb->rest == 0) { | 1018 if (flush) { |
1019 rc = ngx_http_v3_request_body_filter(r, NULL); | |
1020 | |
1021 if (rc != NGX_OK) { | |
1022 return rc; | |
1023 } | |
1024 } | |
1025 | |
1026 if (rb->rest == 0 && rb->last_saved) { | |
995 break; | 1027 break; |
996 } | 1028 } |
997 | 1029 |
998 if (!c->read->ready) { | 1030 if (!c->read->ready || rb->rest == 0) { |
999 | 1031 |
1000 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 1032 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
1001 ngx_add_timer(c->read, clcf->client_body_timeout); | 1033 ngx_add_timer(c->read, clcf->client_body_timeout); |
1002 | 1034 |
1003 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { | 1035 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |