comparison src/http/v3/ngx_http_v3_request.c @ 8548: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 830680e78b24
children d70a38acaea0
comparison
equal deleted inserted replaced
8547:57e5393e5d40 8548:9ffef6054abf
377 ngx_http_chunked_t *ctx) 377 ngx_http_chunked_t *ctx)
378 { 378 {
379 ngx_int_t rc; 379 ngx_int_t rc;
380 ngx_connection_t *c; 380 ngx_connection_t *c;
381 ngx_http_v3_parse_data_t *st; 381 ngx_http_v3_parse_data_t *st;
382 enum {
383 sw_start = 0,
384 sw_skip
385 };
382 386
383 c = r->connection; 387 c = r->connection;
384 st = ctx->h3_parse; 388 st = ctx->h3_parse;
385 389
386 if (st == NULL) { 390 if (st == NULL) {
393 } 397 }
394 398
395 ctx->h3_parse = st; 399 ctx->h3_parse = st;
396 } 400 }
397 401
398 if (ctx->size) { 402 while (b->pos < b->last && ctx->size == 0) {
399 ctx->length = ctx->size + 1; 403
400 return (b->pos == b->last) ? NGX_AGAIN : NGX_OK;
401 }
402
403 while (b->pos < b->last) {
404 rc = ngx_http_v3_parse_data(c, st, *b->pos++); 404 rc = ngx_http_v3_parse_data(c, st, *b->pos++);
405 405
406 if (rc > 0) { 406 if (rc > 0) {
407 ngx_http_v3_finalize_connection(c, rc, 407 ngx_http_v3_finalize_connection(c, rc,
408 "could not parse request body"); 408 "could not parse request body");
412 if (rc == NGX_ERROR) { 412 if (rc == NGX_ERROR) {
413 goto failed; 413 goto failed;
414 } 414 }
415 415
416 if (rc == NGX_AGAIN) { 416 if (rc == NGX_AGAIN) {
417 ctx->state = sw_skip;
417 continue; 418 continue;
418 } 419 }
419 420
420 /* rc == NGX_DONE */ 421 /* rc == NGX_DONE */
421 422
422 ctx->size = st->length; 423 ctx->size = st->length;
423 return NGX_OK; 424 ctx->state = sw_start;
424 } 425 }
425 426
426 if (!b->last_buf) { 427 if (ctx->state == sw_skip) {
427 ctx->length = 1; 428 ctx->length = 1;
428 return NGX_AGAIN; 429 return NGX_AGAIN;
429 } 430 }
430 431
431 if (st->state) { 432 if (b->pos == b->last) {
432 goto failed; 433 ctx->length = ctx->size;
433 } 434 return NGX_AGAIN;
434 435 }
435 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse header done"); 436
436 437 return NGX_OK;
437 return NGX_DONE;
438 438
439 failed: 439 failed:
440 440
441 return NGX_ERROR; 441 return NGX_ERROR;
442 } 442 }