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

Method sendHeaders

Libraries/Http/HttpConnection.cpp:1028–1063  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1026 if (headersSent)
1027 return Result::Error(HttpResultCategory, HttpError::HeadersAlreadySent);
1028 if (responseHeaders.writtenBytes() == 0)
1029 return Result::Error(HttpResultCategory, HttpError::HeaderStartMissing);
1030 if (chunkedTransferEncodingEnabled or transferEncodingAdded)
1031 return Result::Error(HttpResultCategory, HttpError::ContentLengthTransferEncodingConflict);
1032 SC_TRY(responseHeaders.appendContentLength(value, HttpError::HeaderOutputTooSmall));
1033 contentLengthAdded = true;
1034 return Result(true);
1035}
1036
1037Result HttpOutgoingMessage::setChunkedTransferEncoding()
1038{
1039 if (headersSent)
1040 return Result::Error(HttpResultCategory, HttpError::HeadersAlreadySent);
1041 if (chunkedTransferEncodingEnabled)
1042 {
1043 return Result(true);
1044 }
1045 chunkedTransferEncodingEnabled = true;
1046 if (not transferEncodingAdded)
1047 {
1048 SC_TRY(addHeader("Transfer-Encoding", "chunked"));
1049 }
1050 return Result(true);
1051}
1052
1053Result HttpOutgoingMessage::sendHeaders(Function<void(AsyncBufferView::ID)> callback)
1054{
1055 if (headersSent)
1056 return Result::Error(HttpResultCategory, HttpError::HeadersAlreadySent);
1057 if (responseHeaders.writtenBytes() == 0)
1058 return Result::Error(HttpResultCategory, HttpError::HeaderStartMissing);
1059 if (chunkedTransferEncodingEnabled and contentLengthAdded)
1060 return Result::Error(HttpResultCategory, HttpError::ContentLengthTransferEncodingConflict);
1061
1062 if (chunkedTransferEncodingEnabled)
1063 {
1064 if (destinationStream == nullptr)
1065 return Result::Error(HttpResultCategory, HttpError::DestinationStreamMissing);
1066 SC_TRY(chunkedWritableStream.init(destinationStream->getBuffersPool(), *destinationStream));

Callers 15

blockingGetMethod · 0.80
blockingPostMethod · 0.80
blockingCustomHeadersMethod · 0.80
contentCodingPolicyMethod · 0.80
protocolPreferenceMethod · 0.80
proxyOptionsMethod · 0.80
methodCoverageMethod · 0.80
onEndMethod · 0.80
pollGetMethod · 0.80
pollConcurrentGetsMethod · 0.80

Calls 8

writtenMethod · 0.80
getBoundaryMethod · 0.80
ResultClass · 0.50
initMethod · 0.45
writeMethod · 0.45
sizeInBytesMethod · 0.45
appendMethod · 0.45
isValidMethod · 0.45

Tested by 15

blockingGetMethod · 0.64
blockingPostMethod · 0.64
blockingCustomHeadersMethod · 0.64
contentCodingPolicyMethod · 0.64
protocolPreferenceMethod · 0.64
proxyOptionsMethod · 0.64
methodCoverageMethod · 0.64
onEndMethod · 0.64
pollGetMethod · 0.64
pollConcurrentGetsMethod · 0.64