| 283 | } |
| 284 | |
| 285 | Result HttpConnection::sendBodyCopy(int code, StringSpan body, StringSpan contentType) |
| 286 | { |
| 287 | AsyncBufferView::ID bufferID; |
| 288 | if (body.sizeInBytes() > 0) |
| 289 | { |
| 290 | Span<char> writableData; |
| 291 | SC_TRY(buffersPool.requestNewBuffer(body.sizeInBytes(), bufferID, writableData)); |
| 292 | ::memcpy(writableData.data(), body.bytesWithoutTerminator(), body.sizeInBytes()); |
| 293 | buffersPool.setNewBufferSize(bufferID, body.sizeInBytes()); |
| 294 | } |
| 295 | auto releaseBuffer = MakeDeferred( |
| 296 | [&] |
| 297 | { |
| 298 | if (bufferID.isValid()) |
| 299 | { |
| 300 | buffersPool.unrefBuffer(bufferID); |
| 301 | } |
| 302 | }); |
| 303 | |
| 304 | SC_TRY(response.startBody(code, body.sizeInBytes(), contentType)); |
| 305 | SC_TRY(response.sendHeaders()); |
| 306 | if (bufferID.isValid()) |
| 307 | { |
| 308 | SC_TRY(response.getWritableStream().write(bufferID)); |
| 309 | } |
| 310 | return response.end(); |
| 311 | } |
| 312 | |
| 313 | Result HttpConnection::sendTextCopy(int code, StringSpan body) |
| 314 | { |
no test coverage detected