dodo
0.0.1
A C++ library to create containerized Linux services
|
Go to the documentation of this file.
24 #ifndef dodo_network_protocol_http_httpmessage_hpp
25 #define dodo_network_protocol_http_httpmessage_hpp
33 namespace network::protocol::http {
85 void addHeader(
const std::string &key,
const std::string &value );
92 void replaceHeader(
const std::string &key,
const std::string &value );
118 bool getHeaderValue(
const std::string &key, std::string &value )
const;
127 bool getHeaderValue(
const std::string &key,
unsigned long &value )
const;
139 void setBody(
const std::string& body );
164 static bool isCTL(
char c ) {
return c <= 31 || c == 127; };
243 return c ==
'(' || c ==
')' || c ==
'<' || c ==
'>' || c ==
'@' ||
244 c ==
',' || c ==
';' || c ==
':' || c ==
'\\' || c ==
'"' ||
245 c ==
'/' || c ==
'[' || c ==
']' || c ==
'?' || c ==
'=' ||
void addHeader(const std::string &key, const std::string &value)
Add a header to the HTTPMessage.
ParseResult parseFieldValue(VirtualReadBuffer &data, std::string &value)
Parse a header field value.
static bool isCTL(char c)
Check is the char is a CTL character.
ParseResult parseChunkedBody(VirtualReadBuffer &data)
Parse a chunked body (transfer-encoding: chunked) and resturn it as a single string.
bool hasHeader(const std::string &header) const
Return true when this header key exists in this HTTPMessage's headers.
static const char charCR
CR character.
static const char charLF
LF character.
ParseResult parseChunkHex(VirtualReadBuffer &data, unsigned long &value)
Parse a hexadecimal chunk size (a hex value followed by CR LF).
Interface to read individual bytes whilst the implementation can read from an actual source (such as ...
bool getHeaderValue(const std::string &key, std::string &value) const
Get a header value as a string into value.
const std::map< std::string, std::string > & getHeaders() const
Return a reference to the headers map.
std::map< std::string, std::string > headers_
The message headers.
An array of Octets with size elements.
static const char charHT
Horizontal tab character.
static const char charSP
Space character.
Generic HTTP fragment, either a complete (such as HTTPRequest) or incomplete HTTP fragment (ssuch as ...
static ParseResult parseUInt(VirtualReadBuffer &data, unsigned int &value)
Parse an unsigned integer.
const common::Bytes & getBody() const
Return the HTTTMessage body.
void clearHeaders()
Clear all headers.
A C++ platform interface to lean Linux services tailored for containerized deployment.
static bool isSP(char c)
Return true if the char is whitespace character (charSP or charHT)
void replaceHeader(const std::string &key, const std::string &value)
Replace the value of a header.
static bool isSeparator(char c)
Return true if the char is a separator.
HTTPMessage()
Default constructor.
Generic HTTPMessage, parent to HTTPRequest and HTTPResponse.
void setBody(const std::string &body)
Set the body.
ParseResult parseToken(VirtualReadBuffer &buffer, std::string &token)
Parse a token (such as a header field name).
static common::SystemError eatSpace(VirtualReadBuffer &data)
Call buffer.next() as long as buffer.get() is whitespace ( charSP or charHT).
ParseResult parseHeaders(VirtualReadBuffer &data)
Parse a header section and update headers_.
Linux system error primitive to provide a consistent interface to Linux error codes.
common::Bytes body_
The message body (if any).
virtual ParseResult parseBody(VirtualReadBuffer &data)=0
Parse a body and resturn it as a single string.
ParseResult eatCRLF(VirtualReadBuffer &data)
Consume a CR LF sequence only when it is there.
ParseResult parseCRLF(VirtualReadBuffer &data)
Consume a CR LF sequence.
virtual common::SystemError send(BaseSocket *socket)=0
Send this HTTPMessage to the socket.
Interface to and common implementation of concrete sockets (Socket, TLSSocket).