| 532 | bodyFramingKind = HttpBodyFramingKind::ContentLength; |
| 533 | bodyBytesRemaining = getParser().contentLength; |
| 534 | bodyComplete = (bodyBytesRemaining == 0); |
| 535 | } |
| 536 | else if (allowCloseDelimited) |
| 537 | { |
| 538 | bodyFramingKind = HttpBodyFramingKind::CloseDelimited; |
| 539 | bodyBytesRemaining = 0; |
| 540 | bodyComplete = false; |
| 541 | } |
| 542 | else |
| 543 | { |
| 544 | bodyFramingKind = HttpBodyFramingKind::None; |
| 545 | bodyBytesRemaining = 0; |
| 546 | bodyComplete = true; |
| 547 | } |
| 548 | |
| 549 | return initBodyStream(buffersPool, move(onReadRequest)); |
| 550 | } |
| 551 | |
| 552 | Result HttpIncomingMessage::processBodyData(AsyncReadableStream& sourceStream, AsyncBufferView::ID bufferID, |
| 553 | Span<const char> readData, bool allowTrailingData) |
| 554 | { |
| 555 | if (bodyFramingKind == HttpBodyFramingKind::None) |
| 556 | { |
| 557 | if (readData.sizeInBytes() > 0) |
| 558 | { |
| 559 | return Result::Error(HttpResultCategory, HttpError::UnexpectedBodyData); |
| 560 | } |
| 561 | return Result(true); |
| 562 | } |
| 563 | |
| 564 | if (bodyFramingKind == HttpBodyFramingKind::ContentLength or bodyFramingKind == HttpBodyFramingKind::CloseDelimited) |
| 565 | { |
| 566 | if (bodyFramingKind == HttpBodyFramingKind::ContentLength and readData.sizeInBytes() > bodyBytesRemaining) |
| 567 | { |
| 568 | return Result::Error(HttpResultCategory, HttpError::BodyExceedsContentLength); |
| 569 | } |
| 570 | |
| 571 | const uint64_t remainingBeforePush = bodyBytesRemaining; |
| 572 | const bool shouldContinue = pushBodyData(bufferID, readData.sizeInBytes()); |
| 573 | if (not bodyStream.hasBeenDestroyed()) |
| 574 | { |
| 575 | bodyStream.reactivate(shouldContinue); |
| 576 | } |
| 577 | if (bodyFramingKind == HttpBodyFramingKind::ContentLength) |
| 578 | { |
| 579 | if (bodyBytesRemaining == remainingBeforePush) |
| 580 | { |
| 581 | SC_TRY(consumeBodyBytes(readData.sizeInBytes())); |
| 582 | } |
| 583 | else |
| 584 | { |
| 585 | if (bodyBytesRemaining + readData.sizeInBytes() != remainingBeforePush) |
| 586 | return Result::Error(HttpResultCategory, HttpError::BodyStreamConsumptionMismatch); |
| 587 | } |
| 588 | } |
| 589 | if (bodyFramingKind == HttpBodyFramingKind::ContentLength and bodyBytesRemaining == 0) |
| 590 | { |
| 591 | finishBodyStream(); |
no test coverage detected