A Discrete-Event Network Simulator
API
ns3::HTTPMessage Class Reference

The basic class to represent both HTTP requests and responses. More...

#include "http.h"

+ Collaboration diagram for ns3::HTTPMessage:

Public Types

enum  HttpMethod {
  NONE , DELETE , GET , HEAD ,
  PATCH , POST , PUT
}
 
enum  HttpStatus {
  Continue = 100 , SwitchingProtocol = 101 , Processing = 102 , EarlyHints = 103 ,
  Ok = 200 , Created = 201 , Accepted = 202 , NonAuthoritativeInformation = 203 ,
  NoContent = 204 , ResetContent = 205 , PartialContent = 206 , MultiStatus = 207 ,
  AlreadyReported = 208 , ImUsed = 226 , MultipleChoice = 300 , MovedPermanently = 301 ,
  Found = 302 , SeeOther = 303 , NotModified = 304 , UseProxy = 305 ,
  TemporaryRedirect = 307 , PermanentRedirect = 308 , BadRequest = 400 , Unauthorized = 401 ,
  PaymentRequired = 402 , Forbidden = 403 , NotFound = 404 , MethodNotAllowed = 405 ,
  NotAcceptable = 406 , ProxyAuthenticationRequired = 407 , RequestTimeout = 408 , Conflict = 409 ,
  Gone = 410 , LengthRequired = 411 , PreconditionFailed = 412 , PayloadTooLarge = 413 ,
  UriTooLong = 414 , UnsupportedMediaType = 415 , RangeNotSatisfiable = 416 , ExpectationFailed = 417 ,
  ImaTeapot = 418 , MisdirectedRequest = 421 , UnprocessableEntity = 422 , Locked = 423 ,
  FailedDependency = 424 , TooEarly = 425 , UpgradeRequired = 426 , PreconditionRequired = 428 ,
  TooManyRequests = 429 , RequestHeaderFieldsTooLarge = 431 , UnavailableForLegalReasons = 451 , InternalServerError = 500 ,
  NotImplemented = 501 , BadGateway = 502 , ServiceUnavailable = 503 , GatewayTimeout = 504 ,
  HttpVersionNotSupported = 505 , VariantAlsoNegotiates = 506 , InsufficientStorage = 507 , LoopDetected = 508 ,
  NotExtended = 510 , NetworkAuthenticationRequired = 511
}
 

Public Member Functions

void CreateRequest (const std::string &url, const std::string &method)
 
void CreateRequest (const std::string &url, const std::string &method, const std::string &body)
 
void CreateRequest (const std::string &url, const std::string &method, const std::vector< uint8_t > &body)
 
void CreateResponse (const HttpStatus status)
 
void CreateResponse (const HttpStatus status, const std::string &body)
 
void CreateResponse (const HttpStatus status, const std::string &body, const std::unordered_map< std::string, std::string > &headers)
 
void CreateResponse (const HttpStatus status, const std::vector< uint8_t > &body)
 
void CreateResponse (const HttpStatus status, const std::vector< uint8_t > &body, const std::unordered_map< std::string, std::string > &headers)
 
size_t GetContentLength ()
 Return the size of the binary body vector. More...
 
std::string GetHeader (const std::string &name) const
 Get the string value of a single header from the message. More...
 
uint32_t GetHeadersSize ()
 
std::vector< uint8_t > & GetMessageBody ()
 Get the body vector for this message. More...
 
std::string GetMessageBodyString ()
 
HTTPMessage::HttpMethod GetMethod () const
 
std::string GetMethodToString () const
 
std::string GetPath () const
 Grab the current associated path of this message. More...
 
std::string GetRequestUri () const
 
uint32_t GetSize ()
 
HTTPMessage::HttpStatus GetStatus ()
 To be returned with a status code in a response is a status text describing the status code by text rather than by a code. More...
 
uint16_t GetStatusCode () const
 Get the status code for this message. More...
 
std::string GetStatusMessage () const
 Get the current status message for this message. More...
 
std::string GetUri () const
 Grab the uri. More...
 
std::string GetVersion () const
 Get the current HTTP version for this message. More...
 
size_t HeaderCount ()
 Return the amount of headers in the message. More...
 
bool IsFragmented ()
 
void SetFragmented (bool value)
 
HTTPMessageSetHeader (const std::string &name, const std::string &value)
 Set a header in the map to the value provided. More...
 
HTTPMessageSetHeaders (const std::unordered_map< std::string, std::string > &headers)
 Set a number of headers based on a generic map of keys and values. More...
 
void SetMessageBody (const std::string &body)
 Set the body of this message to a string value. More...
 
void SetMessageBody (const std::vector< uint8_t > &body)
 Set the body of this message to an unsigned 8-bit binary value. More...
 
void SetMethod (const std::string &m)
 Set the associated message method for this message. More...
 
void SetPath (const std::string &url)
 Set the path of this message, which will be used if it is a request. More...
 
void SetStatusCode (uint16_t code)
 Set the status code of this HTTP message. More...
 
void SetStatusMessage (const std::string &message)
 Set the status message of this HTTP message. More...
 
void SetVersion (const std::string &version)
 Set the version of this HTTP message to the string specified. More...
 
std::string StatusTextFromStatusCode (const uint16_t statusCode)
 To be returned with a status code in a response is a status text describing the status code by text rather than by a code. More...
 
std::string ToString ()
 Takes the headers added to the message along with the body and outputs it to a std::string for use in client/server HTTP messages. More...
 

Private Attributes

std::vector< uint8_t > m_body
 A vector of unsigned 8-bit integers used to store message bodies. More...
 
uint32_t m_contentLength = 0
 
std::string m_domain
 
bool m_fragmented = false
 Whether the payload size is less then content-length. More...
 
std::unordered_map< std::string, std::string > m_headers
 An unordered_map of headers using a std::string for both the key and the value. More...
 
uint32_t m_headersLength = 0
 
HTTPMessage::HttpMethod m_method = HTTPMessage::HttpMethod::NONE
 The HTTP method for this message. More...
 
std::string m_path = ""
 The path for the resource specified in the message. More...
 
std::string m_request_uri
 
std::string m_scheme
 
uint16_t m_statusCode = 0
 A status code for this message. More...
 
std::string m_statusMessage = ""
 A status message to be associated with the status code for this message. More...
 
std::string m_uri
 
std::string m_version = HTTPVersion11
 The version used for this HTTP message as a string. More...
 

Detailed Description

The basic class to represent both HTTP requests and responses.

Contains a method for grabbing the message as a string formatted for sending through a server or other means.

Allows for setting a message body that is represented by a vector of 8-bit unsigned integers. This is to allow binary data to be sent through the message. But, you also can use the included methods to send plain strings.

This class returns as many methods as possible with a reference to the current object, to try and allow for chaining methods.

Note: for convenience, the header for Content-Length is automatically included as it is grabbed from the m_body member. Though, it is only included if the body member isn't empty.

Definition at line 77 of file http.h.

Member Enumeration Documentation

◆ HttpMethod

Enumerator
NONE 
DELETE 

Http Method Delete.

GET 

Http Method GET.

HEAD 

Http Method Head.

PATCH 

Http Method Patch.

POST 

Http Method Post.

PUT 

Http Method Put.

Definition at line 81 of file http.h.

◆ HttpStatus

Enumerator
Continue 
SwitchingProtocol 
Processing 
EarlyHints 
Ok 
Created 
Accepted 
NonAuthoritativeInformation 
NoContent 
ResetContent 
PartialContent 
MultiStatus 
AlreadyReported 
ImUsed 
MultipleChoice 
MovedPermanently 
Found 
SeeOther 
NotModified 
UseProxy 
TemporaryRedirect 
PermanentRedirect 
BadRequest 
Unauthorized 
PaymentRequired 
Forbidden 
NotFound 
MethodNotAllowed 
NotAcceptable 
ProxyAuthenticationRequired 
RequestTimeout 
Conflict 
Gone 
LengthRequired 
PreconditionFailed 
PayloadTooLarge 
UriTooLong 
UnsupportedMediaType 
RangeNotSatisfiable 
ExpectationFailed 
ImaTeapot 
MisdirectedRequest 
UnprocessableEntity 
Locked 
FailedDependency 
TooEarly 
UpgradeRequired 
PreconditionRequired 
TooManyRequests 
RequestHeaderFieldsTooLarge 
UnavailableForLegalReasons 
InternalServerError 
NotImplemented 
BadGateway 
ServiceUnavailable 
GatewayTimeout 
HttpVersionNotSupported 
VariantAlsoNegotiates 
InsufficientStorage 
LoopDetected 
NotExtended 
NetworkAuthenticationRequired 

Definition at line 91 of file http.h.

Member Function Documentation

◆ CreateRequest() [1/3]

◆ CreateRequest() [2/3]

void ns3::HTTPMessage::CreateRequest ( const std::string &  url,
const std::string &  method,
const std::string &  body 
)
inline

Definition at line 750 of file http.h.

References CreateRequest().

+ Here is the call graph for this function:

◆ CreateRequest() [3/3]

void ns3::HTTPMessage::CreateRequest ( const std::string &  url,
const std::string &  method,
const std::vector< uint8_t > &  body 
)
inline

Definition at line 763 of file http.h.

References m_domain, SetHeader(), SetMessageBody(), SetMethod(), SetPath(), and nlohmann::to_string().

+ Here is the call graph for this function:

◆ CreateResponse() [1/5]

◆ CreateResponse() [2/5]

void ns3::HTTPMessage::CreateResponse ( const HttpStatus  status,
const std::string &  body 
)
inline

Definition at line 794 of file http.h.

References CreateResponse().

+ Here is the call graph for this function:

◆ CreateResponse() [3/5]

void ns3::HTTPMessage::CreateResponse ( const HttpStatus  status,
const std::string &  body,
const std::unordered_map< std::string, std::string > &  headers 
)
inline

Definition at line 822 of file http.h.

References CreateResponse(), and SetHeaders().

+ Here is the call graph for this function:

◆ CreateResponse() [4/5]

void ns3::HTTPMessage::CreateResponse ( const HttpStatus  status,
const std::vector< uint8_t > &  body 
)
inline

Definition at line 804 of file http.h.

References SetHeader(), SetMessageBody(), SetMethod(), SetStatusCode(), and nlohmann::to_string().

+ Here is the call graph for this function:

◆ CreateResponse() [5/5]

void ns3::HTTPMessage::CreateResponse ( const HttpStatus  status,
const std::vector< uint8_t > &  body,
const std::unordered_map< std::string, std::string > &  headers 
)
inline

Definition at line 834 of file http.h.

References CreateResponse(), and SetHeaders().

+ Here is the call graph for this function:

◆ GetContentLength()

size_t ns3::HTTPMessage::GetContentLength ( )
inline

Return the size of the binary body vector.

Definition at line 724 of file http.h.

References m_contentLength.

Referenced by GetSize(), ns3::QKDApp004::PacketReceivedFromKMS(), and ns3::HTTPMessageParser::Parse().

+ Here is the caller graph for this function:

◆ GetHeader()

std::string ns3::HTTPMessage::GetHeader ( const std::string &  name) const
inline

Get the string value of a single header from the message.

Will return an empty string if the header does not exist.

Definition at line 449 of file http.h.

References m_headers.

◆ GetHeadersSize()

uint32_t ns3::HTTPMessage::GetHeadersSize ( )
inline

Definition at line 681 of file http.h.

References m_headersLength, and ToString().

Referenced by GetSize(), and ns3::QKDApp004::PacketReceivedFromKMS().

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

◆ GetMessageBody()

std::vector<uint8_t>& ns3::HTTPMessage::GetMessageBody ( )
inline

Get the body vector for this message.

Definition at line 709 of file http.h.

References m_body.

Referenced by ns3::HTTPMessageParser::Parse().

+ Here is the caller graph for this function:

◆ GetMessageBodyString()

◆ GetMethod()

HTTPMessage::HttpMethod ns3::HTTPMessage::GetMethod ( ) const
inline

Definition at line 482 of file http.h.

References m_method.

Referenced by ns3::QKDKeyManagerSystemApplication::ProcessRequest(), and ns3::QKDSDNController::ProcessRequest().

+ Here is the caller graph for this function:

◆ GetMethodToString()

std::string ns3::HTTPMessage::GetMethodToString ( ) const
inline

Definition at line 487 of file http.h.

References DELETE, GET, HEAD, m_method, NONE, PATCH, POST, and PUT.

Referenced by ToString().

+ Here is the caller graph for this function:

◆ GetPath()

std::string ns3::HTTPMessage::GetPath ( ) const
inline

Grab the current associated path of this message.

Definition at line 573 of file http.h.

References m_path.

◆ GetRequestUri()

std::string ns3::HTTPMessage::GetRequestUri ( ) const
inline

◆ GetSize()

◆ GetStatus()

HTTPMessage::HttpStatus ns3::HTTPMessage::GetStatus ( )
inline

To be returned with a status code in a response is a status text describing the status code by text rather than by a code.

This method takes in one of those codes and tries to return a text for it.

Definition at line 169 of file http.h.

References m_statusCode.

Referenced by ns3::QKDApp004::ProcessCloseResponse(), ns3::QKDApp004::ProcessGetKeyResponse(), ns3::QKDApp014::ProcessGetKeyResponse(), ns3::QKDApp014::ProcessGetKeyWithKeyIDsResponse(), ns3::QKDApp004::ProcessOpenConnectResponse(), ns3::QKDApp004::ProcessSendKsidResponse(), ns3::QKDApp014::ProcessSignalingPacketFromApp(), and ns3::QKDApp014::ProcessStatusResponse().

+ Here is the caller graph for this function:

◆ GetStatusCode()

◆ GetStatusMessage()

std::string ns3::HTTPMessage::GetStatusMessage ( ) const
inline

◆ GetUri()

◆ GetVersion()

std::string ns3::HTTPMessage::GetVersion ( ) const
inline

Get the current HTTP version for this message.

Definition at line 589 of file http.h.

References m_version.

◆ HeaderCount()

size_t ns3::HTTPMessage::HeaderCount ( )
inline

Return the amount of headers in the message.

Definition at line 732 of file http.h.

References m_headers.

◆ IsFragmented()

◆ SetFragmented()

void ns3::HTTPMessage::SetFragmented ( bool  value)
inline

Definition at line 847 of file http.h.

References m_fragmented.

Referenced by ns3::HTTPMessageParser::Parse().

+ Here is the caller graph for this function:

◆ SetHeader()

HTTPMessage& ns3::HTTPMessage::SetHeader ( const std::string &  name,
const std::string &  value 
)
inline

Set a header in the map to the value provided.

Definition at line 410 of file http.h.

References m_contentLength, m_domain, m_headers, m_request_uri, and m_uri.

Referenced by CreateRequest(), CreateResponse(), and ns3::HTTPMessageParser::Parse().

+ Here is the caller graph for this function:

◆ SetHeaders()

HTTPMessage& ns3::HTTPMessage::SetHeaders ( const std::unordered_map< std::string, std::string > &  headers)
inline

Set a number of headers based on a generic map of keys and values.

Definition at line 438 of file http.h.

References m_headers.

Referenced by CreateResponse().

+ Here is the caller graph for this function:

◆ SetMessageBody() [1/2]

void ns3::HTTPMessage::SetMessageBody ( const std::string &  body)
inline

Set the body of this message to a string value.

Definition at line 693 of file http.h.

Referenced by CreateRequest(), and CreateResponse().

+ Here is the caller graph for this function:

◆ SetMessageBody() [2/2]

void ns3::HTTPMessage::SetMessageBody ( const std::vector< uint8_t > &  body)
inline

Set the body of this message to an unsigned 8-bit binary value.

Definition at line 701 of file http.h.

References m_body.

◆ SetMethod()

void ns3::HTTPMessage::SetMethod ( const std::string &  m)
inline

Set the associated message method for this message.

Use NONE to switch this into a response.

Definition at line 465 of file http.h.

References DELETE, GET, HEAD, two-ray-to-three-gpp-ch-calibration::m, m_method, PATCH, POST, and PUT.

Referenced by CreateRequest(), CreateResponse(), and ns3::HTTPMessageParser::Parse().

