Header used by web browsing applications to transmit information about content type, content length and timestamps for delay statistics. More...
#include "http-header.h"
Public Member Functions | |
HttpHeader () | |
Creates an empty instance . More... | |
void | CreateRequest (const std::string &url, const std::string &method, const std::map< std::string, std::string > ¶meters, const std::vector< std::string > &headers={}) |
void | CreateRequest (const std::string &url, const std::string &method, const std::vector< uint8_t > &body, const std::vector< std::string > &headers) |
void | CreateRequest (const std::string &url, const std::string &method="GET", const std::string &body="", const std::vector< std::string > &headers={}) |
void | CreateResponse (const HttpHeader::HttpStatus status, const std::map< std::string, std::string > &body, const std::vector< std::string > &headers={}) |
void | CreateResponse (const HttpHeader::HttpStatus status, const std::string &body="", const std::vector< std::string > &headers={}) |
void | CreateResponse (const HttpHeader::HttpStatus status, const std::vector< uint8_t > &body, const std::vector< std::string > &headers) |
virtual uint32_t | Deserialize (Buffer::Iterator start) |
uint32_t | GetContentSize () |
uint32_t | GetHeaderSize () |
std::string | GetHeaderString () |
virtual TypeId | GetInstanceTypeId () const |
Get the most derived TypeId for this Object. More... | |
HttpMethod | GetMethod () const |
std::vector< uint8_t > | GetPayload () |
std::string | GetPayloadString () |
std::string | GetRequestUri () const |
virtual uint32_t | GetSerializedSize () const |
uint32_t | GetSize () const |
HttpStatus | GetStatus () const |
std::string | GetStatusString () const |
std::string | GetUri () const |
bool | IsFragmented () |
void | ParseResponse () |
virtual void | Print (std::ostream &os) const |
virtual void | Serialize (Buffer::Iterator start) const |
void | SetHeaderString (std::string input) |
void | SetMethod (const std::string &m) |
void | SetMethod (HttpMethod method) |
void | SetStatus (HttpStatus status) |
void | SetUri (const std::string &url) |
std::string | ToString () const |
std::string | urlEncode (const std::string &str) |
Public Member Functions inherited from ns3::Header | |
virtual | ~Header () |
virtual uint32_t | Deserialize (Buffer::Iterator start)=0 |
Deserialize the object from a buffer iterator. More... | |
virtual uint32_t | Deserialize (Buffer::Iterator start, Buffer::Iterator end) |
Deserialize the object from a buffer iterator. More... | |
Public Member Functions inherited from ns3::Chunk | |
virtual uint32_t | Deserialize (Buffer::Iterator start, Buffer::Iterator end) |
Deserialize the object from a buffer iterator. More... | |
Public Member Functions inherited from ns3::ObjectBase | |
virtual | ~ObjectBase () |
Virtual destructor. More... | |
void | GetAttribute (std::string name, AttributeValue &value) const |
Get the value of an attribute, raising fatal errors if unsuccessful. More... | |
bool | GetAttributeFailSafe (std::string name, AttributeValue &value) const |
Get the value of an attribute without raising erros. More... | |
void | SetAttribute (std::string name, const AttributeValue &value) |
Set a single attribute, raising fatal errors if unsuccessful. More... | |
bool | SetAttributeFailSafe (std::string name, const AttributeValue &value) |
Set a single attribute without raising errors. More... | |
bool | TraceConnect (std::string name, std::string context, const CallbackBase &cb) |
Connect a TraceSource to a Callback with a context. More... | |
bool | TraceConnectWithoutContext (std::string name, const CallbackBase &cb) |
Connect a TraceSource to a Callback without a context. More... | |
bool | TraceDisconnect (std::string name, std::string context, const CallbackBase &cb) |
Disconnect from a TraceSource a Callback previously connected with a context. More... | |
bool | TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb) |
Disconnect from a TraceSource a Callback previously connected without a context. More... | |
Static Public Member Functions | |
static TypeId | GetTypeId () |
Returns the object TypeId. More... | |
Static Public Member Functions inherited from ns3::Header | |
static TypeId | GetTypeId (void) |
Get the type ID. More... | |
Static Public Member Functions inherited from ns3::Chunk | |
static TypeId | GetTypeId (void) |
Get the type ID. More... | |
Static Public Member Functions inherited from ns3::ObjectBase | |
static TypeId | GetTypeId (void) |
Get the type ID. More... | |
Private Attributes | |
std::vector< uint8_t > | m_allData |
uint32_t | m_contentLength |
" Content length field (in bytes unit). More... | |
uint16_t | m_contentType |
" Content type field in integer format. More... | |
std::string | m_domain |
bool | m_fragmented |
std::vector< std::string > | m_headers |
uint32_t | m_headerSize |
uint16_t | m_method |
" Connection method field in integer format. More... | |
std::string | m_path |
std::vector< uint8_t > | m_payload |
std::string | m_request_uri |
std::string | m_scheme |
uint16_t | m_status |
" Connection status field in integer format. More... | |
std::string | m_uri |
Additional Inherited Members | |
Protected Member Functions inherited from ns3::ObjectBase | |
void | ConstructSelf (const AttributeConstructionList &attributes) |
Complete construction of ObjectBase; invoked by derived classes. More... | |
virtual void | NotifyConstructionCompleted (void) |
Notifier called once the ObjectBase is fully constructed. More... | |
Related Functions inherited from ns3::ObjectBase | |
static TypeId | GetObjectIid (void) |
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly. More... | |
Header used by web browsing applications to transmit information about content type, content length and timestamps for delay statistics.
The header contains the following fields (and their respective size when serialized):
The header is attached to every packet transmitted by HttpClient and HttpServer applications. In received, split packets, only the first packet of transmitted object contains the header, which helps to identify how many bytes are left to be received.
The last 2 fields allow the applications to compute the propagation delay of each packet. The client TS field indicates the time when the request packet is sent by the HttpClient, while the server TS field indicates the time when the response packet is sent by the HttpServer.
Definition at line 56 of file http-header.h.
The possible types of content (default = NOT_SET).
Enumerator | |
---|---|
NOT_SET | Integer equivalent = 0. |
MAIN_OBJECT | Integer equivalent = 1. |
EMBEDDED_OBJECT | Integer equivalent = 2. |
Definition at line 62 of file http-header.h.
Enumerator | |
---|---|
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 69 of file http-header.h.
Definition at line 78 of file http-header.h.
ns3::HttpHeader::HttpHeader | ( | ) |
Creates an empty instance .
Definition at line 33 of file http-header.cc.
References m_fragmented, and NS_LOG_FUNCTION.
void ns3::HttpHeader::CreateRequest | ( | const std::string & | url, |
const std::string & | method, | ||
const std::map< std::string, std::string > & | parameters, | ||
const std::vector< std::string > & | headers = {} |
||
) |
Definition at line 44 of file http-header.cc.
References NS_LOG_FUNCTION, and urlEncode().
Referenced by CreateRequest().
void ns3::HttpHeader::CreateRequest | ( | const std::string & | url, |
const std::string & | method, | ||
const std::vector< uint8_t > & | body, | ||
const std::vector< std::string > & | headers | ||
) |
Definition at line 84 of file http-header.cc.
References m_allData, m_contentLength, m_domain, m_headers, m_headerSize, m_path, m_payload, NS_LOG_FUNCTION, SetMethod(), SetUri(), and nlohmann::to_string().
void ns3::HttpHeader::CreateRequest | ( | const std::string & | url, |
const std::string & | method = "GET" , |
||
const std::string & | body = "" , |
||
const std::vector< std::string > & | headers = {} |
||
) |
Definition at line 67 of file http-header.cc.
References CreateRequest(), and NS_LOG_FUNCTION.
void ns3::HttpHeader::CreateResponse | ( | const HttpHeader::HttpStatus | status, |
const std::map< std::string, std::string > & | body, | ||
const std::vector< std::string > & | headers = {} |
||
) |
void ns3::HttpHeader::CreateResponse | ( | const HttpHeader::HttpStatus | status, |
const std::string & | body = "" , |
||
const std::vector< std::string > & | headers = {} |
||
) |
Definition at line 141 of file http-header.cc.
References CreateResponse().
void ns3::HttpHeader::CreateResponse | ( | const HttpHeader::HttpStatus | status, |
const std::vector< uint8_t > & | body, | ||
const std::vector< std::string > & | headers | ||
) |
Definition at line 154 of file http-header.cc.
References GetPayloadString(), GetStatusString(), m_allData, m_contentLength, m_headers, m_payload, m_status, NS_LOG_FUNCTION, SetStatus(), and nlohmann::to_string().
|
virtual |
start | an iterator which points to where the header should read from. |
This method is used by Packet::RemoveHeader to re-create a header from the byte buffer of a packet. The data read is expected to match bit-for-bit the representation of this header in real networks.
Note that data is not actually removed from the buffer to which the iterator points. Both Packet::RemoveHeader() and Packet::PeekHeader() call Deserialize(), but only the RemoveHeader() has additional statements to remove the header bytes from the underlying buffer and associated metadata.
Implements ns3::Header.
Definition at line 518 of file http-header.cc.
References ns3::Buffer::Iterator::GetDistanceFrom(), GetSerializedSize(), m_allData, m_contentLength, m_headers, m_payload, NS_ASSERT, NS_LOG_FUNCTION, ParseResponse(), ns3::Buffer::Iterator::Read(), ns3::Buffer::Iterator::ReadU32(), and visualizer.core::start().
uint32_t ns3::HttpHeader::GetContentSize | ( | ) |
Definition at line 581 of file http-header.cc.
References m_contentLength, and NS_LOG_FUNCTION.
uint32_t ns3::HttpHeader::GetHeaderSize | ( | ) |
Definition at line 576 of file http-header.cc.
References m_headerSize.
std::string ns3::HttpHeader::GetHeaderString | ( | ) |
Definition at line 410 of file http-header.cc.
References m_allData, m_contentLength, m_headerSize, and NS_LOG_FUNCTION.
|
virtual |
Get the most derived TypeId for this Object.
This method is typically implemented by ns3::Object::GetInstanceTypeId but some classes which derive from ns3::ObjectBase directly have to implement it themselves.
Implements ns3::ObjectBase.
Definition at line 489 of file http-header.cc.
References GetTypeId().
HttpHeader::HttpMethod ns3::HttpHeader::GetMethod | ( | ) | const |
Definition at line 1197 of file http-header.cc.
References DELETE, GET, HEAD, m_method, NS_FATAL_ERROR, PATCH, POST, and PUT.
|
inline |
Definition at line 210 of file http-header.h.
References m_payload.
|
inline |
Definition at line 214 of file http-header.h.
References m_headers, m_payload, and ParseResponse().
Referenced by CreateResponse().
std::string ns3::HttpHeader::GetRequestUri | ( | ) | const |
Definition at line 1282 of file http-header.cc.
References m_request_uri.
|
virtual |
This method is used by Packet::AddHeader to store a header into the byte buffer of a packet. This method should return the number of bytes which are needed to store the full header data by Serialize.
Implements ns3::Header.
Definition at line 495 of file http-header.cc.
References m_contentLength, and m_headerSize.
Referenced by Deserialize().
uint32_t ns3::HttpHeader::GetSize | ( | void | ) | const |
Definition at line 587 of file http-header.cc.
References m_contentLength, and m_headerSize.
HttpHeader::HttpStatus ns3::HttpHeader::GetStatus | ( | ) | const |
Definition at line 795 of file http-header.cc.
References Accepted, AlreadyReported, BadGateway, BadRequest, Conflict, Continue, Created, EarlyHints, ExpectationFailed, FailedDependency, Forbidden, Found, GatewayTimeout, Gone, HttpVersionNotSupported, ImaTeapot, ImUsed, InsufficientStorage, InternalServerError, LengthRequired, Locked, LoopDetected, m_status, MethodNotAllowed, MisdirectedRequest, MovedPermanently, MultipleChoice, MultiStatus, NetworkAuthenticationRequired, NoContent, NonAuthoritativeInformation, NotAcceptable, NotExtended, NotFound, NotImplemented, NotModified, NS_FATAL_ERROR, Ok, PartialContent, PayloadTooLarge, PaymentRequired, PermanentRedirect, PreconditionFailed, PreconditionRequired, Processing, ProxyAuthenticationRequired, RangeNotSatisfiable, RequestHeaderFieldsTooLarge, RequestTimeout, ResetContent, SeeOther, ServiceUnavailable, SwitchingProtocol, TemporaryRedirect, TooEarly, TooManyRequests, Unauthorized, UnavailableForLegalReasons, UnprocessableEntity, UnsupportedMediaType, UpgradeRequired, UriTooLong, UseProxy, and VariantAlsoNegotiates.
std::string ns3::HttpHeader::GetStatusString | ( | ) | const |
Definition at line 999 of file http-header.cc.
References m_status, and NS_FATAL_ERROR.
Referenced by CreateResponse().
|
static |
Returns the object TypeId.
Definition at line 479 of file http-header.cc.
References ns3::TypeId::SetParent().
Referenced by GetInstanceTypeId().
std::string ns3::HttpHeader::GetUri | ( | ) | const |
|
inline |
Definition at line 275 of file http-header.h.
References m_fragmented.
void ns3::HttpHeader::ParseResponse | ( | ) |
Definition at line 204 of file http-header.cc.
References m_allData, m_contentLength, m_fragmented, m_headers, m_headerSize, m_payload, m_request_uri, m_status, m_uri, min, NS_FATAL_ERROR, NS_LOG_FUNCTION, and SetMethod().
Referenced by Deserialize(), GetPayloadString(), and SetHeaderString().
|
virtual |
os | output stream This method is used by Packet::Print to print the content of a header as ascii data to a c++ output stream. Although the header is free to format its output as it wishes, it is recommended to follow a few rules to integrate with the packet pretty printer: start with flags, small field values located between a pair of parens. Values should be separated by whitespace. Follow the parens with the important fields, separated by whitespace. i.e.: (field1 val1 field2 val2 field3 val3) field4 val4 field5 val5 |
Implements ns3::Header.
Definition at line 557 of file http-header.cc.
References m_allData, m_contentLength, m_headerSize, and NS_LOG_FUNCTION.
Referenced by ToString().
|
virtual |
start | an iterator which points to where the header should be written. |
This method is used by Packet::AddHeader to store a header into the byte buffer of a packet. The data written is expected to match bit-for-bit the representation of this header in a real network.
Implements ns3::Header.
Definition at line 501 of file http-header.cc.
References m_allData, m_contentLength, NS_LOG_FUNCTION, and visualizer.core::start().
void ns3::HttpHeader::SetHeaderString | ( | std::string | input | ) |
Definition at line 421 of file http-header.cc.
References m_allData, m_contentLength, m_headers, m_headerSize, m_payload, NS_LOG_FUNCTION, and ParseResponse().
void ns3::HttpHeader::SetMethod | ( | const std::string & | m | ) |
Definition at line 1141 of file http-header.cc.
References DELETE, GET, HEAD, NS_FATAL_ERROR, NS_LOG_FUNCTION, PATCH, POST, PUT, and SetMethod().
void ns3::HttpHeader::SetMethod | ( | HttpHeader::HttpMethod | method | ) |
method | The connection method. |
Definition at line 1166 of file http-header.cc.
References DELETE, GET, HEAD, m_method, NS_FATAL_ERROR, NS_LOG_FUNCTION, PATCH, POST, and PUT.
Referenced by CreateRequest(), ParseResponse(), and SetMethod().
void ns3::HttpHeader::SetStatus | ( | HttpHeader::HttpStatus | status | ) |
status | The connection status. |
Definition at line 593 of file http-header.cc.
References Accepted, AlreadyReported, BadGateway, BadRequest, Conflict, Continue, Created, EarlyHints, ExpectationFailed, FailedDependency, Forbidden, Found, GatewayTimeout, Gone, HttpVersionNotSupported, ImaTeapot, ImUsed, InsufficientStorage, InternalServerError, LengthRequired, Locked, LoopDetected, m_status, MethodNotAllowed, MisdirectedRequest, MovedPermanently, MultipleChoice, MultiStatus, NetworkAuthenticationRequired, NoContent, NonAuthoritativeInformation, NotAcceptable, NotExtended, NotFound, NotImplemented, NotModified, NS_FATAL_ERROR, NS_LOG_FUNCTION, Ok, PartialContent, PayloadTooLarge, PaymentRequired, PermanentRedirect, PreconditionFailed, PreconditionRequired, Processing, ProxyAuthenticationRequired, RangeNotSatisfiable, RequestHeaderFieldsTooLarge, RequestTimeout, ResetContent, SeeOther, ServiceUnavailable, SwitchingProtocol, TemporaryRedirect, TooEarly, TooManyRequests, Unauthorized, UnavailableForLegalReasons, UnprocessableEntity, UnsupportedMediaType, UpgradeRequired, UriTooLong, UseProxy, and VariantAlsoNegotiates.
Referenced by CreateResponse().
void ns3::HttpHeader::SetUri | ( | const std::string & | url | ) |
std::string | The uri. |
Definition at line 1287 of file http-header.cc.
References m_domain, m_path, m_scheme, m_uri, and NS_LOG_FUNCTION.
Referenced by CreateRequest().
std::string ns3::HttpHeader::ToString | ( | ) | const |
Definition at line 567 of file http-header.cc.
References NS_LOG_FUNCTION, and Print().
std::string ns3::HttpHeader::urlEncode | ( | const std::string & | str | ) |
Definition at line 1229 of file http-header.cc.
References test-ns3::result.
Referenced by CreateRequest().
|
private |
Definition at line 287 of file http-header.h.
Referenced by CreateRequest(), CreateResponse(), Deserialize(), GetHeaderString(), ParseResponse(), Print(), Serialize(), and SetHeaderString().
|
private |
" Content length field (in bytes unit).
Definition at line 292 of file http-header.h.
Referenced by CreateRequest(), CreateResponse(), Deserialize(), GetContentSize(), GetHeaderString(), GetSerializedSize(), GetSize(), ParseResponse(), Print(), Serialize(), and SetHeaderString().
|
private |
" Content type field in integer format.
Definition at line 291 of file http-header.h.
|
private |
Definition at line 282 of file http-header.h.
Referenced by CreateRequest(), and SetUri().
|
private |
Definition at line 295 of file http-header.h.
Referenced by HttpHeader(), IsFragmented(), and ParseResponse().
|
private |
Definition at line 285 of file http-header.h.
Referenced by CreateRequest(), CreateResponse(), Deserialize(), GetPayloadString(), ParseResponse(), and SetHeaderString().
|
private |
Definition at line 293 of file http-header.h.
Referenced by CreateRequest(), GetHeaderSize(), GetHeaderString(), GetSerializedSize(), GetSize(), ParseResponse(), Print(), and SetHeaderString().
|
private |
" Connection method field in integer format.
Definition at line 289 of file http-header.h.
Referenced by GetMethod(), and SetMethod().
|
private |
Definition at line 283 of file http-header.h.
Referenced by CreateRequest(), and SetUri().
|
private |
Definition at line 286 of file http-header.h.
Referenced by CreateRequest(), CreateResponse(), Deserialize(), GetPayload(), GetPayloadString(), ParseResponse(), and SetHeaderString().
|
private |
Definition at line 298 of file http-header.h.
Referenced by GetRequestUri(), and ParseResponse().
|
private |
Definition at line 281 of file http-header.h.
Referenced by SetUri().
|
private |
" Connection status field in integer format.
Definition at line 290 of file http-header.h.
Referenced by CreateResponse(), GetStatus(), GetStatusString(), ParseResponse(), and SetStatus().
|
private |
Definition at line 297 of file http-header.h.
Referenced by GetUri(), ParseResponse(), and SetUri().