PcapPlusPlus  21.05
pcpp::HttpResponseLayer Class Reference

#include <HttpLayer.h>

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

Public Types

enum  HttpResponseStatusCode {
  Http100Continue, Http101SwitchingProtocols, Http102Processing, Http200OK,
  Http201Created, Http202Accepted, Http203NonAuthoritativeInformation, Http204NoContent,
  Http205ResetContent, Http206PartialContent, Http207MultiStatus, Http208AlreadyReported,
  Http226IMUsed, Http300MultipleChoices, Http301MovedPermanently, Http302,
  Http303SeeOther, Http304NotModified, Http305UseProxy, Http306SwitchProxy,
  Http307TemporaryRedirect, Http308PermanentRedirect, Http400BadRequest, Http401Unauthorized,
  Http402PaymentRequired, Http403Forbidden, Http404NotFound, Http405MethodNotAllowed,
  Http406NotAcceptable, Http407ProxyAuthenticationRequired, Http408RequestTimeout, Http409Conflict,
  Http410Gone, Http411LengthRequired, Http412PreconditionFailed, Http413RequestEntityTooLarge,
  Http414RequestURITooLong, Http415UnsupportedMediaType, Http416RequestedRangeNotSatisfiable, Http417ExpectationFailed,
  Http418Imateapot, Http419AuthenticationTimeout, Http420, Http422UnprocessableEntity,
  Http423Locked, Http424FailedDependency, Http426UpgradeRequired, Http428PreconditionRequired,
  Http429TooManyRequests, Http431RequestHeaderFieldsTooLarge, Http440LoginTimeout, Http444NoResponse,
  Http449RetryWith, Http450BlockedByWindowsParentalControls, Http451, Http494RequestHeaderTooLarge,
  Http495CertError, Http496NoCert, Http497HTTPtoHTTPS, Http498TokenExpiredInvalid,
  Http499, Http500InternalServerError, Http501NotImplemented, Http502BadGateway,
  Http503ServiceUnavailable, Http504GatewayTimeout, Http505HTTPVersionNotSupported, Http506VariantAlsoNegotiates,
  Http507InsufficientStorage, Http508LoopDetected, Http509BandwidthLimitExceeded, Http510NotExtended,
  Http511NetworkAuthenticationRequired, Http520OriginError, Http521WebServerIsDown, Http522ConnectionTimedOut,
  Http523ProxyDeclinedRequest, Http524aTimeoutOccurred, Http598NetworkReadTimeoutError, Http599NetworkConnectTimeoutError,
  HttpStatusCodeUnknown
}
 

Public Member Functions

 HttpResponseLayer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
 
 HttpResponseLayer (HttpVersion version, HttpResponseLayer::HttpResponseStatusCode statusCode, std::string statusCodeString="")
 
 HttpResponseLayer (const HttpResponseLayer &other)
 
HttpResponseLayeroperator= (const HttpResponseLayer &other)
 
HttpResponseFirstLinegetFirstLine () const
 
HeaderFieldsetContentLength (int contentLength, const std::string prevFieldName="")
 
int getContentLength () 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 response 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 response has the following first line: 200 OK HTTP/1.1 Since it's not an "ordinary" HTTP field, it requires a special treatment and gets a class of it's own: HttpResponseFirstLine. Unlike most L2-4 protocols, an HTTP response 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 HttpResponseLayer (the other packets won't be recognized as HttpResponseLayer) 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 response header is complete or not (doesn't end with "\r\n\r\n" or "\n\n") using HttpMessage::isHeaderComplete()

Member Enumeration Documentation

◆ HttpResponseStatusCode

Enum for HTTP response status codes

Enumerator
Http100Continue 

100 Continue

Http101SwitchingProtocols 

101 Switching Protocols

Http102Processing 

102 Processing

Http200OK 

200 OK

Http201Created 

201 Created

Http202Accepted 

202 Accepted

Http203NonAuthoritativeInformation 

203 Non-Authoritative Information

Http204NoContent 

204 No Content

Http205ResetContent 

205 Reset Content

Http206PartialContent 

206 Partial Content

Http207MultiStatus 

207 Multi-Status

Http208AlreadyReported 

208 Already Reported

Http226IMUsed 

226 IM Used

Http300MultipleChoices 

300 Multiple Choices

Http301MovedPermanently 

301 Moved Permanently

Http302 

302 (various messages)

Http303SeeOther 

303 See Other

Http304NotModified 

304 Not Modified

Http305UseProxy 

305 Use Proxy

Http306SwitchProxy 

306 Switch Proxy

Http307TemporaryRedirect 

307 Temporary Redirect

Http308PermanentRedirect 

308 Permanent Redirect,

Http400BadRequest 

400 Bad Request

Http401Unauthorized 

401 Unauthorized

Http402PaymentRequired 

402 Payment Required

Http403Forbidden 

403 Forbidden

Http404NotFound 

404 Not Found

Http405MethodNotAllowed 

405 Method Not Allowed

Http406NotAcceptable 

406 Not Acceptable

Http407ProxyAuthenticationRequired 

407 Proxy Authentication Required

Http408RequestTimeout 

408 Request Timeout

Http409Conflict 

409 Conflict

Http410Gone 

410 Gone

Http411LengthRequired 

411 Length Required

Http412PreconditionFailed 

412 Precondition Failed

Http413RequestEntityTooLarge 

413 RequestEntity Too Large

Http414RequestURITooLong 

414 Request-URI Too Long

Http415UnsupportedMediaType 

415 Unsupported Media Type

Http416RequestedRangeNotSatisfiable 

416 Requested Range Not Satisfiable

Http417ExpectationFailed 

417 Expectation Failed

Http418Imateapot 

418 I'm a teapot

Http419AuthenticationTimeout 

419 Authentication Timeout

Http420 

420 (various messages)

Http422UnprocessableEntity 

422 Unprocessable Entity

Http423Locked 

423 Locked

Http424FailedDependency 

424 Failed Dependency

Http426UpgradeRequired 

426 Upgrade Required

Http428PreconditionRequired 

428 Precondition Required

Http429TooManyRequests 

429 Too Many Requests

Http431RequestHeaderFieldsTooLarge 

431 Request Header Fields Too Large

Http440LoginTimeout 

440 Login Timeout

Http444NoResponse 

444 No Response

Http449RetryWith 

449 Retry With

Http450BlockedByWindowsParentalControls 

450 Blocked by Windows Parental Controls

Http451 

451 (various messages)

Http494RequestHeaderTooLarge 

494 Request Header Too Large

Http495CertError 

495 Cert Error

Http496NoCert 

496 No Cert

Http497HTTPtoHTTPS 

497 HTTP to HTTPS

Http498TokenExpiredInvalid 

498 Token expired/invalid

Http499 

499 (various messages)

Http500InternalServerError 

500 Internal Server Error

Http501NotImplemented 

501 Not Implemented

Http502BadGateway 

502 Bad Gateway

Http503ServiceUnavailable 

503 Service Unavailable

Http504GatewayTimeout 

504 Gateway Timeout

Http505HTTPVersionNotSupported 

505 HTTP Version Not Supported

Http506VariantAlsoNegotiates 

506 Variant Also Negotiates

Http507InsufficientStorage 

507 Insufficient Storage

Http508LoopDetected 

508 Loop Detected

Http509BandwidthLimitExceeded 

509 Bandwidth Limit Exceeded

Http510NotExtended 

510 Not Extended

Http511NetworkAuthenticationRequired 

511 Network Authentication Required

Http520OriginError 

520 Origin Error

Http521WebServerIsDown 

521 Web server is down

Http522ConnectionTimedOut 

522 Connection timed out

Http523ProxyDeclinedRequest 

523 Proxy Declined Request

Http524aTimeoutOccurred 

524 A timeout occurred

Http598NetworkReadTimeoutError 

598 Network read timeout error

Http599NetworkConnectTimeoutError 

599 Network connect timeout error

HttpStatusCodeUnknown 

Unknown status code

Constructor & Destructor Documentation

◆ HttpResponseLayer() [1/3]

pcpp::HttpResponseLayer::HttpResponseLayer ( 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

◆ HttpResponseLayer() [2/3]

pcpp::HttpResponseLayer::HttpResponseLayer ( HttpVersion  version,
HttpResponseLayer::HttpResponseStatusCode  statusCode,
std::string  statusCodeString = "" 
)

A constructor that allocates a new HTTP response 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]versionHTTP version to be used
[in]statusCodeStatus code to be used
[in]statusCodeStringMost status codes have their default string, e.g 200 is usually "OK", 404 is usually "Not Found", etc. But the user can set a non-default status code string and it will be written in the header first line. Empty string ("") means using the default status code string

◆ HttpResponseLayer() [3/3]

pcpp::HttpResponseLayer::HttpResponseLayer ( const HttpResponseLayer other)

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

Parameters
[in]otherThe instance to copy from

Member Function Documentation

◆ getContentLength()

int pcpp::HttpResponseLayer::getContentLength ( ) const

The length of the body of many HTTP response messages is determined by a HTTP header field called "Content-Length". This method parses this field, extracts its value and return it. If this field doesn't exist the method will return 0

Returns
HTTP response body length determined by "Content-Length" field

◆ getFirstLine()

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

◆ operator=()

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

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

Parameters
[in]otherThe instance to copy from

◆ setContentLength()

HeaderField* pcpp::HttpResponseLayer::setContentLength ( int  contentLength,
const std::string  prevFieldName = "" 
)

The length of the body of many HTTP response messages is determined by a HTTP header field called "Content-Length". This method sets The content-length field value. The method supports several cases:

  • If the "Content-Length" field exists - the method will only replace the existing value with the new value
  • If the "Content-Length" field doesn't exist - the method will create this field and put the value in it. Here are also 2 cases:
    • If prevFieldName is specified - the new "Content-Length" field will be created after it
    • If prevFieldName isn't specified or doesn't exist - the new "Content-Length" field will be created as the last field before end-of-header field
      Parameters
      [in]contentLengthThe content length value to set
      [in]prevFieldNameOptional field, if specified and "Content-Length" field doesn't exist, it will be created after it
      Returns
      A pointer to the "Content-Length" field, or NULL if creation failed for some reason

◆ toString()

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

Implements pcpp::Layer.