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;
85 return port == 80 || port == 8080;
93 const std::string& fieldValue)
override;
105 HttpMessage() : TextBasedProtocolMessage()
107 HttpMessage(
const HttpMessage& other) : TextBasedProtocolMessage(other)
109 HttpMessage& operator=(
const HttpMessage& other)
111 TextBasedProtocolMessage::operator=(other);
116 char getHeaderFieldNameValueSeparator()
const override
120 bool spacesAllowedBetweenHeaderFieldNameAndValue()
const override
430 HttpStatus2xxCodeUnknown = 900002,
431 HttpStatus3xxCodeUnknown = 900003,
432 HttpStatus4xxCodeUnknown = 900004,
433 HttpStatus5xxCodeUnknown = 900005,
434 HttpStatusCodeUnknown = 999999,
463 operator Value()
const
468 explicit operator bool()
const =
delete;
475 return std::to_string(m_Value);
483 return static_cast<int>(m_Value);
496 return m_Value > 599;
500 Value m_Value = HttpStatusCodeUnknown;
501 std::string m_CustomizedMessage;
544 PCPP_DEPRECATED(
"Use other constructors instead")
546 const std::
string& statusCodeString);
689 return m_FirstLineEndOffset;
714 void setMessage(
const std::string& message)
718 virtual const char* what()
const noexcept
720 return m_Message.c_str();
724 std::string m_Message;
730 const std::string& uri =
"/");
739 int m_FirstLineEndOffset;
789 PCPP_DEPRECATED(
"Use the other overload instead")
835 return m_FirstLineEndOffset;
861 void setMessage(
const std::string& message)
865 virtual const char* what()
const noexcept
867 return m_Message.c_str();
871 std::string m_Message;
882 int m_FirstLineEndOffset;
Definition: HttpLayer.h:74
OsiModelLayer getOsiModelLayer() const override
Definition: HttpLayer.h:96
HeaderField * insertField(HeaderField *prevField, const std::string &fieldName, const std::string &fieldValue) override
HeaderField * addField(const HeaderField &newField) override
static bool isHttpPort(uint16_t port)
Definition: HttpLayer.h:83
HeaderField * insertField(HeaderField *prevField, const HeaderField &newField) override
HeaderField * addField(const std::string &fieldName, const std::string &fieldValue) override
Definition: HttpLayer.h:710
Definition: HttpLayer.h:628
bool setMethod(HttpRequestLayer::HttpMethod newMethod)
int getSize() const
Definition: HttpLayer.h:687
HttpRequestLayer::HttpMethod getMethod() const
Definition: HttpLayer.h:635
bool isComplete() const
Definition: HttpLayer.h:698
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:664
Definition: HttpLayer.h:141
HttpRequestLayer & operator=(const HttpRequestLayer &other)
HttpMethod
Definition: HttpLayer.h:149
@ HttpDELETE
Definition: HttpLayer.h:159
@ HttpCONNECT
Definition: HttpLayer.h:165
@ HttpPOST
Definition: HttpLayer.h:155
@ HttpMethodUnknown
Definition: HttpLayer.h:169
@ HttpTRACE
Definition: HttpLayer.h:161
@ HttpOPTIONS
Definition: HttpLayer.h:163
@ HttpHEAD
Definition: HttpLayer.h:153
@ HttpPATCH
Definition: HttpLayer.h:167
@ HttpGET
Definition: HttpLayer.h:151
@ HttpPUT
Definition: HttpLayer.h:157
HttpRequestLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
HttpRequestLayer(const HttpRequestLayer &other)
std::string toString() const override
HttpRequestLayer(HttpMethod method, const std::string &uri, HttpVersion version)
std::string getUrl() const
HttpRequestFirstLine * getFirstLine() const
Definition: HttpLayer.h:209
Definition: HttpLayer.h:857
Definition: HttpLayer.h:758
int getStatusCodeAsInt() const
bool isComplete() const
Definition: HttpLayer.h:844
HttpVersion getVersion() const
Definition: HttpLayer.h:802
static HttpVersion parseVersion(const char *data, size_t dataLen)
HttpResponseStatusCode getStatusCode() const
Definition: HttpLayer.h:765
std::string getStatusCodeString() const
bool setStatusCode(const HttpResponseStatusCode &newStatusCode, const std::string &statusCodeString)
void setVersion(HttpVersion newVersion)
int getSize() const
Definition: HttpLayer.h:833
static HttpResponseStatusCode parseStatusCode(const char *data, size_t dataLen)
Definition: HttpLayer.h:519
std::string toString() const override
HttpResponseLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
HttpResponseFirstLine * getFirstLine() const
Definition: HttpLayer.h:576
HeaderField * setContentLength(int contentLength, const std::string &prevFieldName="")
int getContentLength() const
The enum wrapper class of HTTP response status codes.
Definition: HttpLayer.h:237
int toInt() const
get status code number as int
Definition: HttpLayer.h:481
bool isUnsupportedCode() const
Definition: HttpLayer.h:494
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:473
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:243
@ Http507InsufficientStorage
Definition: HttpLayer.h:401
@ Http301MovedPermanently
Definition: HttpLayer.h:280
@ Http306SwitchProxy
Definition: HttpLayer.h:290
@ Http499
Definition: HttpLayer.h:384
@ Http599NetworkConnectTimeoutError
Definition: HttpLayer.h:425
@ Http410Gone
Definition: HttpLayer.h:318
@ Http100Continue
Definition: HttpLayer.h:245
@ Http502BadGateway
Definition: HttpLayer.h:391
@ Http411LengthRequired
Definition: HttpLayer.h:320
@ Http407ProxyAuthenticationRequired
Definition: HttpLayer.h:312
@ Http308PermanentRedirect
Definition: HttpLayer.h:294
@ Http205ResetContent
Definition: HttpLayer.h:265
@ Http300MultipleChoices
Definition: HttpLayer.h:278
@ Http402PaymentRequired
Definition: HttpLayer.h:302
@ Http207MultiStatus
Definition: HttpLayer.h:269
@ Http420
Definition: HttpLayer.h:338
@ Http400BadRequest
Definition: HttpLayer.h:298
@ Http509BandwidthLimitExceeded
Definition: HttpLayer.h:405
@ Http426UpgradeRequired
Definition: HttpLayer.h:350
@ Http494RequestHeaderTooLarge
Definition: HttpLayer.h:374
@ Http511NetworkAuthenticationRequired
Definition: HttpLayer.h:409
@ Http598NetworkReadTimeoutError
Definition: HttpLayer.h:423
@ Http501NotImplemented
Definition: HttpLayer.h:389
@ Http523ProxyDeclinedRequest
Definition: HttpLayer.h:418
@ Http421MisdirectedRequest
Definition: HttpLayer.h:340
@ Http404NotFound
Definition: HttpLayer.h:306
@ Http418ImATeapot
Definition: HttpLayer.h:334
@ Http305UseProxy
Definition: HttpLayer.h:288
@ Http226IMUsed
Definition: HttpLayer.h:274
@ Http498TokenExpiredInvalid
Definition: HttpLayer.h:382
@ Http416RequestedRangeNotSatisfiable
Definition: HttpLayer.h:330
@ Http524aTimeoutOccurred
Definition: HttpLayer.h:420
@ Http444NoResponse
Definition: HttpLayer.h:364
@ Http414RequestURITooLong
Definition: HttpLayer.h:326
@ Http425TooEarly
Definition: HttpLayer.h:348
@ Http401Unauthorized
Definition: HttpLayer.h:300
@ Http429TooManyRequests
Definition: HttpLayer.h:355
@ Http450BlockedByWindowsParentalControls
Definition: HttpLayer.h:369
@ Http204NoContent
Definition: HttpLayer.h:263
@ Http508LoopDetected
Definition: HttpLayer.h:403
@ Http510NotExtended
Definition: HttpLayer.h:407
@ Http403Forbidden
Definition: HttpLayer.h:304
@ Http408RequestTimeout
Definition: HttpLayer.h:314
@ Http440LoginTimeout
Definition: HttpLayer.h:361
@ Http500InternalServerError
Definition: HttpLayer.h:387
@ Http505HTTPVersionNotSupported
Definition: HttpLayer.h:397
@ Http206PartialContent
Definition: HttpLayer.h:267
@ Http520OriginError
Definition: HttpLayer.h:412
@ Http302
Definition: HttpLayer.h:282
@ Http409Conflict
Definition: HttpLayer.h:316
@ Http419AuthenticationTimeout
Definition: HttpLayer.h:336
@ Http406NotAcceptable
Definition: HttpLayer.h:310
@ Http451
Definition: HttpLayer.h:371
@ Http496NoCert
Definition: HttpLayer.h:378
@ Http103EarlyHints
Definition: HttpLayer.h:251
@ Http202Accepted
Definition: HttpLayer.h:259
@ Http522ConnectionTimedOut
Definition: HttpLayer.h:416
@ Http203NonAuthoritativeInformation
Definition: HttpLayer.h:261
@ Http304NotModified
Definition: HttpLayer.h:286
@ Http201Created
Definition: HttpLayer.h:257
@ Http101SwitchingProtocols
Definition: HttpLayer.h:247
@ Http413RequestEntityTooLarge
Definition: HttpLayer.h:324
@ Http495CertError
Definition: HttpLayer.h:376
@ Http497HTTPtoHTTPS
Definition: HttpLayer.h:380
@ Http200OK
Definition: HttpLayer.h:255
@ Http431RequestHeaderFieldsTooLarge
Definition: HttpLayer.h:358
@ Http405MethodNotAllowed
Definition: HttpLayer.h:308
@ Http449RetryWith
Definition: HttpLayer.h:367
@ Http506VariantAlsoNegotiates
Definition: HttpLayer.h:399
@ Http503ServiceUnavailable
Definition: HttpLayer.h:393
@ Http102Processing
Definition: HttpLayer.h:249
@ HttpStatus1xxCodeUnknown
Definition: HttpLayer.h:429
@ Http521WebServerIsDown
Definition: HttpLayer.h:414
@ Http415UnsupportedMediaType
Definition: HttpLayer.h:328
@ Http504GatewayTimeout
Definition: HttpLayer.h:395
@ Http412PreconditionFailed
Definition: HttpLayer.h:322
@ Http417ExpectationFailed
Definition: HttpLayer.h:332
@ Http428PreconditionRequired
Definition: HttpLayer.h:353
@ Http303SeeOther
Definition: HttpLayer.h:284
@ Http307TemporaryRedirect
Definition: HttpLayer.h:292
@ Http424FailedDependency
Definition: HttpLayer.h:346
@ Http422UnprocessableEntity
Definition: HttpLayer.h:342
@ Http423Locked
Definition: HttpLayer.h:344
@ Http208AlreadyReported
Definition: HttpLayer.h:271
HttpResponseStatusCode(Value statusCode)
Construct HttpResponseStatusCode from Value enum.
Definition: HttpLayer.h:445
Definition: TextBasedProtocol.h:123
The main namespace for the PcapPlusPlus lib.
uint8_t ProtocolType
Definition: ProtocolType.h:17
OsiModelLayer
Definition: ProtocolType.h:364
@ OsiModelApplicationLayer
Definition: ProtocolType.h:378
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