MCPcopy Create free account
hub / github.com/aria2/aria2 / execute

Method execute

src/HttpServerBodyCommand.cc:175–343  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173}
174
175bool HttpServerBodyCommand::execute()
176{
177 if (e_->getRequestGroupMan()->downloadFinished() || e_->isHaltRequested()) {
178 return true;
179 }
180 try {
181 if (socket_->isReadable(0) || (writeCheck_ && socket_->isWritable(0)) ||
182 socket_->getRecvBufferedLength() ||
183 !httpServer_->getSocketRecvBuffer()->bufferEmpty() ||
184 httpServer_->getContentLength() == 0) {
185 timeoutTimer_ = global::wallclock();
186
187 if (httpServer_->receiveBody()) {
188 std::string reqPath = httpServer_->getRequestPath();
189 reqPath.erase(std::find(reqPath.begin(), reqPath.end(), '#'),
190 reqPath.end());
191 std::string query(std::find(reqPath.begin(), reqPath.end(), '?'),
192 reqPath.end());
193 reqPath.erase(reqPath.size() - query.size(), query.size());
194
195 if (httpServer_->getMethod() == "OPTIONS") {
196 // Response to Preflight Request.
197 // See http://www.w3.org/TR/cors/
198 auto& header = httpServer_->getRequestHeader();
199 std::string accessControlHeaders;
200 if (!header->find(HttpHeader::ORIGIN).empty() &&
201 !header->find(HttpHeader::ACCESS_CONTROL_REQUEST_METHOD)
202 .empty() &&
203 !httpServer_->getAllowOrigin().empty()) {
204 accessControlHeaders +=
205 "Access-Control-Allow-Methods: POST, GET, OPTIONS\r\n"
206 "Access-Control-Max-Age: 1728000\r\n";
207 const std::string& accReqHeaders =
208 header->find(HttpHeader::ACCESS_CONTROL_REQUEST_HEADERS);
209 if (!accReqHeaders.empty()) {
210 // We allow all headers requested.
211 accessControlHeaders += "Access-Control-Allow-Headers: ";
212 accessControlHeaders += accReqHeaders;
213 accessControlHeaders += "\r\n";
214 }
215 }
216 httpServer_->feedResponse(200, accessControlHeaders);
217 addHttpServerResponseCommand(false);
218 return true;
219 }
220
221 // Do something for requestpath and body
222 switch (httpServer_->getRequestType()) {
223 case RPC_TYPE_XML: {
224#ifdef ENABLE_XML_RPC
225 auto dw = static_cast<rpc::XmlRpcDiskWriter*>(httpServer_->getBody());
226 int error;
227 error = dw->finalize();
228 rpc::RpcRequest req;
229 if (error == 0) {
230 req = dw->getResult();
231 }
232 dw->reset();

Callers

nothing calls this directly

Calls 15

fmtFunction · 0.85
getMethodFunction · 0.85
toXmlFunction · 0.85
decodeGetParamsFunction · 0.85
processJsonRpcRequestFunction · 0.85
getRequestGroupManMethod · 0.80
isReadableMethod · 0.80
isWritableMethod · 0.80
bufferEmptyMethod · 0.80
receiveBodyMethod · 0.80
eraseMethod · 0.80

Tested by

no test coverage detected