MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / processBodyData

Method processBodyData

Libraries/Http/HttpConnection.cpp:534–730  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

532}
533
534Result 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 {

Callers 3

onRequestBodyDataMethod · 0.80
onResponseDataMethod · 0.80
onResponseBodyDataMethod · 0.80

Calls 10

reactivateMethod · 0.80
pauseMethod · 0.80
unrefBufferMethod · 0.80
scHttpHexValueFunction · 0.70
ErrorEnum · 0.50
ResultClass · 0.50
sizeInBytesMethod · 0.45
dataMethod · 0.45
createChildViewMethod · 0.45
unshiftMethod · 0.45

Tested by

no test coverage detected