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

Method prepareBodyStream

Libraries/Http/HttpConnection.cpp:487–532  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

485void HttpIncomingMessage::abortBodyStream() { bodyStream.destroy(); }
486
487Result HttpIncomingMessage::prepareBodyStream(AsyncBuffersPool& buffersPool, Function<Result()>&& onReadRequest,
488 bool allowCloseDelimited)
489{
490 StringSpan transferEncoding;
491 StringSpan contentLengthValue;
492 const bool hasTransferEncoding = getHeader("Transfer-Encoding", transferEncoding);
493 if (hasTransferEncoding and getHeader("Content-Length", contentLengthValue))
494 {
495 return Result::Error("HttpIncomingMessage conflicting Content-Length and Transfer-Encoding");
496 }
497
498 if (hasTransferEncoding)
499 {
500 if (not scHttpTransferEncodingIsChunked(transferEncoding))
501 {
502 return Result::Error("HttpIncomingMessage unsupported Transfer-Encoding");
503 }
504 bodyFramingKind = HttpBodyFramingKind::Chunked;
505 bodyBytesRemaining = 0;
506 bodyComplete = false;
507 chunkedState = ChunkedState::Size;
508 chunkedChunkSize = 0;
509 chunkedBytesRemaining = 0;
510 chunkedSizeHasDigits = false;
511 }
512 else if (getHeader("Content-Length", contentLengthValue))
513 {
514 bodyFramingKind = HttpBodyFramingKind::ContentLength;
515 bodyBytesRemaining = getParser().contentLength;
516 bodyComplete = (bodyBytesRemaining == 0);
517 }
518 else if (allowCloseDelimited)
519 {
520 bodyFramingKind = HttpBodyFramingKind::CloseDelimited;
521 bodyBytesRemaining = 0;
522 bodyComplete = false;
523 }
524 else
525 {
526 bodyFramingKind = HttpBodyFramingKind::None;
527 bodyBytesRemaining = 0;
528 bodyComplete = true;
529 }
530
531 return initBodyStream(buffersPool, move(onReadRequest));
532}
533
534Result HttpIncomingMessage::processBodyData(AsyncReadableStream& sourceStream, AsyncBufferView::ID bufferID,
535 Span<const char> readData, bool allowTrailingData)

Callers 2

onStreamReceiveMethod · 0.80
onResponseDataMethod · 0.80

Calls 2

ErrorEnum · 0.50

Tested by

no test coverage detected