+ Here is the caller graph for this function:

◆ SetPath()

void ns3::HTTPMessage::SetPath ( const std::string &  url)
inline

Set the path of this message, which will be used if it is a request.

Definition at line 527 of file http.h.

References m_domain, m_path, m_scheme, and m_uri.

Referenced by CreateRequest(), and ns3::HTTPMessageParser::Parse().

+ Here is the caller graph for this function:

◆ SetStatusCode()

void ns3::HTTPMessage::SetStatusCode ( uint16_t  code)
inline

Set the status code of this HTTP message.

Definition at line 597 of file http.h.

References m_statusCode.

Referenced by CreateResponse(), and ns3::HTTPMessageParser::Parse().

+ Here is the caller graph for this function:

◆ SetStatusMessage()

void ns3::HTTPMessage::SetStatusMessage ( const std::string &  message)
inline

Set the status message of this HTTP message.

Definition at line 613 of file http.h.

References m_statusMessage.

Referenced by ns3::HTTPMessageParser::Parse().

+ Here is the caller graph for this function:

◆ SetVersion()

void ns3::HTTPMessage::SetVersion ( const std::string &  version)
inline

Set the version of this HTTP message to the string specified.

Definition at line 581 of file http.h.

References m_version, and conf::version.

Referenced by ns3::HTTPMessageParser::Parse().

+ Here is the caller graph for this function:

◆ StatusTextFromStatusCode()

std::string ns3::HTTPMessage::StatusTextFromStatusCode ( const uint16_t  statusCode)
inline

To be returned with a status code in a response is a status text describing the status code by text rather than by a code.

This method takes in one of those codes and tries to return a text for it.

Definition at line 291 of file http.h.

Referenced by ToString().

+ Here is the caller graph for this function:

◆ ToString()

std::string ns3::HTTPMessage::ToString ( )
inline

Takes the headers added to the message along with the body and outputs it to a std::string for use in client/server HTTP messages.

Definition at line 633 of file http.h.

References ns3::CarriageReturn, GetMethodToString(), ns3::HTTPVersion11, m_body, m_contentLength, m_headers, m_headersLength, m_method, m_path, m_statusCode, m_statusMessage, and StatusTextFromStatusCode().

Referenced by ns3::QKDKeyManagerSystemApplication::AddNewLink(), ns3::QKDApp004::Close(), ns3::QKDApp004::CreateKeyQueues(), ns3::QKDApp004::CreateKeyQueuesResponse(), ns3::QKDApp014::ExchangeInfoMessages(), GetHeadersSize(), ns3::QKDApp004::GetKeyFromKMS(), ns3::QKDApp014::GetKeysFromKMS(), ns3::QKDApp014::GetKeyWithKeyIDs(), ns3::QKDApp014::GetStatusFromKMS(), ns3::QKDKeyManagerSystemApplication::NegotiateKeysForAssociation(), ns3::QKDKeyManagerSystemApplication::NewAppRequest(), ns3::QKDApp004::OpenConnect(), ns3::QKDKeyManagerSystemApplication::PacketReceived(), ns3::QKDSDNController::PacketReceived(), ns3::QKDApp004::PacketReceivedFromKMS(), ns3::QKDApp014::PacketReceivedFromKMS(), ns3::QKDKeyManagerSystemApplication::PacketReceivedKMSs(), ns3::QKDKeyManagerSystemApplication::PacketReceivedSDN(), ns3::QKDKeyManagerSystemApplication::ProcessAddKeysRequest(), ns3::QKDKeyManagerSystemApplication::ProcessCloseRequest(), ns3::QKDKeyManagerSystemApplication::ProcessGetKey004Request(), ns3::QKDKeyManagerSystemApplication::ProcessKMSCloseRequest(), ns3::QKDKeyManagerSystemApplication::ProcessNewAppRequest(), ns3::QKDKeyManagerSystemApplication::ProcessNewAppResponse(), ns3::QKDKeyManagerSystemApplication::ProcessOpenConnectRequest(), ns3::QKDKeyManagerSystemApplication::ProcessRegisterRequest(), ns3::QKDKeyManagerSystemApplication::ProcessRequest(), ns3::QKDSDNController::ProcessRequest(), ns3::QKDKeyManagerSystemApplication::ProcessTransformRequest(), ns3::QKDKeyManagerSystemApplication::RegisterApplicationEntry(), ns3::QKDKeyManagerSystemApplication::RegisterRequest(), ns3::QKDApp004::SendKsidRequest(), ns3::QKDApp004::SendKsidResponse(), ns3::QKDApp004::SendMaliciousRequestToKMS(), ns3::QKDKeyManagerSystemApplication::SendQKDLinkStatusToSDN(), ns3::QKDApp004::SignalingPacketReceivedFromApp(), ns3::QKDApp014::SignalingPacketReceivedFromApp(), and ns3::QKDKeyManagerSystemApplication::TransformKeys().

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

Member Data Documentation

◆ m_body

std::vector<uint8_t> ns3::HTTPMessage::m_body
private

A vector of unsigned 8-bit integers used to store message bodies.

Definition at line 906 of file http.h.

Referenced by GetMessageBody(), GetMessageBodyString(), SetMessageBody(), and ToString().

◆ m_contentLength

uint32_t ns3::HTTPMessage::m_contentLength = 0
private

Definition at line 913 of file http.h.

Referenced by GetContentLength(), SetHeader(), and ToString().

◆ m_domain

std::string ns3::HTTPMessage::m_domain
private

Definition at line 886 of file http.h.

Referenced by CreateRequest(), SetHeader(), and SetPath().

◆ m_fragmented

bool ns3::HTTPMessage::m_fragmented = false
private

Whether the payload size is less then content-length.

Definition at line 911 of file http.h.

Referenced by IsFragmented(), and SetFragmented().

◆ m_headers

std::unordered_map<std::string, std::string> ns3::HTTPMessage::m_headers
private

An unordered_map of headers using a std::string for both the key and the value.

Definition at line 901 of file http.h.

Referenced by GetHeader(), HeaderCount(), SetHeader(), SetHeaders(), and ToString().

◆ m_headersLength

uint32_t ns3::HTTPMessage::m_headersLength = 0
private

Definition at line 914 of file http.h.

Referenced by GetHeadersSize(), and ToString().

◆ m_method

HTTPMessage::HttpMethod ns3::HTTPMessage::m_method = HTTPMessage::HttpMethod::NONE
private

The HTTP method for this message.

Defaults to NONE denoting a response.

Definition at line 862 of file http.h.

Referenced by GetMethod(), GetMethodToString(), SetMethod(), and ToString().

◆ m_path

std::string ns3::HTTPMessage::m_path = ""
private

The path for the resource specified in the message.

Only used for a request.

Defaults to blank.

Definition at line 883 of file http.h.

Referenced by GetPath(), SetPath(), and ToString().

◆ m_request_uri

std::string ns3::HTTPMessage::m_request_uri
private

Definition at line 888 of file http.h.

Referenced by GetRequestUri(), and SetHeader().

◆ m_scheme

std::string ns3::HTTPMessage::m_scheme
private

Definition at line 885 of file http.h.

Referenced by SetPath().

◆ m_statusCode

uint16_t ns3::HTTPMessage::m_statusCode = 0
private

A status code for this message.

This is ignored if this is a request, as requests have no notion of statuses.

Definition at line 869 of file http.h.

Referenced by GetStatus(), GetStatusCode(), SetStatusCode(), and ToString().

◆ m_statusMessage

std::string ns3::HTTPMessage::m_statusMessage = ""
private

A status message to be associated with the status code for this message.

Keep blank to use an automatically generated status message.

Definition at line 876 of file http.h.

Referenced by GetStatusMessage(), SetStatusMessage(), and ToString().

◆ m_uri

std::string ns3::HTTPMessage::m_uri
private

Definition at line 887 of file http.h.

Referenced by GetUri(), SetHeader(), and SetPath().

◆ m_version

std::string ns3::HTTPMessage::m_version = HTTPVersion11
private

The version used for this HTTP message as a string.

Defaults to "HTTP/1.1"

Definition at line 895 of file http.h.

Referenced by GetVersion(), and SetVersion().


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