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

Method onResponseData

Libraries/Http/HttpAsyncClient.cpp:708–820  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

706 if (response.getParser().statusCode == 204 or response.getParser().statusCode == 304)
707 {
708 return true;
709 }
710 return response.getParser().statusCode >= 100 and response.getParser().statusCode < 200;
711}
712
713bool HttpAsyncClient::responseHasKnownLength() const
714{
715 StringSpan contentLength;
716 return response.getHeader("Content-Length", contentLength);
717}
718
719void HttpAsyncClient::onResponseData(AsyncBufferView::ID bufferID)
720{
721 Span<const char> readData;
722 Result readable = connection->buffersPool.getReadableData(bufferID, readData);
723 if (not readable)
724 {
725 fail(readable);
726 return;
727 }
728
729 Result parseRes = response.writeHeaders(static_cast<uint32_t>(connection->getHeaderMemory().sizeInBytes()),
730 readData, connection->getReadableTransportStream(), bufferID);
731 if (not parseRes)
732 {
733 fail(parseRes);
734 return;
735 }
736 if (not response.hasReceivedHeaders())
737 {
738 return;
739 }
740
741 const bool removed = connection->getReadableTransportStream()
742 .eventData.removeListener<HttpAsyncClient, &HttpAsyncClient::onResponseData>(*this);
743 (void)(removed);
744
745 if (response.getParser().statusCode < 200 and not responseMustNotHaveBody())
746 {
747 fail(Result::Error("HttpAsyncClient does not support informational responses"));
748 return;
749 }
750
751 Result prepareBody(true);
752 if (responseMustNotHaveBody())
753 {
754 response.setBodyBytesRemaining(0);
755 response.setBodyFramingKind(HttpBodyFramingKind::None);
756 response.setBodyComplete(true);
757 prepareBody = response.initBodyStream(connection->buffersPool,
758 {[this]() -> Result { return onResponseBodyStreamRead(); }});
759 }
760 else
761 {
762 prepareBody = response.prepareBodyStream(connection->buffersPool,
763 {[this]() -> Result { return onResponseBodyStreamRead(); }}, true);
764 }
765 if (not prepareBody)

Callers

nothing calls this directly

Calls 12

getReadableDataMethod · 0.80
writeHeadersMethod · 0.80
initBodyStreamMethod · 0.80
prepareBodyStreamMethod · 0.80
getHeadersLengthMethod · 0.80
processBodyDataMethod · 0.80
unrefBufferMethod · 0.80
ErrorEnum · 0.50
sizeInBytesMethod · 0.45
isValidMethod · 0.45
createChildViewMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected