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

Method sendBodyCopy

Libraries/Http/HttpConnection.cpp:285–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

283}
284
285Result 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
313Result HttpConnection::sendTextCopy(int code, StringSpan body)
314{

Callers 1

handleRequestMethod · 0.80

Calls 11

MakeDeferredFunction · 0.85
requestNewBufferMethod · 0.80
setNewBufferSizeMethod · 0.80
unrefBufferMethod · 0.80
startBodyMethod · 0.80
sendHeadersMethod · 0.80
sizeInBytesMethod · 0.45
dataMethod · 0.45
isValidMethod · 0.45
writeMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected