| 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 | |
| 1037 | Result 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 | |
| 1053 | Result 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)); |