本文整理汇总了C++中HttpMessage::removeAttribute方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpMessage::removeAttribute方法的具体用法?C++ HttpMessage::removeAttribute怎么用?C++ HttpMessage::removeAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpMessage
的用法示例。
在下文中一共展示了HttpMessage::removeAttribute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: constructMessage
// ---------------< construct a general message to be sent as acknowledgement >---------
HttpMessage ClientHandler::constructMessage(HttpMessage msg) {
msg.removeAttribute("content-length");
std::string bodyString = "<file>" + msg.findValue("file") + "</file>";
std::string sizeString = Converter<size_t>::toString(bodyString.size());
msg.addAttribute(HttpMessage::Attribute("content-length", sizeString));
msg.addBody(bodyString);
return msg;
}
示例2: readMessage
//----< this defines processing to frame messages >------------------
HttpMessage ClientHandler::readMessage(Socket& socket) {
connectionClosed_ = false;
HttpMessage msg;
while (true) { // read message attributes
std::string attribString = socket.recvString('\n');
if (attribString.size() > 1) {
HttpMessage::Attribute attrib = HttpMessage::parseAttribute(attribString);
msg.addAttribute(attrib);
}
else break;
}
if (msg.attributes().size() == 0) { // If client is done, connection breaks
connectionClosed_ = true; // and recvString returns empty string
return msg;
}
if (msg.attributes()[0].first == "POST") // read body if POST
{
if (msg.attributes()[0].second == "Message") msg = readBody(msg, socket); // case 0 - normal message
else if (msg.attributes()[0].second == "File") { // case 1 - client sending file to server
saveFileServer(msg, socket);
msg = constructMessage(msg);
}
else if (msg.attributes()[0].second == "closePackage") msg = closePackage(msg); // case 7 - close a package
else if (msg.attributes()[0].second == "returnFile") { // case 4 - server sends files to client
saveFileClient(msg, socket);
msg = constructMessage(msg);
}
}
else if (msg.attributes()[0].first == "GET") { // read message if GET
msg = readBody(msg, socket);
if (msg.attributes()[0].second == "getFileList") msg = getFileList(msg); // case 5 - request list of packages
else if (msg.attributes()[0].second == "getFileNameList") msg = getFileNameList(msg); // case 6 - request list of files in a packages
else if (msg.attributes()[0].second == "File" || msg.attributes()[0].second == "FileWithDeps")
msg = getFiles(msg, msg.attributes()[0].second);
}
else {
msg.removeAttribute("content-length");
std::string bodyString = "<msg>Error message</msg>";
std::string sizeString = Converter<size_t>::toString(bodyString.size());
msg.addAttribute(HttpMessage::Attribute("content-length", sizeString));
msg.addBody(bodyString);
}
return msg;
}
示例3: main
int main()
{
Utils::Title("Testing HttpMessage class", '=');
HttpMessage msg;
msg.addAttribute(HttpMessage::attribute("Command", "GetFiles"));
msg.addAttribute(HttpMessage::attribute("ToAddr", "127.0.0.1:8080"));
msg.addAttribute(HttpMessage::attribute("FromAddr", "127.0.0.1:8081"));
msg.addAttribute(HttpMessage::attribute("Mode", "OneWay"));
msg.addAttribute(HttpMessage::attribute("content_length", "10"));
msg.addBody(std::vector<HttpMessage::byte> { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' });
std::cout << "\n" << Utils::addHeaderAndFooterLines(msg.toString());
Utils::title("testing headerString(), bodyString(), and toString()");
std::cout << "\nheader string:";
std::cout << "\n" << msg.headerString();
std::cout << "\nbody string:";
std::cout << "\n" << msg.bodyString();
std::cout << "\n\nmessage string:";
std::cout << "\n" << StringHelper::addHeaderAndFooterLines(msg.toString());
Utils::title("Testing removeAttribute");
putline();
msg.removeAttribute("content_length");
std::cout << msg.toString();
putline();
Utils::title("Testing addBody(const std::string&)");
std::string msgBody = "<msg>this is a message</msg>";
msg.addAttribute(HttpMessage::Attribute("content_length", Converter<size_t>::toString(msgBody.size())));
msg.addBody(msgBody);
std::cout << "\n" << StringHelper::addHeaderAndFooterLines(msg.toString());
Utils::title("Testing parseAttribute(const std::string&)");
std::string test2 = "name:value";
std::cout << "\n input = \"" << test2 << "\"";
Attribute attrib2 = HttpMessage::parseAttribute(test2);
std::cout << "\n result is: " << HttpMessage::attribString(attrib2);
test2 = " name : value ";
std::cout << "\n input = \"" << test2 << "\"";
attrib2 = HttpMessage::parseAttribute(test2);
std::cout << "\n result is: " << HttpMessage::attribString(attrib2);
Utils::title("Testing Message parsing");
MockSocket sock(msg);
HttpMessage msg2;
while (true)
{
std::string line = sock.recvString();
if (line.size() == 0)
break;
Attribute attrib = HttpMessage::parseAttribute(line);
msg2.addAttribute(attrib);
}
Value val = msg2.findValue("content_length");
if (val.size() > 0)
{
size_t numBytes = Converter<size_t>::toValue(val);
byte* pBuffer = new byte[numBytes];
sock.recv(numBytes, pBuffer);
msg2.addBody(numBytes, pBuffer);
}
std::cout << "\n" << Utils::addHeaderAndFooterLines(msg2.toString());
std::cout << "\n\n";
}