mirror of https://github.com/aria2/aria2
Use move to send string data into SocketBuffer::pushStr
parent
508109edbb
commit
fba7e7ee8b
|
@ -85,7 +85,7 @@ bool FtpConnection::sendUser()
|
||||||
request += "\r\n";
|
request += "\r\n";
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
||||||
cuid_, "USER ********"));
|
cuid_, "USER ********"));
|
||||||
socketBuffer_.pushStr(request);
|
socketBuffer_.pushStr(std::move(request));
|
||||||
}
|
}
|
||||||
socketBuffer_.send();
|
socketBuffer_.send();
|
||||||
return socketBuffer_.sendBufferIsEmpty();
|
return socketBuffer_.sendBufferIsEmpty();
|
||||||
|
@ -99,7 +99,7 @@ bool FtpConnection::sendPass()
|
||||||
request += "\r\n";
|
request += "\r\n";
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
||||||
cuid_, "PASS ********"));
|
cuid_, "PASS ********"));
|
||||||
socketBuffer_.pushStr(request);
|
socketBuffer_.pushStr(std::move(request));
|
||||||
}
|
}
|
||||||
socketBuffer_.send();
|
socketBuffer_.send();
|
||||||
return socketBuffer_.sendBufferIsEmpty();
|
return socketBuffer_.sendBufferIsEmpty();
|
||||||
|
@ -113,7 +113,7 @@ bool FtpConnection::sendType()
|
||||||
request += "\r\n";
|
request += "\r\n";
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
||||||
cuid_,request.c_str()));
|
cuid_,request.c_str()));
|
||||||
socketBuffer_.pushStr(request);
|
socketBuffer_.pushStr(std::move(request));
|
||||||
}
|
}
|
||||||
socketBuffer_.send();
|
socketBuffer_.send();
|
||||||
return socketBuffer_.sendBufferIsEmpty();
|
return socketBuffer_.sendBufferIsEmpty();
|
||||||
|
@ -125,7 +125,7 @@ bool FtpConnection::sendPwd()
|
||||||
std::string request = "PWD\r\n";
|
std::string request = "PWD\r\n";
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
||||||
cuid_,request.c_str()));
|
cuid_,request.c_str()));
|
||||||
socketBuffer_.pushStr(request);
|
socketBuffer_.pushStr(std::move(request));
|
||||||
}
|
}
|
||||||
socketBuffer_.send();
|
socketBuffer_.send();
|
||||||
return socketBuffer_.sendBufferIsEmpty();
|
return socketBuffer_.sendBufferIsEmpty();
|
||||||
|
@ -139,7 +139,7 @@ bool FtpConnection::sendCwd(const std::string& dir)
|
||||||
request += "\r\n";
|
request += "\r\n";
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
||||||
cuid_,request.c_str()));
|
cuid_,request.c_str()));
|
||||||
socketBuffer_.pushStr(request);
|
socketBuffer_.pushStr(std::move(request));
|
||||||
}
|
}
|
||||||
socketBuffer_.send();
|
socketBuffer_.send();
|
||||||
return socketBuffer_.sendBufferIsEmpty();
|
return socketBuffer_.sendBufferIsEmpty();
|
||||||
|
@ -154,7 +154,7 @@ bool FtpConnection::sendMdtm()
|
||||||
request += "\r\n";
|
request += "\r\n";
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
||||||
cuid_, request.c_str()));
|
cuid_, request.c_str()));
|
||||||
socketBuffer_.pushStr(request);
|
socketBuffer_.pushStr(std::move(request));
|
||||||
}
|
}
|
||||||
socketBuffer_.send();
|
socketBuffer_.send();
|
||||||
return socketBuffer_.sendBufferIsEmpty();
|
return socketBuffer_.sendBufferIsEmpty();
|
||||||
|
@ -169,7 +169,7 @@ bool FtpConnection::sendSize()
|
||||||
request += "\r\n";
|
request += "\r\n";
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
||||||
cuid_, request.c_str()));
|
cuid_, request.c_str()));
|
||||||
socketBuffer_.pushStr(request);
|
socketBuffer_.pushStr(std::move(request));
|
||||||
}
|
}
|
||||||
socketBuffer_.send();
|
socketBuffer_.send();
|
||||||
return socketBuffer_.sendBufferIsEmpty();
|
return socketBuffer_.sendBufferIsEmpty();
|
||||||
|
@ -181,7 +181,7 @@ bool FtpConnection::sendEpsv()
|
||||||
std::string request("EPSV\r\n");
|
std::string request("EPSV\r\n");
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
||||||
cuid_, request.c_str()));
|
cuid_, request.c_str()));
|
||||||
socketBuffer_.pushStr(request);
|
socketBuffer_.pushStr(std::move(request));
|
||||||
}
|
}
|
||||||
socketBuffer_.send();
|
socketBuffer_.send();
|
||||||
return socketBuffer_.sendBufferIsEmpty();
|
return socketBuffer_.sendBufferIsEmpty();
|
||||||
|
@ -193,7 +193,7 @@ bool FtpConnection::sendPasv()
|
||||||
std::string request("PASV\r\n");
|
std::string request("PASV\r\n");
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
||||||
cuid_, request.c_str()));
|
cuid_, request.c_str()));
|
||||||
socketBuffer_.pushStr(request);
|
socketBuffer_.pushStr(std::move(request));
|
||||||
}
|
}
|
||||||
socketBuffer_.send();
|
socketBuffer_.send();
|
||||||
return socketBuffer_.sendBufferIsEmpty();
|
return socketBuffer_.sendBufferIsEmpty();
|
||||||
|
@ -223,7 +223,7 @@ bool FtpConnection::sendEprt(const std::shared_ptr<SocketCore>& serverSocket)
|
||||||
addrinfo.first.c_str(),
|
addrinfo.first.c_str(),
|
||||||
addrinfo.second);
|
addrinfo.second);
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, request.c_str()));
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, request.c_str()));
|
||||||
socketBuffer_.pushStr(request);
|
socketBuffer_.pushStr(std::move(request));
|
||||||
}
|
}
|
||||||
socketBuffer_.send();
|
socketBuffer_.send();
|
||||||
return socketBuffer_.sendBufferIsEmpty();
|
return socketBuffer_.sendBufferIsEmpty();
|
||||||
|
@ -243,7 +243,7 @@ bool FtpConnection::sendPort(const std::shared_ptr<SocketCore>& serverSocket)
|
||||||
addrinfo.second/256, addrinfo.second%256);
|
addrinfo.second/256, addrinfo.second%256);
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
||||||
cuid_, request.c_str()));
|
cuid_, request.c_str()));
|
||||||
socketBuffer_.pushStr(request);
|
socketBuffer_.pushStr(std::move(request));
|
||||||
}
|
}
|
||||||
socketBuffer_.send();
|
socketBuffer_.send();
|
||||||
return socketBuffer_.sendBufferIsEmpty();
|
return socketBuffer_.sendBufferIsEmpty();
|
||||||
|
@ -258,7 +258,7 @@ bool FtpConnection::sendRest(const std::shared_ptr<Segment>& segment)
|
||||||
segment->getPositionToWrite() : static_cast<int64_t>(0LL));
|
segment->getPositionToWrite() : static_cast<int64_t>(0LL));
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
||||||
cuid_, request.c_str()));
|
cuid_, request.c_str()));
|
||||||
socketBuffer_.pushStr(request);
|
socketBuffer_.pushStr(std::move(request));
|
||||||
}
|
}
|
||||||
socketBuffer_.send();
|
socketBuffer_.send();
|
||||||
return socketBuffer_.sendBufferIsEmpty();
|
return socketBuffer_.sendBufferIsEmpty();
|
||||||
|
@ -273,7 +273,7 @@ bool FtpConnection::sendRetr()
|
||||||
request += "\r\n";
|
request += "\r\n";
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
||||||
cuid_, request.c_str()));
|
cuid_, request.c_str()));
|
||||||
socketBuffer_.pushStr(request);
|
socketBuffer_.pushStr(std::move(request));
|
||||||
}
|
}
|
||||||
socketBuffer_.send();
|
socketBuffer_.send();
|
||||||
return socketBuffer_.sendBufferIsEmpty();
|
return socketBuffer_.sendBufferIsEmpty();
|
||||||
|
|
|
@ -105,7 +105,7 @@ void HttpConnection::sendRequest(const std::shared_ptr<HttpRequest>& httpRequest
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
||||||
cuid_,
|
cuid_,
|
||||||
eraseConfidentialInfo(request).c_str()));
|
eraseConfidentialInfo(request).c_str()));
|
||||||
socketBuffer_.pushStr(request);
|
socketBuffer_.pushStr(std::move(request));
|
||||||
socketBuffer_.send();
|
socketBuffer_.send();
|
||||||
std::shared_ptr<HttpRequestEntry> entry(new HttpRequestEntry(httpRequest));
|
std::shared_ptr<HttpRequestEntry> entry(new HttpRequestEntry(httpRequest));
|
||||||
outstandingHttpRequests_.push_back(entry);
|
outstandingHttpRequests_.push_back(entry);
|
||||||
|
@ -118,7 +118,7 @@ void HttpConnection::sendProxyRequest
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
||||||
cuid_,
|
cuid_,
|
||||||
eraseConfidentialInfo(request).c_str()));
|
eraseConfidentialInfo(request).c_str()));
|
||||||
socketBuffer_.pushStr(request);
|
socketBuffer_.pushStr(std::move(request));
|
||||||
socketBuffer_.send();
|
socketBuffer_.send();
|
||||||
std::shared_ptr<HttpRequestEntry> entry(new HttpRequestEntry(httpRequest));
|
std::shared_ptr<HttpRequestEntry> entry(new HttpRequestEntry(httpRequest));
|
||||||
outstandingHttpRequests_.push_back(entry);
|
outstandingHttpRequests_.push_back(entry);
|
||||||
|
|
|
@ -210,26 +210,27 @@ const std::string& HttpServer::getRequestPath() const
|
||||||
return lastRequestHeader_->getRequestPath();
|
return lastRequestHeader_->getRequestPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpServer::feedResponse(std::string& text, const std::string& contentType)
|
void HttpServer::feedResponse(std::string text,
|
||||||
|
const std::string& contentType)
|
||||||
{
|
{
|
||||||
feedResponse(200, "", text, contentType);
|
feedResponse(200, "", std::move(text), contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpServer::feedResponse(int status,
|
void HttpServer::feedResponse(int status,
|
||||||
const std::string& headers,
|
const std::string& headers,
|
||||||
const std::string& text,
|
std::string text,
|
||||||
const std::string& contentType)
|
const std::string& contentType)
|
||||||
{
|
{
|
||||||
std::string httpDate = Time().toHTTPDate();
|
std::string httpDate = Time().toHTTPDate();
|
||||||
std::string header= fmt("HTTP/1.1 %s\r\n"
|
std::string header = fmt("HTTP/1.1 %s\r\n"
|
||||||
"Date: %s\r\n"
|
"Date: %s\r\n"
|
||||||
"Content-Length: %lu\r\n"
|
"Content-Length: %lu\r\n"
|
||||||
"Expires: %s\r\n"
|
"Expires: %s\r\n"
|
||||||
"Cache-Control: no-cache\r\n",
|
"Cache-Control: no-cache\r\n",
|
||||||
getStatusString(status),
|
getStatusString(status),
|
||||||
httpDate.c_str(),
|
httpDate.c_str(),
|
||||||
static_cast<unsigned long>(text.size()),
|
static_cast<unsigned long>(text.size()),
|
||||||
httpDate.c_str());
|
httpDate.c_str());
|
||||||
if(!contentType.empty()) {
|
if(!contentType.empty()) {
|
||||||
header += "Content-Type: ";
|
header += "Content-Type: ";
|
||||||
header += contentType;
|
header += contentType;
|
||||||
|
@ -249,8 +250,8 @@ void HttpServer::feedResponse(int status,
|
||||||
header += headers;
|
header += headers;
|
||||||
header += "\r\n";
|
header += "\r\n";
|
||||||
A2_LOG_DEBUG(fmt("HTTP Server sends response:\n%s", header.c_str()));
|
A2_LOG_DEBUG(fmt("HTTP Server sends response:\n%s", header.c_str()));
|
||||||
socketBuffer_.pushStr(header);
|
socketBuffer_.pushStr(std::move(header));
|
||||||
socketBuffer_.pushStr(text);
|
socketBuffer_.pushStr(std::move(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpServer::feedUpgradeResponse(const std::string& protocol,
|
void HttpServer::feedUpgradeResponse(const std::string& protocol,
|
||||||
|
@ -264,7 +265,7 @@ void HttpServer::feedUpgradeResponse(const std::string& protocol,
|
||||||
protocol.c_str(),
|
protocol.c_str(),
|
||||||
headers.c_str());
|
headers.c_str());
|
||||||
A2_LOG_DEBUG(fmt("HTTP Server sends upgrade response:\n%s", header.c_str()));
|
A2_LOG_DEBUG(fmt("HTTP Server sends upgrade response:\n%s", header.c_str()));
|
||||||
socketBuffer_.pushStr(header);
|
socketBuffer_.pushStr(std::move(header));
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t HttpServer::sendResponse()
|
ssize_t HttpServer::sendResponse()
|
||||||
|
|
|
@ -111,7 +111,7 @@ public:
|
||||||
return reqType_;
|
return reqType_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void feedResponse(std::string& text, const std::string& contentType);
|
void feedResponse(std::string text, const std::string& contentType);
|
||||||
|
|
||||||
// Feeds HTTP response with the status code |status| (e.g.,
|
// Feeds HTTP response with the status code |status| (e.g.,
|
||||||
// 200). The |headers| is zero or more lines of HTTP header field
|
// 200). The |headers| is zero or more lines of HTTP header field
|
||||||
|
@ -119,7 +119,7 @@ public:
|
||||||
// body. The |contentType" is the content-type of the response body.
|
// body. The |contentType" is the content-type of the response body.
|
||||||
void feedResponse(int status,
|
void feedResponse(int status,
|
||||||
const std::string& headers = "",
|
const std::string& headers = "",
|
||||||
const std::string& text = "",
|
std::string text = "",
|
||||||
const std::string& contentType = "");
|
const std::string& contentType = "");
|
||||||
|
|
||||||
// Feeds "101 Switching Protocols" response. The |protocol| will
|
// Feeds "101 Switching Protocols" response. The |protocol| will
|
||||||
|
|
|
@ -107,7 +107,7 @@ void HttpServerBodyCommand::sendJsonRpcResponse
|
||||||
bool gzip = httpServer_->supportsGZip();
|
bool gzip = httpServer_->supportsGZip();
|
||||||
std::string responseData = rpc::toJson(res, callback, gzip);
|
std::string responseData = rpc::toJson(res, callback, gzip);
|
||||||
if(res.code == 0) {
|
if(res.code == 0) {
|
||||||
httpServer_->feedResponse(responseData,
|
httpServer_->feedResponse(std::move(responseData),
|
||||||
getJsonRpcContentType(!callback.empty()));
|
getJsonRpcContentType(!callback.empty()));
|
||||||
} else {
|
} else {
|
||||||
httpServer_->disableKeepAlive();
|
httpServer_->disableKeepAlive();
|
||||||
|
@ -123,7 +123,7 @@ void HttpServerBodyCommand::sendJsonRpcResponse
|
||||||
httpCode = 500;
|
httpCode = 500;
|
||||||
};
|
};
|
||||||
httpServer_->feedResponse(httpCode, A2STR::NIL,
|
httpServer_->feedResponse(httpCode, A2STR::NIL,
|
||||||
responseData,
|
std::move(responseData),
|
||||||
getJsonRpcContentType(!callback.empty()));
|
getJsonRpcContentType(!callback.empty()));
|
||||||
}
|
}
|
||||||
addHttpServerResponseCommand();
|
addHttpServerResponseCommand();
|
||||||
|
@ -135,7 +135,7 @@ void HttpServerBodyCommand::sendJsonRpcBatchResponse
|
||||||
{
|
{
|
||||||
bool gzip = httpServer_->supportsGZip();
|
bool gzip = httpServer_->supportsGZip();
|
||||||
std::string responseData = rpc::toJsonBatch(results, callback, gzip);
|
std::string responseData = rpc::toJsonBatch(results, callback, gzip);
|
||||||
httpServer_->feedResponse(responseData,
|
httpServer_->feedResponse(std::move(responseData),
|
||||||
getJsonRpcContentType(!callback.empty()));
|
getJsonRpcContentType(!callback.empty()));
|
||||||
addHttpServerResponseCommand();
|
addHttpServerResponseCommand();
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ bool HttpServerBodyCommand::execute()
|
||||||
rpc::RpcResponse res = method->execute(req, e_);
|
rpc::RpcResponse res = method->execute(req, e_);
|
||||||
bool gzip = httpServer_->supportsGZip();
|
bool gzip = httpServer_->supportsGZip();
|
||||||
std::string responseData = rpc::toXml(res, gzip);
|
std::string responseData = rpc::toXml(res, gzip);
|
||||||
httpServer_->feedResponse(responseData, "text/xml");
|
httpServer_->feedResponse(std::move(responseData), "text/xml");
|
||||||
addHttpServerResponseCommand();
|
addHttpServerResponseCommand();
|
||||||
#else // !ENABLE_XML_RPC
|
#else // !ENABLE_XML_RPC
|
||||||
httpServer_->feedResponse(404);
|
httpServer_->feedResponse(404);
|
||||||
|
|
Loading…
Reference in New Issue