35 #define PCPP_HTTP_HOST_FIELD "Host"
37 #define PCPP_HTTP_CONNECTION_FIELD "Connection"
39 #define PCPP_HTTP_USER_AGENT_FIELD "User-Agent"
41 #define PCPP_HTTP_REFERER_FIELD "Referer"
43 #define PCPP_HTTP_ACCEPT_FIELD "Accept"
45 #define PCPP_HTTP_ACCEPT_ENCODING_FIELD "Accept-Encoding"
47 #define PCPP_HTTP_ACCEPT_LANGUAGE_FIELD "Accept-Language"
49 #define PCPP_HTTP_COOKIE_FIELD "Cookie"
51 #define PCPP_HTTP_CONTENT_LENGTH_FIELD "Content-Length"
53 #define PCPP_HTTP_CONTENT_ENCODING_FIELD "Content-Encoding"
55 #define PCPP_HTTP_CONTENT_TYPE_FIELD "Content-Type"
57 #define PCPP_HTTP_TRANSFER_ENCODING_FIELD "Transfer-Encoding"
59 #define PCPP_HTTP_SERVER_FIELD "Server"
63 class HttpRequestFirstLine;
64 class HttpResponseFirstLine;
86 return port == 80 || port == 8080;
94 const std::string& fieldValue);
106 HttpMessage() : TextBasedProtocolMessage()
108 HttpMessage(
const HttpMessage& other) : TextBasedProtocolMessage(other)
110 HttpMessage& operator=(
const HttpMessage& other)
112 TextBasedProtocolMessage::operator=(other);
117 char getHeaderFieldNameValueSeparator()
const
121 bool spacesAllowedBetweenHeaderFieldNameAndValue()
const
431 HttpStatus2xxCodeUnknown = 900002,
432 HttpStatus3xxCodeUnknown = 900003,
433 HttpStatus4xxCodeUnknown = 900004,
434 HttpStatus5xxCodeUnknown = 900005,
435 HttpStatusCodeUnknown = 999999,
464 operator Value()
const
469 explicit operator bool()
const =
delete;
476 return std::to_string(m_Value);
484 return static_cast<int>(m_Value);
497 return m_Value > 599;
501 Value m_Value = HttpStatusCodeUnknown;
502 std::string m_CustomizedMessage;
545 PCPP_DEPRECATED(
"Use other constructors instead")
547 const std::
string& statusCodeString);
690 return m_FirstLineEndOffset;
715 void setMessage(
const std::string& message)
719 virtual const char* what()
const noexcept
721 return m_Message.c_str();
725 std::string m_Message;
731 const std::string& uri =
"/");
740 int m_FirstLineEndOffset;
790 PCPP_DEPRECATED(
"Use the other overload instead")
836 return m_FirstLineEndOffset;
862 void setMessage(
const std::string& message)
866 virtual const char* what()
const noexcept
868 return m_Message.c_str();
872 std::string m_Message;
883 int m_FirstLineEndOffset;
Definition: HttpLayer.h:74
virtual HeaderField * addField(const std::string &fieldName, const std::string &fieldValue)
virtual HeaderField * insertField(HeaderField *prevField, const HeaderField &newField)
OsiModelLayer getOsiModelLayer() const
Definition: HttpLayer.h:97
virtual HeaderField * addField(const HeaderField &newField)
static bool isHttpPort(uint16_t port)
Definition: HttpLayer.h:84
virtual HeaderField * insertField(HeaderField *prevField, const std::string &fieldName, const std::string &fieldValue)
Definition: HttpLayer.h:711
Definition: HttpLayer.h:629
bool setMethod(HttpRequestLayer::HttpMethod newMethod)
int getSize() const
Definition: HttpLayer.h:688
HttpRequestLayer::HttpMethod getMethod() const
Definition: HttpLayer.h:636
bool isComplete() const
Definition: HttpLayer.h:699
bool setUri(std::string newUri)
std::string getUri() const
static HttpRequestLayer::HttpMethod parseMethod(const char *data, size_t dataLen)
void setVersion(HttpVersion newVersion)
HttpVersion getVersion() const
Definition: HttpLayer.h:665
Definition: HttpLayer.h:142
HttpRequestLayer & operator=(const HttpRequestLayer &other)
HttpMethod
Definition: HttpLayer.h:150
@ HttpDELETE
Definition: HttpLayer.h:160
@ HttpCONNECT
Definition: HttpLayer.h:166
@ HttpPOST
Definition: HttpLayer.h:156
@ HttpMethodUnknown
Definition: HttpLayer.h:170
@ HttpTRACE
Definition: HttpLayer.h:162
@ HttpOPTIONS
Definition: HttpLayer.h:164
@ HttpHEAD
Definition: HttpLayer.h:154
@ HttpPATCH
Definition: HttpLayer.h:168
@ HttpGET
Definition: HttpLayer.h:152
@ HttpPUT
Definition: HttpLayer.h:158
std::string toString() const
HttpRequestLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
HttpRequestLayer(const HttpRequestLayer &other)
HttpRequestLayer(HttpMethod method, const std::string &uri, HttpVersion version)
std::string getUrl() const
HttpRequestFirstLine * getFirstLine() const
Definition: HttpLayer.h:210
Definition: HttpLayer.h:858
Definition: HttpLayer.h:759
int getStatusCodeAsInt() const
bool isComplete() const
Definition: HttpLayer.h:845
HttpVersion getVersion() const
Definition: HttpLayer.h:803
static HttpVersion parseVersion(const char *data, size_t dataLen)
HttpResponseStatusCode getStatusCode() const
Definition: HttpLayer.h:766
std::string getStatusCodeString() const
bool setStatusCode(const HttpResponseStatusCode &newStatusCode, const std::string &statusCodeString)
void setVersion(HttpVersion newVersion)
int getSize() const
Definition: HttpLayer.h:834
static HttpResponseStatusCode parseStatusCode(const char *data, size_t dataLen)
Definition: HttpLayer.h:520
HttpResponseLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
HttpResponseFirstLine * getFirstLine() const
Definition: HttpLayer.h:577
std::string toString() const
HeaderField * setContentLength(int contentLength, const std::string &prevFieldName="")
int getContentLength() const
The enum wrapper class of HTTP response status codes.
Definition: HttpLayer.h:238
int toInt() const
get status code number as int
Definition: HttpLayer.h:482
bool isUnsupportedCode() const
Definition: HttpLayer.h:495
HttpResponseStatusCode(const int &statusCodeNumber, const std::string &statusMessage="")
Construct HttpResponseStatusCode from the code number and the customized message.
std::string toString() const
get status code number as string
Definition: HttpLayer.h:474
HttpResponseStatusCode(const Value &statusCode, const std::string &statusMessage)
Construct HttpResponseStatusCode from Value enum and the customized message.
std::string getMessage() const
get status code message, e.g. "OK", "Not Found"
Value
Define enum types and the corresponding int values.
Definition: HttpLayer.h:244
@ Http507InsufficientStorage
Definition: HttpLayer.h:402
@ Http301MovedPermanently
Definition: HttpLayer.h:281
@ Http306SwitchProxy
Definition: HttpLayer.h:291
@ Http499
Definition: HttpLayer.h:385
@ Http599NetworkConnectTimeoutError
Definition: HttpLayer.h:426
@ Http410Gone
Definition: HttpLayer.h:319
@ Http100Continue
Definition: HttpLayer.h:246
@ Http502BadGateway
Definition: HttpLayer.h:392
@ Http411LengthRequired
Definition: HttpLayer.h:321
@ Http407ProxyAuthenticationRequired
Definition: HttpLayer.h:313
@ Http308PermanentRedirect
Definition: HttpLayer.h:295
@ Http205ResetContent
Definition: HttpLayer.h:266
@ Http300MultipleChoices
Definition: HttpLayer.h:279
@ Http402PaymentRequired
Definition: HttpLayer.h:303
@ Http207MultiStatus
Definition: HttpLayer.h:270
@ Http420
Definition: HttpLayer.h:339
@ Http400BadRequest
Definition: HttpLayer.h:299
@ Http509BandwidthLimitExceeded
Definition: HttpLayer.h:406
@ Http426UpgradeRequired
Definition: HttpLayer.h:351
@ Http494RequestHeaderTooLarge
Definition: HttpLayer.h:375
@ Http511NetworkAuthenticationRequired
Definition: HttpLayer.h:410
@ Http598NetworkReadTimeoutError
Definition: HttpLayer.h:424
@ Http501NotImplemented
Definition: HttpLayer.h:390
@ Http523ProxyDeclinedRequest
Definition: HttpLayer.h:419
@ Http421MisdirectedRequest
Definition: HttpLayer.h:341
@ Http404NotFound
Definition: HttpLayer.h:307
@ Http418ImATeapot
Definition: HttpLayer.h:335
@ Http305UseProxy
Definition: HttpLayer.h:289
@ Http226IMUsed
Definition: HttpLayer.h:275
@ Http498TokenExpiredInvalid
Definition: HttpLayer.h:383
@ Http416RequestedRangeNotSatisfiable
Definition: HttpLayer.h:331
@ Http524aTimeoutOccurred
Definition: HttpLayer.h:421
@ Http444NoResponse
Definition: HttpLayer.h:365
@ Http414RequestURITooLong
Definition: HttpLayer.h:327
@ Http425TooEarly
Definition: HttpLayer.h:349
@ Http401Unauthorized
Definition: HttpLayer.h:301
@ Http429TooManyRequests
Definition: HttpLayer.h:356
@ Http450BlockedByWindowsParentalControls
Definition: HttpLayer.h:370
@ Http204NoContent
Definition: HttpLayer.h:264
@ Http508LoopDetected
Definition: HttpLayer.h:404
@ Http510NotExtended
Definition: HttpLayer.h:408
@ Http403Forbidden
Definition: HttpLayer.h:305
@ Http408RequestTimeout
Definition: HttpLayer.h:315
@ Http440LoginTimeout
Definition: HttpLayer.h:362
@ Http500InternalServerError
Definition: HttpLayer.h:388
@ Http505HTTPVersionNotSupported
Definition: HttpLayer.h:398
@ Http206PartialContent
Definition: HttpLayer.h:268
@ Http520OriginError
Definition: HttpLayer.h:413
@ Http302
Definition: HttpLayer.h:283
@ Http409Conflict
Definition: HttpLayer.h:317
@ Http419AuthenticationTimeout
Definition: HttpLayer.h:337
@ Http406NotAcceptable
Definition: HttpLayer.h:311
@ Http451
Definition: HttpLayer.h:372
@ Http496NoCert
Definition: HttpLayer.h:379
@ Http103EarlyHints
Definition: HttpLayer.h:252
@ Http202Accepted
Definition: HttpLayer.h:260
@ Http522ConnectionTimedOut
Definition: HttpLayer.h:417
@ Http203NonAuthoritativeInformation
Definition: HttpLayer.h:262
@ Http304NotModified
Definition: HttpLayer.h:287
@ Http201Created
Definition: HttpLayer.h:258
@ Http101SwitchingProtocols
Definition: HttpLayer.h:248
@ Http413RequestEntityTooLarge
Definition: HttpLayer.h:325
@ Http495CertError
Definition: HttpLayer.h:377
@ Http497HTTPtoHTTPS
Definition: HttpLayer.h:381
@ Http200OK
Definition: HttpLayer.h:256
@ Http431RequestHeaderFieldsTooLarge
Definition: HttpLayer.h:359
@ Http405MethodNotAllowed
Definition: HttpLayer.h:309
@ Http449RetryWith
Definition: HttpLayer.h:368
@ Http506VariantAlsoNegotiates
Definition: HttpLayer.h:400
@ Http503ServiceUnavailable
Definition: HttpLayer.h:394
@ Http102Processing
Definition: HttpLayer.h:250
@ HttpStatus1xxCodeUnknown
Definition: HttpLayer.h:430
@ Http521WebServerIsDown
Definition: HttpLayer.h:415
@ Http415UnsupportedMediaType
Definition: HttpLayer.h:329
@ Http504GatewayTimeout
Definition: HttpLayer.h:396
@ Http412PreconditionFailed
Definition: HttpLayer.h:323
@ Http417ExpectationFailed
Definition: HttpLayer.h:333
@ Http428PreconditionRequired
Definition: HttpLayer.h:354
@ Http303SeeOther
Definition: HttpLayer.h:285
@ Http307TemporaryRedirect
Definition: HttpLayer.h:293
@ Http424FailedDependency
Definition: HttpLayer.h:347
@ Http422UnprocessableEntity
Definition: HttpLayer.h:343
@ Http423Locked
Definition: HttpLayer.h:345
@ Http208AlreadyReported
Definition: HttpLayer.h:272
HttpResponseStatusCode(Value statusCode)
Construct HttpResponseStatusCode from Value enum.
Definition: HttpLayer.h:446
Definition: TextBasedProtocol.h:123
The main namespace for the PcapPlusPlus lib.
uint8_t ProtocolType
Definition: ProtocolType.h:17
OsiModelLayer
Definition: ProtocolType.h:354
@ OsiModelApplicationLayer
Definition: ProtocolType.h:368
HttpVersion
Definition: HttpLayer.h:21
@ HttpVersionUnknown
Definition: HttpLayer.h:29
@ ZeroDotNine
Definition: HttpLayer.h:23
@ OneDotZero
Definition: HttpLayer.h:25
@ OneDotOne
Definition: HttpLayer.h:27