PcapPlusPlus  24.09
pcpp::HttpResponseFirstLine Class Reference

#include <HttpLayer.h>

Classes

class  HttpResponseFirstLineException
 

Public Member Functions

HttpResponseStatusCode getStatusCode () const
 
int getStatusCodeAsInt () const
 
std::string getStatusCodeString () const
 
bool setStatusCode (const HttpResponseStatusCode &newStatusCode, const std::string &statusCodeString)
 
bool setStatusCode (const HttpResponseStatusCode &newStatusCode)
 
HttpVersion getVersion () const
 
void setVersion (HttpVersion newVersion)
 
int getSize () const
 
bool isComplete () const
 

Static Public Member Functions

static HttpResponseStatusCode parseStatusCode (const char *data, size_t dataLen)
 
static HttpVersion parseVersion (const char *data, size_t dataLen)
 

Detailed Description

Represents an HTTP response header first line. The first line includes 2 parameters: status code (e.g 200 OK, 404 Not Found, etc.), and HTTP version (e.g HTTP/1.1). These 2 parameters are included in this class, and the user can retrieve or set them. This class cannot be instantiated by users, it's created inside HttpResponseLayer and user can get a pointer to an instance of it. The "get" methods of this class will retrieve the actual data of the HTTP response and the "set" methods will change the packet data. Since HTTP is a textual protocol, most fields aren't of fixed size and this also applies to the first line parameters. So most "set" methods of this class need in most cases to shorten or extend the data in HttpResponseLayer. These methods will return a false value if this action failed

Member Function Documentation

◆ getSize()

int pcpp::HttpResponseFirstLine::getSize ( ) const
inline
Returns
The size in bytes of the HTTP first line

◆ getStatusCode()

HttpResponseStatusCode pcpp::HttpResponseFirstLine::getStatusCode ( ) const
inline
Returns
The status code as HttpResponseStatusCode enum

◆ getStatusCodeAsInt()

int pcpp::HttpResponseFirstLine::getStatusCodeAsInt ( ) const
Returns
The status code number as integer (e.g 200, 404, etc.)

◆ getStatusCodeString()

std::string pcpp::HttpResponseFirstLine::getStatusCodeString ( ) const
Returns
The status code message (e.g "OK", "Not Found", etc.)

◆ getVersion()

HttpVersion pcpp::HttpResponseFirstLine::getVersion ( ) const
inline
Returns
The HTTP version

◆ isComplete()

bool pcpp::HttpResponseFirstLine::isComplete ( ) const
inline

As explained in HttpResponseLayer, an HTTP header can spread over more than 1 packet, so when looking at a single packet the header can be partial. Same goes for the first line - it can spread over more than 1 packet. This method returns an indication whether the first line is partial

Returns
False if the first line is partial, true if it's complete

◆ parseStatusCode()

static HttpResponseStatusCode pcpp::HttpResponseFirstLine::parseStatusCode ( const char *  data,
size_t  dataLen 
)
static

A static method for parsing the HTTP status code out of raw data

Parameters
[in]dataThe raw data
[in]dataLenThe raw data length
Returns
The parsed HTTP status code as enum

◆ parseVersion()

static HttpVersion pcpp::HttpResponseFirstLine::parseVersion ( const char *  data,
size_t  dataLen 
)
static

A static method for parsing the HTTP version out of raw first line data (e.g "HTTP/x.y")

Parameters
[in]dataThe raw data
[in]dataLenThe raw data length
Returns
The parsed HTTP status code as enum

◆ setStatusCode() [1/2]

bool pcpp::HttpResponseFirstLine::setStatusCode ( const HttpResponseStatusCode newStatusCode)

Set the status code

Parameters
[in]newStatusCodeThe new status code to set
Returns
True if setting the status code was completed successfully, false otherwise

◆ setStatusCode() [2/2]

bool pcpp::HttpResponseFirstLine::setStatusCode ( const HttpResponseStatusCode newStatusCode,
const std::string &  statusCodeString 
)

Set the status code

Parameters
[in]newStatusCodeThe new status code to set
[in]statusCodeStringAn optional parameter: set a non-default status code message (e.g "Bla Bla" instead of "Not Found"). If this parameter isn't supplied or supplied as empty string (""), the default message for the status code will be set
Returns
True if setting the status code was completed successfully, false otherwise
Deprecated:
Use the other overload instead.

◆ setVersion()

void pcpp::HttpResponseFirstLine::setVersion ( HttpVersion  newVersion)

Set the HTTP version. This method doesn't return a value since all supported HTTP versions are of the same size (HTTP/0.9, HTTP/1.0, HTTP/1.1)

Parameters
[in]newVersionThe HTTP version to set