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

Method receiveEchoBody

Examples/ApiServer/ApiServer.cpp:105–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103 }
104
105 void receiveEchoBody(HttpConnection& connection)
106 {
107 SC_ASSERT_RELEASE(connection.response.startResponse(200));
108 SC_ASSERT_RELEASE(connection.response.addHeader("Content-Type", HttpContentTypeTextPlainUtf8()));
109 if (connection.request.getBodyFramingKind() == HttpBodyFramingKind::ContentLength)
110 {
111 SC_ASSERT_RELEASE(connection.response.addContentLength(connection.request.getBodyBytesRemaining()));
112 }
113 else
114 {
115 connection.response.setKeepAlive(false);
116 }
117 SC_ASSERT_RELEASE(connection.response.sendHeaders());
118
119 if (connection.request.getBodyFramingKind() == HttpBodyFramingKind::None or
120 (connection.request.getBodyFramingKind() == HttpBodyFramingKind::ContentLength and
121 connection.request.getBodyBytesRemaining() == 0))
122 {
123 SC_ASSERT_RELEASE(connection.response.end());
124 return;
125 }
126
127 connection.pipeline.source = &connection.request.getReadableStream();
128 connection.pipeline.sinks[0] = &connection.response.getWritableStream();
129 SC_ASSERT_RELEASE(connection.pipeline.pipe());
130 SC_ASSERT_RELEASE(connection.pipeline.start());
131 }
132
133 Result notFound(HttpConnection& connection) { return connection.sendTextCopy(404, "not found\n"); }
134};

Callers

nothing calls this directly

Calls 9

startResponseMethod · 0.80
addContentLengthMethod · 0.80
setKeepAliveMethod · 0.80
sendHeadersMethod · 0.80
addHeaderMethod · 0.45
endMethod · 0.45
pipeMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected