| 1026 | } |
| 1027 | |
| 1028 | Result HttpOutgoingMessage::sendHeaders(Function<void(AsyncBufferView::ID)> callback) |
| 1029 | { |
| 1030 | SC_TRY_MSG(not headersSent, "Headers already sent"); |
| 1031 | SC_TRY_MSG(responseHeaders.writtenBytes() != 0, "startResponse or startRequest must be the first call"); |
| 1032 | SC_TRY_MSG(not(chunkedTransferEncodingEnabled and contentLengthAdded), |
| 1033 | "HttpOutgoingMessage does not support Content-Length with Transfer-Encoding"); |
| 1034 | |
| 1035 | if (chunkedTransferEncodingEnabled) |
| 1036 | { |
| 1037 | SC_TRY_MSG(destinationStream != nullptr, "HttpOutgoingMessage missing destination stream"); |
| 1038 | SC_TRY(chunkedWritableStream.init(destinationStream->getBuffersPool(), *destinationStream)); |
| 1039 | writableStream = &chunkedWritableStream; |
| 1040 | } |
| 1041 | else |
| 1042 | { |
| 1043 | writableStream = destinationStream; |
| 1044 | } |
| 1045 | |
| 1046 | if (not connectionHeaderAdded) |
| 1047 | { |
| 1048 | if (forceDisableKeepAlive or not keepAlive) |
| 1049 | { |
| 1050 | SC_TRY(responseHeaders.appendLiteral("Connection: close\r\n", |
| 1051 | "HttpOutgoingMessage::appendAscii - header space is finished")); |
| 1052 | } |
| 1053 | else |
| 1054 | { |
| 1055 | SC_TRY(responseHeaders.appendLiteral("Connection: keep-alive\r\n", |
| 1056 | "HttpOutgoingMessage::appendAscii - header space is finished")); |
| 1057 | } |
| 1058 | } |
| 1059 | SC_TRY(responseHeaders.appendLiteral("\r\n", "HttpOutgoingMessage::appendAscii - header space is finished")); |
| 1060 | SC_TRY(destinationStream->write(responseHeaders.written(), move(callback))); |
| 1061 | headersSent = true; |
| 1062 | return Result(true); |
| 1063 | } |
| 1064 | |
| 1065 | void HttpOutgoingMessage::reset() |
| 1066 | { |