Files
MINWebServer/MINWebServer/http/MINWebMessage.h
T
2020-12-11 10:09:00 +08:00

79 lines
1.8 KiB
C++

//
// Created by SunnyQjm on 2020/10/14 上午10:26.
//
#ifndef MIN_NGINX_MINWEBMESSAGE_H
#define MIN_NGINX_MINWEBMESSAGE_H
#include <string>
#include <map>
#include <ndn-cxx/face.hpp>
#include "../utils/StringUtils.h"
#include "../common/MINHttpDef.h"
#include "../utils/json.h"
namespace MIN {
#define MIN_MAP std::map
enum class MessageParserState : uint8_t
{
NONE,
PARSING_START_LINE,
START_LINE_REQUEST,
START_LINE_RESPONSE,
HEADER_KEY,
HEADER_VALUE,
PARSING_BODY,
};
enum MINParserType {
MIN_WEB_REQUEST = 0,
MIN_WEB_RESPONSE = 1,
};
typedef std::map<std::string, std::string, StringCaseLess> MINHttpHeaders;
typedef std::string MINHttpBody;
class MINWebMessage {
public:
// /MIN/Nginx/test/getData?size=1&page=2
// /MIN/Nginx/test/getPost/:filedId => /MIN/Nginx/test/getPost/2
std::string url;
int type;
MessageParserState state;
// SignatureInfo
std::shared_ptr<ndn::SignatureInfo> signatureInfo;
// headers
MINHttpHeaders headers;
// body
MINHttpBody body;
// structured content
void *content; // DATA_NO_COPY
int contentLength;
MINWebServer::MINHttpContentType contentType;
nlohmann::json json; // APPLICATION_JSON
virtual MINWebMessage& SetHeader(const std::string& name, const std::string& value)
{
headers[name] = value;
return *this;
}
virtual void reset() {
type = MIN_WEB_REQUEST;
state= MessageParserState::NONE;
url = "";
signatureInfo = std::make_shared<ndn::SignatureInfo>();
}
};
}
#endif //MIN_NGINX_MINWEBMESSAGE_H