The basic class to represent both HTTP requests and responses. More...
#include "http.h"
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) |
HTTPMessage & | SetHeader (const std::string &name, const std::string &value) |
Set a header in the map to the value provided. More... | |
HTTPMessage & | SetHeaders (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... | |
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.
|
inline |
Definition at line 738 of file http.h.
Referenced by ns3::QKDKeyManagerSystemApplication::AddNewLink(), ns3::QKDApp004::Close(), ns3::QKDApp004::CreateKeyQueues(), CreateRequest(), ns3::QKDApp014::ExchangeInfoMessages(), ns3::QKDApp004::GetKeyFromKMS(), ns3::QKDApp014::GetKeysFromKMS(), ns3::QKDApp014::GetKeyWithKeyIDs(), ns3::QKDApp014::GetStatusFromKMS(), ns3::QKDKeyManagerSystemApplication::NegotiateKeysForAssociation(), ns3::QKDKeyManagerSystemApplication::NewAppRequest(), ns3::QKDApp004::OpenConnect(), ns3::QKDKeyManagerSystemApplication::ProcessCloseRequest(), ns3::QKDKeyManagerSystemApplication::RegisterApplicationEntry(), ns3::QKDKeyManagerSystemApplication::RegisterRequest(), ns3::QKDApp004::SendKsidRequest(), ns3::QKDApp004::SendMaliciousRequestToKMS(), ns3::QKDKeyManagerSystemApplication::SendQKDLinkStatusToSDN(), and ns3::QKDKeyManagerSystemApplication::TransformKeys().
|
inline |
Definition at line 750 of file http.h.
References CreateRequest().
|
inline |
Definition at line 763 of file http.h.
References m_domain, SetHeader(), SetMessageBody(), SetMethod(), SetPath(), and nlohmann::to_string().
|
inline |
Definition at line 785 of file http.h.
Referenced by ns3::QKDApp004::CreateKeyQueuesResponse(), CreateResponse(), ns3::QKDApp014::ExchangeInfoMessages(), ns3::QKDKeyManagerSystemApplication::ProcessAddKeysRequest(), 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(), and ns3::QKDApp004::SendKsidResponse().
|
inline |
Definition at line 794 of file http.h.
References CreateResponse().
|
inline |
Definition at line 822 of file http.h.
References CreateResponse(), and SetHeaders().
|
inline |
Definition at line 804 of file http.h.
References SetHeader(), SetMessageBody(), SetMethod(), SetStatusCode(), and nlohmann::to_string().
|
inline |
Definition at line 834 of file http.h.
References CreateResponse(), and SetHeaders().
|
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().
|
inline |
|
inline |
Definition at line 681 of file http.h.
References m_headersLength, and ToString().
Referenced by GetSize(), and ns3::QKDApp004::PacketReceivedFromKMS().
|
inline |
Get the body vector for this message.
Definition at line 709 of file http.h.
References m_body.
Referenced by ns3::HTTPMessageParser::Parse().
|
inline |
Definition at line 714 of file http.h.
References m_body.
Referenced by ns3::QKDKMSQueueLogic::Enqueue(), ns3::QKDKeyManagerSystemApplication::ProcessAddKeysRequest(), ns3::QKDKeyManagerSystemApplication::ProcessAddKeysResponse(), ns3::QKDApp004::ProcessGetKeyResponse(), ns3::QKDKeyManagerSystemApplication::ProcessKMSCloseRequest(), ns3::QKDKeyManagerSystemApplication::ProcessKMSCloseResponse(), ns3::QKDKeyManagerSystemApplication::ProcessNewAppRequest(), ns3::QKDKeyManagerSystemApplication::ProcessOpenConnectRequest(), ns3::QKDApp004::ProcessOpenConnectResponse(), ns3::QKDKeyManagerSystemApplication::ProcessRequest(), ns3::QKDSDNController::ProcessRequest(), ns3::QKDApp014::ProcessResponseFromKMS(), ns3::QKDKeyManagerSystemApplication::ProcessResponseSDN(), ns3::QKDApp014::ProcessSignalingPacketFromApp(), ns3::QKDApp004::ProcessSignalingPacketFromApp(), ns3::QKDKeyManagerSystemApplication::ProcessTransformRequest(), and ns3::QKDKeyManagerSystemApplication::ProcessTransformResponse().
|
inline |
Definition at line 482 of file http.h.
References m_method.
Referenced by ns3::QKDKeyManagerSystemApplication::ProcessRequest(), and ns3::QKDSDNController::ProcessRequest().
|
inline |
|
inline |
|
inline |
Definition at line 431 of file http.h.
References m_request_uri.
Referenced by ns3::QKDApp004::ProcessCloseResponse(), ns3::QKDApp004::ProcessGetKeyResponse(), ns3::QKDApp004::ProcessOpenConnectResponse(), ns3::QKDKeyManagerSystemApplication::ProcessRequestSDN(), ns3::QKDApp004::ProcessResponseFromKMS(), and ns3::QKDKeyManagerSystemApplication::ProcessResponseSDN().
|
inline |
Definition at line 686 of file http.h.
References GetContentLength(), and GetHeadersSize().
Referenced by ns3::QKDKeyManagerSystemApplication::PacketReceived(), ns3::QKDSDNController::PacketReceived(), ns3::QKDApp004::PacketReceivedFromKMS(), ns3::QKDApp014::PacketReceivedFromKMS(), ns3::QKDKeyManagerSystemApplication::PacketReceivedKMSs(), ns3::QKDKeyManagerSystemApplication::PacketReceivedSDN(), ns3::QKDApp004::SignalingPacketReceivedFromApp(), and ns3::QKDApp014::SignalingPacketReceivedFromApp().
|
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().
|
inline |
Get the status code for this message.
Definition at line 605 of file http.h.
References m_statusCode.
Referenced by ns3::HTTPMessageParser::Parse(), ns3::QKDKeyManagerSystemApplication::ProcessAddKeysResponse(), ns3::QKDKeyManagerSystemApplication::ProcessKMSCloseResponse(), ns3::QKDKeyManagerSystemApplication::ProcessNewAppResponse(), ns3::QKDKeyManagerSystemApplication::ProcessRegisterResponse(), ns3::QKDKeyManagerSystemApplication::ProcessRequestSDN(), ns3::QKDKeyManagerSystemApplication::ProcessResponseSDN(), and ns3::QKDKeyManagerSystemApplication::ProcessTransformResponse().
|
inline |
Get the current status message for this message.
Returns an autogenerated status if one isn't specified.
Definition at line 623 of file http.h.
References m_statusMessage.
Referenced by ns3::QKDKeyManagerSystemApplication::PacketReceived(), ns3::QKDSDNController::PacketReceived(), ns3::QKDApp004::PacketReceivedFromKMS(), ns3::QKDApp014::PacketReceivedFromKMS(), ns3::QKDKeyManagerSystemApplication::PacketReceivedKMSs(), ns3::QKDKeyManagerSystemApplication::PacketReceivedSDN(), ns3::QKDApp004::SignalingPacketReceivedFromApp(), and ns3::QKDApp014::SignalingPacketReceivedFromApp().
|
inline |
Grab the uri.
Definition at line 519 of file http.h.
References m_uri.
Referenced by ns3::QKDKeyManagerSystemApplication::PacketReceivedSDN(), ns3::QKDKeyManagerSystemApplication::ProcessAddKeysRequest(), ns3::QKDKeyManagerSystemApplication::ProcessGetKey004Request(), ns3::QKDKeyManagerSystemApplication::ProcessKMSCloseRequest(), ns3::QKDKeyManagerSystemApplication::ProcessNewAppRequest(), ns3::QKDKeyManagerSystemApplication::ProcessNewAppResponse(), ns3::QKDKeyManagerSystemApplication::ProcessOpenConnectRequest(), ns3::QKDKeyManagerSystemApplication::ProcessPacketKMSs(), ns3::QKDKeyManagerSystemApplication::ProcessRegisterRequest(), ns3::QKDKeyManagerSystemApplication::ProcessRequest(), ns3::QKDSDNController::ProcessRequest(), ns3::QKDKeyManagerSystemApplication::ProcessRequestKMS(), ns3::QKDApp004::ProcessSignalingPacketFromApp(), and ns3::QKDKeyManagerSystemApplication::ProcessTransformRequest().
|
inline |
|
inline |
|
inline |
Definition at line 852 of file http.h.
References m_fragmented.
Referenced by ns3::QKDKeyManagerSystemApplication::PacketReceived(), ns3::QKDSDNController::PacketReceived(), ns3::QKDApp004::PacketReceivedFromKMS(), ns3::QKDApp014::PacketReceivedFromKMS(), ns3::QKDKeyManagerSystemApplication::PacketReceivedKMSs(), ns3::QKDKeyManagerSystemApplication::PacketReceivedSDN(), ns3::QKDApp004::SignalingPacketReceivedFromApp(), and ns3::QKDApp014::SignalingPacketReceivedFromApp().
|
inline |
Definition at line 847 of file http.h.
References m_fragmented.
Referenced by ns3::HTTPMessageParser::Parse().
|
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().
|
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().
|
inline |
Set the body of this message to a string value.
Definition at line 693 of file http.h.
Referenced by CreateRequest(), and CreateResponse().
|
inline |
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
private |
Definition at line 913 of file http.h.
Referenced by GetContentLength(), SetHeader(), and ToString().
|
private |
Definition at line 886 of file http.h.
Referenced by CreateRequest(), SetHeader(), and SetPath().
|
private |
Whether the payload size is less then content-length.
Definition at line 911 of file http.h.
Referenced by IsFragmented(), and SetFragmented().
|
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().
|
private |
Definition at line 914 of file http.h.
Referenced by GetHeadersSize(), and ToString().
|
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().
|
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().
|
private |
Definition at line 888 of file http.h.
Referenced by GetRequestUri(), and SetHeader().
|
private |
|
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().
|
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().
|
private |
Definition at line 887 of file http.h.
Referenced by GetUri(), SetHeader(), and SetPath().
|
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().