dodo  0.0.1
A C++ library to create containerized Linux services
dodo::network::protocol::http::HTTPResponse Class Reference

HTTPResponse class. More...

#include <httpresponse.hpp>

Inheritance diagram for dodo::network::protocol::http::HTTPResponse:
Collaboration diagram for dodo::network::protocol::http::HTTPResponse:

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
}
 
- Public Types inherited from dodo::network::protocol::http::HTTPFragment
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 HTTPResponseLinegetResponseLine () 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...
 
- Public Member Functions inherited from dodo::network::protocol::http::HTTPMessage
 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::BytesgetBody () 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 Public Member Functions inherited from dodo::network::protocol::http::HTTPFragment
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...
 
- Protected Attributes inherited from dodo::network::protocol::http::HTTPMessage
common::Bytes body_
 The message body (if any). More...
 
std::map< std::string, std::string > headers_
 The message headers. More...
 

Additional Inherited Members

- Static Public Attributes inherited from dodo::network::protocol::http::HTTPMessage
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...
 
- Protected Member Functions inherited from dodo::network::protocol::http::HTTPMessage
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 Protected Member Functions inherited from dodo::network::protocol::http::HTTPMessage
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...
 

Detailed Description

HTTPResponse class.

Contains

Definition at line 40 of file httpresponse.hpp.

Member Enumeration Documentation

◆ HTTPCode

Member Function Documentation

◆ asString()

◆ getResponseLine()

const HTTPResponseLine& dodo::network::protocol::http::HTTPResponse::getResponseLine ( ) const
inline

Return a const reference to the HTTPResponseLine of this HTTPResponse.

Returns
a const reference to the HTTPResponseLine of this HTTPResponse.

Definition at line 207 of file httpresponse.hpp.

References response_line_.

◆ hasBody()

bool dodo::network::protocol::http::HTTPResponse::hasBody ( ) const

Return true when the response has a body.

Returns
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HTTPCodeAsString()

std::string dodo::network::protocol::http::HTTPResponse::HTTPCodeAsString ( HTTPCode  code)
static

Return the (upper case) string representation of the http error code.

Parameters
codeThe HTTP error code.
Returns
The string representation.

Definition at line 176 of file httpresponse.cpp.

Referenced by dodo::network::protocol::http::HTTPResponse::HTTPResponseLine::asString().

Here is the caller graph for this function:

◆ parse()

◆ parseBody()

◆ send()

Field Documentation

◆ response_line_

HTTPResponseLine dodo::network::protocol::http::HTTPResponse::response_line_
protected

The HTTPResponseLIne of the HTTPResponse.

Definition at line 236 of file httpresponse.hpp.

Referenced by asString(), getResponseLine(), parse(), and send().


The documentation for this class was generated from the following files: