MCPcopy Create free account
hub / github.com/3rdparty/libprocess / ConnectionProcess

Class ConnectionProcess

src/http.cpp:1126–1357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1124
1125
1126class ConnectionProcess : public Process<ConnectionProcess>
1127{
1128public:
1129 ConnectionProcess(const network::Socket& _socket)
1130 : ProcessBase(ID::generate("__http_connection__")),
1131 socket(_socket),
1132 sendChain(Nothing()),
1133 close(false) {}
1134
1135 Future<Response> send(const Request& request, bool streamedResponse)
1136 {
1137 if (!disconnection.future().isPending()) {
1138 return Failure("Disconnected");
1139 }
1140
1141 if (close) {
1142 return Failure("Cannot pipeline after 'Connection: close'");
1143 }
1144
1145 if (request.type == Request::PIPE) {
1146 if (request.reader.isNone()) {
1147 return Failure("Request reader must be set for PIPE request");
1148 }
1149
1150 if (!request.body.empty()) {
1151 return Failure("Request body must be empty for PIPE request");
1152 }
1153
1154 Option<string> contentLength = request.headers.get("Content-Length");
1155 if (request.headers.contains("Content-Length")) {
1156 return Failure("'Content-Length' cannot be set for PIPE request");
1157 }
1158 }
1159
1160 if (!request.keepAlive) {
1161 close = true;
1162 }
1163
1164 // We must chain the calls to Socket::send as it
1165 // otherwise interleaves data across calls.
1166 network::Socket socket_ = socket;
1167
1168 sendChain = sendChain
1169 .then([socket_, request]() {
1170 return _send(socket_, encode(request));
1171 });
1172
1173 // If we can't write to the socket, disconnect.
1174 sendChain
1175 .onFailed(defer(self(), [this](const string& failure) {
1176 disconnect(failure);
1177 }));
1178
1179 Promise<Response> promise;
1180 Future<Response> response = promise.future();
1181
1182 pipeline.push(std::make_tuple(streamedResponse, std::move(promise)));
1183

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected