PcapPlusPlus  20.08
pcpp::HttpRequestLayer Class Reference

#include <HttpLayer.h>

Inheritance diagram for pcpp::HttpRequestLayer:
pcpp::HttpMessage pcpp::TextBasedProtocolMessage pcpp::Layer pcpp::IDataContainer

Public Types

enum  HttpMethod {
  HttpGET, HttpHEAD, HttpPOST, HttpPUT,
  HttpDELETE, HttpTRACE, HttpOPTIONS, HttpCONNECT,
  HttpPATCH, HttpMethodUnknown
}
 

Public Member Functions

 HttpRequestLayer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
 
 HttpRequestLayer (HttpMethod method, std::string uri, HttpVersion version)
 
 HttpRequestLayer (const HttpRequestLayer &other)
 
HttpRequestLayeroperator= (const HttpRequestLayer &other)
 
HttpRequestFirstLinegetFirstLine () const
 
std::string getUrl () const
 
std::string toString () const
 
- Public Member Functions inherited from pcpp::HttpMessage
virtual HeaderFieldaddField (const std::string &fieldName, const std::string &fieldValue)
 
virtual HeaderFieldaddField (const HeaderField &newField)
 
virtual HeaderFieldinsertField (HeaderField *prevField, const std::string &fieldName, const std::string &fieldValue)
 
virtual HeaderFieldinsertField (HeaderField *prevField, const HeaderField &newField)
 
OsiModelLayer getOsiModelLayer () const
 
- Public Member Functions inherited from pcpp::TextBasedProtocolMessage
HeaderFieldgetFieldByName (std::string fieldName, int index=0) const
 
HeaderFieldgetFirstField () const
 
HeaderFieldgetNextField (HeaderField *prevField) const
 
int getFieldCount () const
 
HeaderFieldaddEndOfHeader ()
 
virtual HeaderFieldinsertField (std::string prevFieldName, const std::string &fieldName, const std::string &fieldValue)
 
bool removeField (HeaderField *fieldToRemove)
 
bool removeField (std::string fieldName, int index=0)
 
bool isHeaderComplete () const
 
virtual void parseNextLayer ()
 
size_t getHeaderLen () const
 
virtual void computeCalculateFields ()
 
- Public Member Functions inherited from pcpp::Layer
virtual ~Layer ()
 
LayergetNextLayer () const
 
LayergetPrevLayer () const
 
ProtocolType getProtocol () const
 
uint8_t * getData () const
 
size_t getDataLen () const
 
uint8_t * getLayerPayload () const
 
size_t getLayerPayloadSize () const
 
bool isAllocatedToPacket () const
 
void copyData (uint8_t *toArr) const
 
uint8_t * getDataPtr (size_t offset=0) const
 

Additional Inherited Members

- Static Public Member Functions inherited from pcpp::HttpMessage
static bool isHttpPort (uint16_t port)
 

Detailed Description

Represents an HTTP request header and inherits all basic functionality of HttpMessage and TextBasedProtocolMessage. The functionality that is added for this class is the HTTP first line concept. An HTTP request has the following first line: GET /bla/blabla.asp HTTP/1.1 Since it's not an "ordinary" HTTP field, it requires a special treatment and gets a class of it's own: HttpRequestFirstLine. Unlike most L2-4 protocols, an HTTP request header can spread over more than 1 packet. PcapPlusPlus currently doesn't support a header that is spread over more than 1 packet so in such cases: 1) only the first packet will be parsed as HttpRequestLayer (the other packets won't be recognized as HttpRequestLayer) and 2) the HTTP header for the first packet won't be complete (as it continues in the following packets), this why PcapPlusPlus can indicate that HTTP request header is complete or not(doesn't end with "\r\n\r\n" or "\n\n") using HttpMessage::isHeaderComplete()

Member Enumeration Documentation

◆ HttpMethod

HTTP request methods

Enumerator
HttpGET 

GET

HttpHEAD 

HEAD

HttpPOST 

POST

HttpPUT 

PUT

HttpDELETE 

DELETE

HttpTRACE 

TRACE

HttpOPTIONS 

OPTIONS

HttpCONNECT 

CONNECT

HttpPATCH 

PATCH

HttpMethodUnknown 

Unknown HTTP method

Constructor & Destructor Documentation

◆ HttpRequestLayer() [1/3]

pcpp::HttpRequestLayer::HttpRequestLayer ( uint8_t *  data,
size_t  dataLen,
Layer prevLayer,
Packet packet 
)

A constructor that creates the layer from an existing packet raw data

Parameters
[in]dataA pointer to the raw data
[in]dataLenSize of the data in bytes
[in]prevLayerA pointer to the previous layer
[in]packetA pointer to the Packet instance where layer will be stored in

◆ HttpRequestLayer() [2/3]

pcpp::HttpRequestLayer::HttpRequestLayer ( HttpMethod  method,
std::string  uri,
HttpVersion  version 
)

A constructor that allocates a new HTTP request header with only the first line filled. Object will be created without further fields. The user can then add fields using addField() methods

Parameters
[in]methodThe HTTP method used in this HTTP request
[in]uriThe URI of the first line
[in]versionHTTP version to be used in this request

◆ HttpRequestLayer() [3/3]

pcpp::HttpRequestLayer::HttpRequestLayer ( const HttpRequestLayer other)

A copy constructor for this layer. This copy constructor inherits base copy constructor HttpMessage::HttpMessage() and add the functionality of copying the first line as well

Parameters
[in]otherThe instance to copy from

Member Function Documentation

◆ getFirstLine()

HttpRequestFirstLine* pcpp::HttpRequestLayer::getFirstLine ( ) const
inline
Returns
A pointer to the first line instance for this message

◆ getUrl()

std::string pcpp::HttpRequestLayer::getUrl ( ) const

The URL is hostname+uri. So given the following URL, for example: "www.cnn.com/main.html", the hostname is "www.cnn.com" and the URI is "/.main.html". URI and hostname are split to 2 different places inside the HTTP request packet: URI is in the first line and hostname is in "HOST" field. This methods concatenates the hostname and URI to the full URL

Returns
The URL of the HTTP request message

◆ operator=()

HttpRequestLayer& pcpp::HttpRequestLayer::operator= ( const HttpRequestLayer other)

An assignment operator overload for this layer. This method inherits base assignment operator HttpMessage::operator=() and add the functionality of copying the first line as well

Parameters
[in]otherThe instance to copy from

◆ toString()

std::string pcpp::HttpRequestLayer::toString ( ) const
virtual
Returns
A string representation of the layer most important data (should look like the layer description in Wireshark)

Implements pcpp::Layer.