dodo
0.0.1
A C++ library to create containerized Linux services
|
HTTPResponse class. More...
#include <httpresponse.hpp>
Data Structures | |
class | HTTPResponseLine |
A HTTP response line. More... | |
Public Types | |
enum | HTTPCode : unsigned int { hcContinue = 100, hcSwitchingProtocols = 101, hcProcessing = 102, hcEarlyHints = 103, hcOK = 200, hcCreated = 201, hcAccepted = 202, hcNonAuthoritiveInformation = 203, hcNoContent = 204, hcResetContent = 205, hcPartialContent = 206, hcMultiStatus = 207, hcAlreadyReported = 208, hcIMUsed = 226, hcMultipleChoices = 300, hcMovedPermanently = 301, hcFound = 302, hcSeeOther = 303, hcNotModified = 304, hcUseProxy = 305, hcSwitchProxy = 306, hcTemporaryRedirect = 307, hcPermanentRedirect = 308, hcBadRequest = 400, hcUnAuthorized = 401, hcPaymentRequired = 402, hcForbidden = 403, hcNotFound = 404, hcMethodNotAllowed = 405, hcNotAcceptable = 406, hcProxyAuthenticationRequired = 407, hcRequestTimeout = 408, hcConflict = 409, hcGone = 410, hcLengthRequired = 411, hcPreconditionFailed = 412, hcPayloadTooLarge = 413, hcURITooLong = 414, hcUnsupportedMediaType = 415, hcRangeNotSatisfiable = 416, hcExpectationFailed = 417, hcIAmATeapot = 418, hcMisdirectRequest = 421, hcUnporessableEntity = 422, hcLocked = 423, hcFailedDependency = 424, hcUpgradeRequired = 426, hcPreconditionRequired = 428, hcTooManyRequests = 429, hcRequestHeaderFieldsTooLarge = 431, hcUnavailableForLegalReasons = 451, hcInternalServerError = 500, hcNotImplemented = 501, hcBadGateway = 502, hcServiceUnavailable = 503, hcGatewayTimeout = 504, hcHTTPVersionNotSupported = 505, hcVariantAlsoNegotiates = 506, hcInsufficientStorage = 507, hcLoopDetected = 508, hcNotExtended = 510, hcNetworkAuthenticationRequired = 511, hcCheckpoint = 103, hcThisIsFine = 218, hcPageExpired = 419, hcMethodFailure = 420, hcEnhanceYourCalm = 420, hcBlockedByWindowsParentalControls = 450, hcInvalidToken = 498, hcTokenRequired = 499, hcBandwidthLimitExceeded = 509, hcInvalidSSLCertificate = 526, hcSiteIsFrozen = 530, hcNetworkReadTimeoutError = 598, hcLoginTimeout = 440, hcRetryWith = 449, hcRedirect = 451, hcNoRepsonse = 444, hcRequestHeaderTooLarge = 494, hcSSLCertificateError = 495, hcSSLCertificateRequired = 496, hcHHTPRequestSentToHTTPSPort = 497, hcClientClosedrequest = 499, hcUnknownError = 520, hcWebServerIsDown = 521, hcConnectionTimedOut = 522, hcOriginIsUnreachable = 523, hcATimeoutOccured = 524, hcSSLHandshakeFailed = 525, hcRailgunError = 527, hcOriginDNSError = 530 } |
![]() | |
enum | ParseError : unsigned int { peOk = 0, peIncomplete, peSystemError, peExpectCRLF, peUnFinishedToken, peExpectingHeaderColon, peInvalidHeaderFieldValue, peInvalidHeaderListEnd, peInvalidMethod, peInvalidHTTPVersion, peInvalidRequestLine, peInvalidContentLength, peUnexpectedBody, peInvalidTransferEncoding, peInvalidChunkHex, peInvalidLastChunk, peExpectingUnsignedInt } |
Parse results returned by the parse functions. More... | |
Public Member Functions | |
virtual std::string | asString () const |
Return the HTTPResponse as a string. More... | |
const HTTPResponseLine & | getResponseLine () const |
Return a const reference to the HTTPResponseLine of this HTTPResponse. More... | |
bool | hasBody () const |
Return true when the response has a body. More... | |
virtual ParseResult | parse (VirtualReadBuffer &buffer) |
Read a complete HTTPFragment from a VirtualReadBuffer. More... | |
virtual ParseResult | parseBody (VirtualReadBuffer &data) |
Parse a body and resturn it as a single string. More... | |
virtual common::SystemError | send (BaseSocket *socket) |
Send this HTTPMessage to the socket. More... | |
![]() | |
HTTPMessage () | |
Default constructor. More... | |
void | addHeader (const std::string &key, const std::string &value) |
Add a header to the HTTPMessage. More... | |
void | clearHeaders () |
Clear all headers. More... | |
const common::Bytes & | getBody () const |
Return the HTTTMessage body. More... | |
const std::map< std::string, std::string > & | getHeaders () const |
Return a reference to the headers map. More... | |
bool | getHeaderValue (const std::string &key, std::string &value) const |
Get a header value as a string into value. More... | |
bool | getHeaderValue (const std::string &key, unsigned long &value) const |
Get a header value as an unsigned long into value. More... | |
bool | hasHeader (const std::string &header) const |
Return true when this header key exists in this HTTPMessage's headers. More... | |
void | replaceHeader (const std::string &key, const std::string &value) |
Replace the value of a header. More... | |
void | setBody (const std::string &body) |
Set the body. More... | |
Static Public Member Functions | |
static std::string | HTTPCodeAsString (HTTPCode code) |
Return the (upper case) string representation of the http error code. More... | |
![]() | |
static std::string | getParseResultAsString (ParseError error) |
Return the string description of a ParseError. More... | |
Protected Attributes | |
HTTPResponseLine | response_line_ |
The HTTPResponseLIne of the HTTPResponse. More... | |
![]() | |
common::Bytes | body_ |
The message body (if any). More... | |
std::map< std::string, std::string > | headers_ |
The message headers. More... | |
Additional Inherited Members | |
![]() | |
static const char | charCR = char(13) |
CR character. More... | |
static const char | charHT = char(9) |
Horizontal tab character. More... | |
static const char | charLF = char(10) |
LF character. More... | |
static const char | charSP = char(32) |
Space character. More... | |
![]() | |
ParseResult | eatCRLF (VirtualReadBuffer &data) |
Consume a CR LF sequence only when it is there. More... | |
ParseResult | parseChunkedBody (VirtualReadBuffer &data) |
Parse a chunked body (transfer-encoding: chunked) and resturn it as a single string. More... | |
ParseResult | parseChunkHex (VirtualReadBuffer &data, unsigned long &value) |
Parse a hexadecimal chunk size (a hex value followed by CR LF). More... | |
ParseResult | parseCRLF (VirtualReadBuffer &data) |
Consume a CR LF sequence. More... | |
ParseResult | parseFieldValue (VirtualReadBuffer &data, std::string &value) |
Parse a header field value. More... | |
ParseResult | parseHeaders (VirtualReadBuffer &data) |
Parse a header section and update headers_. More... | |
ParseResult | parseToken (VirtualReadBuffer &buffer, std::string &token) |
Parse a token (such as a header field name). More... | |
![]() | |
static common::SystemError | eatSpace (VirtualReadBuffer &data) |
Call buffer.next() as long as buffer.get() is whitespace ( charSP or charHT). More... | |
static bool | isCTL (char c) |
Check is the char is a CTL character. More... | |
static bool | isSeparator (char c) |
Return true if the char is a separator. More... | |
static bool | isSP (char c) |
Return true if the char is whitespace character (charSP or charHT) More... | |
static ParseResult | parseUInt (VirtualReadBuffer &data, unsigned int &value) |
Parse an unsigned integer. More... | |
HTTPResponse class.
Contains
Definition at line 40 of file httpresponse.hpp.
enum dodo::network::protocol::http::HTTPResponse::HTTPCode : unsigned int |
Definition at line 46 of file httpresponse.hpp.
|
virtual |
Return the HTTPResponse as a string.
Implements dodo::network::protocol::http::HTTPFragment.
Definition at line 71 of file httpresponse.cpp.
References dodo::common::Bytes::asString(), dodo::network::protocol::http::HTTPResponse::HTTPResponseLine::asString(), dodo::network::protocol::http::HTTPMessage::body_, dodo::network::protocol::http::HTTPMessage::charCR, dodo::network::protocol::http::HTTPMessage::charLF, dodo::common::Bytes::getSize(), dodo::network::protocol::http::HTTPMessage::headers_, and response_line_.
|
inline |
Return a const reference to the HTTPResponseLine of this HTTPResponse.
Definition at line 207 of file httpresponse.hpp.
References response_line_.
bool dodo::network::protocol::http::HTTPResponse::hasBody | ( | ) | const |
Return true when the response has a body.
Definition at line 58 of file httpresponse.cpp.
References dodo::network::protocol::http::HTTPMessage::getHeaderValue().
Referenced by parse().
|
static |
Return the (upper case) string representation of the http error code.
code | The HTTP error code. |
Definition at line 176 of file httpresponse.cpp.
Referenced by dodo::network::protocol::http::HTTPResponse::HTTPResponseLine::asString().
|
virtual |
Read a complete HTTPFragment from a VirtualReadBuffer.
buffer | the VirtualReadBuffer to get characters from. |
Implements dodo::network::protocol::http::HTTPFragment.
Definition at line 32 of file httpresponse.cpp.
References dodo::network::protocol::http::HTTPMessage::charCR, dodo::network::protocol::http::HTTPMessage::charLF, dodo::common::SystemError::ecOK, dodo::network::protocol::http::HTTPFragment::ParseResult::eof(), dodo::network::VirtualReadBuffer::get(), hasBody(), dodo::network::VirtualReadBuffer::next(), dodo::network::protocol::http::HTTPFragment::ParseResult::ok(), dodo::network::protocol::http::HTTPResponse::HTTPResponseLine::parse(), parseBody(), dodo::network::protocol::http::HTTPMessage::parseHeaders(), dodo::network::protocol::http::HTTPFragment::peOk, response_line_, and dodo::network::protocol::http::HTTPFragment::ParseResult::setSystemError().
|
virtual |
Parse a body and resturn it as a single string.
Note that the content-length header must be present and specify the correct body length.
data | The VirtualReadBuffer to read from. |
Implements dodo::network::protocol::http::HTTPMessage.
Definition at line 143 of file httpresponse.cpp.
References dodo::common::Bytes::append(), dodo::network::protocol::http::HTTPMessage::body_, dodo::common::SystemError::ecOK, dodo::network::VirtualReadBuffer::get(), dodo::network::protocol::http::HTTPMessage::getHeaderValue(), dodo::network::VirtualReadBuffer::next(), dodo::network::protocol::http::HTTPFragment::ParseResult::ok(), dodo::network::protocol::http::HTTPMessage::parseChunkedBody(), dodo::network::protocol::http::HTTPFragment::peInvalidTransferEncoding, dodo::network::protocol::http::HTTPFragment::peOk, dodo::network::protocol::http::HTTPFragment::peUnexpectedBody, and dodo::network::protocol::http::HTTPFragment::ParseResult::setSystemError().
Referenced by parse().
|
virtual |
Send this HTTPMessage to the socket.
socket | The socket to write to. |
Implements dodo::network::protocol::http::HTTPMessage.
Definition at line 84 of file httpresponse.cpp.
References dodo::network::protocol::http::HTTPResponse::HTTPResponseLine::asString(), dodo::network::protocol::http::HTTPMessage::body_, dodo::network::protocol::http::HTTPMessage::charCR, dodo::network::protocol::http::HTTPMessage::charLF, dodo::common::Bytes::getArray(), dodo::common::Bytes::getSize(), dodo::network::protocol::http::HTTPMessage::headers_, dodo::common::SystemError::ok(), response_line_, and dodo::network::BaseSocket::send().
|
protected |
The HTTPResponseLIne of the HTTPResponse.
Definition at line 236 of file httpresponse.hpp.
Referenced by asString(), getResponseLine(), parse(), and send().