dodo
0.0.1
A C++ library to create containerized Linux services
|
Go to the documentation of this file.
30 namespace network::protocol::http {
38 std::map<std::string,std::string>::const_iterator i =
headers_.find( key );
48 if ( buffer.
get() !=
charCR )
return parseResult;
50 if ( ! parseResult.
ok() )
return parseResult;
59 error = buffer.
next();
65 std::map<std::string,std::string>::const_iterator i =
headers_.find( key );
69 value = stoul( i->second, &pos );
70 return pos==i->second.size();
75 std::map<std::string,std::string>::const_iterator i =
headers_.find( key );
86 std::string header_key =
"";
87 std::string header_value =
"";
90 if ( parseResult.
ok() ) {
91 std::for_each( header_key.begin(), header_key.end(), [](
char & c) {
92 c = (char)std::tolower(c);
95 if ( !parseResult.
ok() )
return parseResult;
98 if ( ! parseResult.
ok() )
return parseResult;
100 if ( ! parseResult.
ok() )
return parseResult;
102 if ( parseResult.
ok() || parseResult.
eof() ) {
105 if ( ! parseResult.
ok() )
return parseResult;
106 }
else return parseResult;
107 }
else return parseResult;
110 if ( ! parseResult.
ok() )
return parseResult;
119 if ( ! parseResult.
ok() )
return parseResult;
127 std::stringstream ss;
129 if ( std::isxdigit( buffer.
get() ) ) {
132 if ( !parseResult.
ok() )
return parseResult;
136 ss >> std::hex >> value;
143 const int psStart = 0;
144 const int psReadValue = 1;
147 const int psDone = 101;
150 while ( parseResult.
ok() && state != psDone ) {
161 }
else if (
isSP( data.
get() ) ) {
172 if ( parseResult.
ok() &&
isSP( data.
get() ) ) {
199 std::stringstream stoken;
201 stoken << buffer.
get();
203 if ( ! parseResult.
ok() )
return parseResult;
206 token = stoken.str();
213 std::stringstream ss;
215 while ( parseResult.
ok() && isdigit( data.
get() ) ) {
226 size_t chunk_size = 0;
227 while ( parseResult.
ok() ) {
229 if ( parseResult.
ok() ) {
230 if ( chunk_size == 0 )
break;
231 for (
size_t i = 0; i < chunk_size; i++ ) {
234 if ( ! parseResult.
ok() )
return parseResult;
237 if ( ! parseResult.
ok() )
return parseResult;
238 }
else return parseResult;
@ peExpectingUnsignedInt
An unsigned int was expected.
void addHeader(const std::string &key, const std::string &value)
Add a header to the HTTPMessage.
@ peExpectingHeaderColon
A header field name was read, but no colon found after it.
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.
static const char charCR
CR character.
static const char charLF
LF character.
@ peUnFinishedToken
A token is being parsed but is ending erroneously.
ParseResult parseChunkHex(VirtualReadBuffer &data, unsigned long &value)
Parse a hexadecimal chunk size (a hex value followed by CR LF).
@ peInvalidHeaderListEnd
A header list is not ending properly.
bool ok() const
Test if parseError == peOk && systemError == common::SystemError::ecOK.
Interface to read individual bytes whilst the implementation can read from an actual source (such as ...
void setSystemError(common::SystemError se)
Set the systemError.
bool getHeaderValue(const std::string &key, std::string &value) const
Get a header value as a string into value.
std::map< std::string, std::string > headers_
The message headers.
virtual common::SystemError next()=0
Move to the next char from the VirtualReadBuffer.
virtual char get() const =0
Get the current char from VirtualReadBuffer.
Put the stream in floating point fixed-format mode.
static const char charHT
Horizontal tab character.
static const char charSP
Space character.
static ParseResult parseUInt(VirtualReadBuffer &data, unsigned int &value)
Parse an unsigned integer.
@ peInvalidChunkHex
The hex chunk size is invalid.
void append(const Bytes &src)
Append another Bytes.
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.
Used to convey parsing succces.
bool eof() const
Test if systemError == common::SystemError::ecEAGAIN
@ peInvalidLastChunk
The last chunk does not have size 0.
@ ecOK
0 Not an error, success
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).
@ peInvalidHeaderFieldValue
A header field value was being read, but it is invalid.
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_.
Helper class to write strings in stream format, eg.
Linux system error primitive to provide a consistent interface to Linux error codes.
@ peExpectCRLF
A CR was not followed by an LF.
common::Bytes body_
The message body (if any).
size_t getSize() const
Return the array size.
ParseResult eatCRLF(VirtualReadBuffer &data)
Consume a CR LF sequence only when it is there.
ParseResult parseCRLF(VirtualReadBuffer &data)
Consume a CR LF sequence.