| 532 | } |
| 533 | |
| 534 | Result HttpIncomingMessage::processBodyData(AsyncReadableStream& sourceStream, AsyncBufferView::ID bufferID, |
| 535 | Span<const char> readData, bool allowTrailingData) |
| 536 | { |
| 537 | if (bodyFramingKind == HttpBodyFramingKind::None) |
| 538 | { |
| 539 | if (readData.sizeInBytes() > 0) |
| 540 | { |
| 541 | return Result::Error("HttpIncomingMessage unexpected body data"); |
| 542 | } |
| 543 | return Result(true); |
| 544 | } |
| 545 | |
| 546 | if (bodyFramingKind == HttpBodyFramingKind::ContentLength or bodyFramingKind == HttpBodyFramingKind::CloseDelimited) |
| 547 | { |
| 548 | if (bodyFramingKind == HttpBodyFramingKind::ContentLength and readData.sizeInBytes() > bodyBytesRemaining) |
| 549 | { |
| 550 | return Result::Error("HttpIncomingMessage received body beyond Content-Length"); |
| 551 | } |
| 552 | |
| 553 | const uint64_t remainingBeforePush = bodyBytesRemaining; |
| 554 | const bool shouldContinue = pushBodyData(bufferID, readData.sizeInBytes()); |
| 555 | if (not bodyStream.hasBeenDestroyed()) |
| 556 | { |
| 557 | bodyStream.reactivate(shouldContinue); |
| 558 | } |
| 559 | if (bodyFramingKind == HttpBodyFramingKind::ContentLength) |
| 560 | { |
| 561 | if (bodyBytesRemaining == remainingBeforePush) |
| 562 | { |
| 563 | SC_TRY(consumeBodyBytes(readData.sizeInBytes())); |
| 564 | } |
| 565 | else |
| 566 | { |
| 567 | SC_TRY_MSG(bodyBytesRemaining + readData.sizeInBytes() == remainingBeforePush, |
| 568 | "HttpIncomingMessage body stream consumed an unexpected byte count"); |
| 569 | } |
| 570 | } |
| 571 | if (bodyFramingKind == HttpBodyFramingKind::ContentLength and bodyBytesRemaining == 0) |
| 572 | { |
| 573 | finishBodyStream(); |
| 574 | } |
| 575 | if (not shouldContinue) |
| 576 | { |
| 577 | sourceStream.pause(); |
| 578 | } |
| 579 | return Result(true); |
| 580 | } |
| 581 | |
| 582 | size_t rawOffset = 0; |
| 583 | while (rawOffset < readData.sizeInBytes()) |
| 584 | { |
| 585 | const char current = readData.data()[rawOffset]; |
| 586 | switch (chunkedState) |
| 587 | { |
| 588 | case ChunkedState::Size: { |
| 589 | uint8_t hexValue = 0; |
| 590 | if (scHttpHexValue(current, hexValue)) |
| 591 | { |
no test coverage detected