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

Header used by web browsing applications to transmit information about content type, content length and timestamps for delay statistics. More...

#include "http-header.h"

+ Inheritance diagram for ns3::HttpHeader:
+ Collaboration diagram for ns3::HttpHeader:

Public Types

enum  ContentType_t { NOT_SET = 0 , MAIN_OBJECT = 1 , EMBEDDED_OBJECT = 2 }
 The possible types of content (default = NOT_SET). More...
 
enum  HttpMethod {
  DELETE = 0 , GET = 1 , HEAD = 2 , PATCH = 3 ,
  POST = 4 , PUT = 5
}
 
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

 HttpHeader ()
 Creates an empty instance . More...
 
void CreateRequest (const std::string &url, const std::string &method, const std::map< std::string, std::string > &parameters, 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...
 

Detailed Description

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):

  • content type (2 bytes);
  • content length (4 bytes);
  • client time stamp (8 bytes); and
  • server time stamp (8 bytes).

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.

Member Enumeration Documentation

◆ ContentType_t

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.

◆ HttpMethod

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.

◆ 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 78 of file http-header.h.

Constructor & Destructor Documentation

◆ HttpHeader()

ns3::HttpHeader::HttpHeader ( )

Creates an empty instance .

Definition at line 33 of file http-header.cc.

References m_fragmented, and NS_LOG_FUNCTION.

Member Function Documentation

◆ CreateRequest() [1/3]

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

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

◆ CreateRequest() [2/3]

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

+ Here is the call graph for this function:

◆ CreateRequest() [3/3]

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.

+ Here is the call graph for this function:

◆ CreateResponse() [1/3]

void ns3::HttpHeader::CreateResponse ( const HttpHeader::HttpStatus  status,
const std::map< std::string, std::string > &  body,
const std::vector< std::string > &  headers = {} 
)

Referenced by CreateResponse().

+ Here is the caller graph for this function:

◆ CreateResponse() [2/3]

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

+ Here is the call graph for this function:

◆ CreateResponse() [3/3]

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

+ Here is the call graph for this function:

◆ Deserialize()

uint32_t ns3::HttpHeader::Deserialize ( Buffer::Iterator  start)
virtual
Parameters
startan iterator which points to where the header should read from.
Returns
the number of bytes read.

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

+ Here is the call graph for this function:

◆ GetContentSize()

uint32_t ns3::HttpHeader::GetContentSize ( )

Definition at line 581 of file http-header.cc.

References m_contentLength, and NS_LOG_FUNCTION.

◆ GetHeaderSize()

uint32_t ns3::HttpHeader::GetHeaderSize ( )

Definition at line 576 of file http-header.cc.

References m_headerSize.

◆ GetHeaderString()

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.

◆ GetInstanceTypeId()

TypeId ns3::HttpHeader::GetInstanceTypeId ( ) const
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.

Returns
The TypeId associated to the most-derived type of this instance.

Implements ns3::ObjectBase.

Definition at line 489 of file http-header.cc.

References GetTypeId().

+ Here is the call graph for this function:

◆ GetMethod()

HttpHeader::HttpMethod ns3::HttpHeader::GetMethod ( ) const
Returns
The connection method.

Definition at line 1197 of file http-header.cc.

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

◆ GetPayload()

std::vector<uint8_t> ns3::HttpHeader::GetPayload ( )
inline

Definition at line 210 of file http-header.h.

References m_payload.

◆ GetPayloadString()

std::string ns3::HttpHeader::GetPayloadString ( )
inline

Definition at line 214 of file http-header.h.

References m_headers, m_payload, and ParseResponse().

Referenced by CreateResponse().

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

◆ GetRequestUri()

std::string ns3::HttpHeader::GetRequestUri ( ) const
Returns
The request uri value

Definition at line 1282 of file http-header.cc.

References m_request_uri.

◆ GetSerializedSize()

uint32_t ns3::HttpHeader::GetSerializedSize ( ) const
virtual
Returns
the expected size of the header.

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

+ Here is the caller graph for this function:

◆ GetSize()

uint32_t ns3::HttpHeader::GetSize ( void  ) const
Returns
The content length (in bytes).

Definition at line 587 of file http-header.cc.

References m_contentLength, and m_headerSize.

◆ GetStatus()

◆ GetStatusString()

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

+ Here is the caller graph for this function:

◆ GetTypeId()

TypeId ns3::HttpHeader::GetTypeId ( void  )
static

Returns the object TypeId.

Returns
The object TypeId.

Definition at line 479 of file http-header.cc.

References ns3::TypeId::SetParent().

Referenced by GetInstanceTypeId().

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

◆ GetUri()

std::string ns3::HttpHeader::GetUri ( ) const
Returns
The uri value

Definition at line 1276 of file http-header.cc.

References m_uri.

◆ IsFragmented()

bool ns3::HttpHeader::IsFragmented ( )
inline

Definition at line 275 of file http-header.h.

References m_fragmented.

◆ ParseResponse()

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

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

◆ Print()

void ns3::HttpHeader::Print ( std::ostream &  os) const
virtual
Parameters
osoutput 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().

+ Here is the caller graph for this function:

◆ Serialize()

void ns3::HttpHeader::Serialize ( Buffer::Iterator  start) const
virtual
Parameters
startan 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().

+ Here is the call graph for this function:

◆ SetHeaderString()

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

+ Here is the call graph for this function:

◆ SetMethod() [1/2]

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

+ Here is the call graph for this function:

◆ SetMethod() [2/2]

void ns3::HttpHeader::SetMethod ( HttpHeader::HttpMethod  method)
Parameters
methodThe 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().

+ Here is the caller graph for this function:

◆ SetStatus()

◆ SetUri()

void ns3::HttpHeader::SetUri ( const std::string &  url)
Parameters
std::stringThe 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().

+ Here is the caller graph for this function:

◆ ToString()

std::string ns3::HttpHeader::ToString ( ) const
Returns
The string representation of the header.

Definition at line 567 of file http-header.cc.

References NS_LOG_FUNCTION, and Print().

+ Here is the call graph for this function:

◆ urlEncode()

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

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_allData

std::vector<uint8_t> ns3::HttpHeader::m_allData
private

◆ m_contentLength

uint32_t ns3::HttpHeader::m_contentLength
private

◆ m_contentType

uint16_t ns3::HttpHeader::m_contentType
private

" Content type field in integer format.

Definition at line 291 of file http-header.h.

◆ m_domain

std::string ns3::HttpHeader::m_domain
private

Definition at line 282 of file http-header.h.

Referenced by CreateRequest(), and SetUri().

◆ m_fragmented

bool ns3::HttpHeader::m_fragmented
private

Definition at line 295 of file http-header.h.

Referenced by HttpHeader(), IsFragmented(), and ParseResponse().

◆ m_headers

std::vector<std::string> ns3::HttpHeader::m_headers
private

◆ m_headerSize

uint32_t ns3::HttpHeader::m_headerSize
private

◆ m_method

uint16_t ns3::HttpHeader::m_method
private

" Connection method field in integer format.

Definition at line 289 of file http-header.h.

Referenced by GetMethod(), and SetMethod().

◆ m_path

std::string ns3::HttpHeader::m_path
private

Definition at line 283 of file http-header.h.

Referenced by CreateRequest(), and SetUri().

◆ m_payload

std::vector<uint8_t> ns3::HttpHeader::m_payload
private

◆ m_request_uri

std::string ns3::HttpHeader::m_request_uri
private

Definition at line 298 of file http-header.h.

Referenced by GetRequestUri(), and ParseResponse().

◆ m_scheme

std::string ns3::HttpHeader::m_scheme
private

Definition at line 281 of file http-header.h.

Referenced by SetUri().

◆ m_status

uint16_t ns3::HttpHeader::m_status
private

" Connection status field in integer format.

Definition at line 290 of file http-header.h.

Referenced by CreateResponse(), GetStatus(), GetStatusString(), ParseResponse(), and SetStatus().

◆ m_uri

std::string ns3::HttpHeader::m_uri
private

Definition at line 297 of file http-header.h.

Referenced by GetUri(), ParseResponse(), and SetUri().


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