comparison src/http/ngx_http_request_body.c @ 8086:9ffef6054abf quic

HTTP/3: fixed handling request body eof. While for HTTP/1 unexpected eof always means an error, for HTTP/3 an eof right after a DATA frame end means the end of the request body. For this reason, since adding HTTP/3 support, eof no longer produced an error right after recv() but was passed to filters which would make a decision. This decision was made in ngx_http_parse_chunked() and ngx_http_v3_parse_request_body() based on the b->last_buf flag. Now that since 0f7f1a509113 (1.19.2) rb->chunked->length is a lower threshold for the expected number of bytes, it can be set to zero to indicate that more bytes may or may not follow. Now it's possible to move the check for eof from parser functions to ngx_http_request_body_chunked_filter() and clean up the parsing code. Also, in the default branch, in case of eof, the following three things happened, which were replaced with returning NGX_ERROR while implementing HTTP/3: - "client prematurely closed connection" message was logged - c->error flag was set - NGX_HTTP_BAD_REQUEST was returned The change brings back this behavior for HTTP/1 as well as HTTP/3.
author Roman Arutyunyan <arut@nginx.com>
date Wed, 16 Sep 2020 18:59:25 +0100
parents eaea7dac3292
children 5a794d2452ef
comparison
equal deleted inserted replaced
8085:57e5393e5d40 8086:9ffef6054abf
958 958
959 if (rb->rest == 0) { 959 if (rb->rest == 0) {
960 break; 960 break;
961 } 961 }
962 962
963 size = cl->buf->last - cl->buf->pos;
964
965 if (cl->buf->last_buf && (off_t) size < rb->rest) {
966 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
967 "client prematurely closed connection");
968 r->connection->error = 1;
969 return NGX_HTTP_BAD_REQUEST;
970 }
971
963 tl = ngx_chain_get_free_buf(r->pool, &rb->free); 972 tl = ngx_chain_get_free_buf(r->pool, &rb->free);
964 if (tl == NULL) { 973 if (tl == NULL) {
965 return NGX_HTTP_INTERNAL_SERVER_ERROR; 974 return NGX_HTTP_INTERNAL_SERVER_ERROR;
966 } 975 }
967 976
975 b->pos = cl->buf->pos; 984 b->pos = cl->buf->pos;
976 b->last = cl->buf->last; 985 b->last = cl->buf->last;
977 b->end = cl->buf->end; 986 b->end = cl->buf->end;
978 b->flush = r->request_body_no_buffering; 987 b->flush = r->request_body_no_buffering;
979 988
980 size = cl->buf->last - cl->buf->pos;
981
982 if ((off_t) size < rb->rest) { 989 if ((off_t) size < rb->rest) {
983 cl->buf->pos = cl->buf->last; 990 cl->buf->pos = cl->buf->last;
984 rb->rest -= size; 991 rb->rest -= size;
985 992
986 } else { 993 } else {
987 cl->buf->pos += (size_t) rb->rest; 994 cl->buf->pos += (size_t) rb->rest;
988 rb->rest = 0; 995 rb->rest = 0;
989 b->last = cl->buf->pos; 996 b->last = cl->buf->pos;
990 b->last_buf = 1; 997 b->last_buf = 1;
991 }
992
993 if (cl->buf->last_buf && rb->rest > 0) {
994 /* XXX client prematurely closed connection */
995 return NGX_ERROR;
996 } 998 }
997 999
998 *ll = tl; 1000 *ll = tl;
999 ll = &tl->next; 1001 ll = &tl->next;
1000 } 1002 }
1144 } 1146 }
1145 1147
1146 b->last = cl->buf->pos; 1148 b->last = cl->buf->pos;
1147 1149
1148 continue; 1150 continue;
1151 }
1152
1153 if (rc == NGX_AGAIN && cl->buf->last_buf) {
1154
1155 /* last body buffer */
1156
1157 if (rb->chunked->length > 0) {
1158 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
1159 "client prematurely closed connection");
1160 r->connection->error = 1;
1161 return NGX_HTTP_BAD_REQUEST;
1162 }
1163
1164 rc = NGX_DONE;
1149 } 1165 }
1150 1166
1151 if (rc == NGX_DONE) { 1167 if (rc == NGX_DONE) {
1152 1168
1153 /* a whole response has been parsed successfully */ 1169 /* a whole response has been parsed successfully */