30 #define PCPP_HTTP_HOST_FIELD "Host"
32 #define PCPP_HTTP_CONNECTION_FIELD "Connection"
34 #define PCPP_HTTP_USER_AGENT_FIELD "User-Agent"
36 #define PCPP_HTTP_REFERER_FIELD "Referer"
38 #define PCPP_HTTP_ACCEPT_FIELD "Accept"
40 #define PCPP_HTTP_ACCEPT_ENCODING_FIELD "Accept-Encoding"
42 #define PCPP_HTTP_ACCEPT_LANGUAGE_FIELD "Accept-Language"
44 #define PCPP_HTTP_COOKIE_FIELD "Cookie"
46 #define PCPP_HTTP_CONTENT_LENGTH_FIELD "Content-Length"
48 #define PCPP_HTTP_CONTENT_ENCODING_FIELD "Content-Encoding"
50 #define PCPP_HTTP_CONTENT_TYPE_FIELD "Content-Type"
52 #define PCPP_HTTP_TRANSFER_ENCODING_FIELD "Transfer-Encoding"
54 #define PCPP_HTTP_SERVER_FIELD "Server"
58 class HttpRequestFirstLine;
59 class HttpResponseFirstLine;
76 return port == 80 || port == 8080;
84 const std::string& fieldValue)
override;
96 HttpMessage() : TextBasedProtocolMessage()
98 HttpMessage(
const HttpMessage& other) : TextBasedProtocolMessage(other)
100 HttpMessage& operator=(
const HttpMessage& other)
102 TextBasedProtocolMessage::operator=(other);
107 char getHeaderFieldNameValueSeparator()
const override
111 bool spacesAllowedBetweenHeaderFieldNameAndValue()
const override
403 HttpStatus2xxCodeUnknown = 900002,
404 HttpStatus3xxCodeUnknown = 900003,
405 HttpStatus4xxCodeUnknown = 900004,
406 HttpStatus5xxCodeUnknown = 900005,
407 HttpStatusCodeUnknown = 999999,
430 operator Value()
const
435 explicit operator bool()
const =
delete;
440 return std::to_string(m_Value);
446 return static_cast<int>(m_Value);
455 return m_Value > 599;
459 Value m_Value = HttpStatusCodeUnknown;
460 std::string m_CustomizedMessage;
498 PCPP_DEPRECATED(
"Use other constructors instead")
500 const std::
string& statusCodeString);
614 return m_FirstLineEndOffset;
635 void setMessage(
const std::string& message)
639 virtual const char* what()
const noexcept
641 return m_Message.c_str();
645 std::string m_Message;
651 const std::string& uri =
"/");
660 int m_FirstLineEndOffset;
700 PCPP_DEPRECATED(
"Use the other overload instead")
734 return m_FirstLineEndOffset;
756 void setMessage(
const std::string& message)
760 virtual const char* what()
const noexcept
762 return m_Message.c_str();
766 std::string m_Message;
777 int m_FirstLineEndOffset;
Definition: HttpLayer.h:67
OsiModelLayer getOsiModelLayer() const override
Definition: HttpLayer.h:87
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:74
HeaderField * insertField(HeaderField *prevField, const HeaderField &newField) override
HeaderField * addField(const std::string &fieldName, const std::string &fieldValue) override
Definition: HttpLayer.h:631
Definition: HttpLayer.h:569
bool setMethod(HttpRequestLayer::HttpMethod newMethod)
int getSize() const
Definition: HttpLayer.h:612
HttpRequestLayer::HttpMethod getMethod() const
Definition: HttpLayer.h:574
bool isComplete() const
Definition: HttpLayer.h:621
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:595
Definition: HttpLayer.h:131
HttpRequestLayer & operator=(const HttpRequestLayer &other)
HttpMethod
HTTP request methods.
Definition: HttpLayer.h:137
@ HttpDELETE
DELETE.
Definition: HttpLayer.h:147
@ HttpCONNECT
CONNECT.
Definition: HttpLayer.h:153
@ HttpPOST
POST.
Definition: HttpLayer.h:143
@ HttpMethodUnknown
Unknown HTTP method.
Definition: HttpLayer.h:157
@ HttpTRACE
TRACE.
Definition: HttpLayer.h:149
@ HttpOPTIONS
OPTIONS.
Definition: HttpLayer.h:151
@ HttpHEAD
HEAD.
Definition: HttpLayer.h:141
@ HttpPATCH
PATCH.
Definition: HttpLayer.h:155
@ HttpGET
GET.
Definition: HttpLayer.h:139
@ HttpPUT
PUT.
Definition: HttpLayer.h:145
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:188
Definition: HttpLayer.h:752
Definition: HttpLayer.h:677
int getStatusCodeAsInt() const
bool isComplete() const
Definition: HttpLayer.h:741
HttpVersion getVersion() const
Definition: HttpLayer.h:709
static HttpVersion parseVersion(const char *data, size_t dataLen)
HttpResponseStatusCode getStatusCode() const
Definition: HttpLayer.h:682
std::string getStatusCodeString() const
bool setStatusCode(const HttpResponseStatusCode &newStatusCode, const std::string &statusCodeString)
void setVersion(HttpVersion newVersion)
int getSize() const
Definition: HttpLayer.h:732
static HttpResponseStatusCode parseStatusCode(const char *data, size_t dataLen)
Definition: HttpLayer.h:476
std::string toString() const override
HttpResponseLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
HttpResponseFirstLine * getFirstLine() const
Definition: HttpLayer.h:522
HeaderField * setContentLength(int contentLength, const std::string &prevFieldName="")
int getContentLength() const
The enum wrapper class of HTTP response status codes.
Definition: HttpLayer.h:212
int toInt() const
get status code number as int
Definition: HttpLayer.h:444
bool isUnsupportedCode() const
Definition: HttpLayer.h:453
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:438
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:216
@ Http507InsufficientStorage
507 Insufficient Storage
Definition: HttpLayer.h:374
@ Http301MovedPermanently
301 Moved Permanently
Definition: HttpLayer.h:253
@ Http306SwitchProxy
306 Switch Proxy
Definition: HttpLayer.h:263
@ Http499
499 (various messages)
Definition: HttpLayer.h:357
@ Http599NetworkConnectTimeoutError
599 Network connect timeout error
Definition: HttpLayer.h:398
@ Http410Gone
410 Gone
Definition: HttpLayer.h:291
@ Http100Continue
100 Continue
Definition: HttpLayer.h:218
@ Http502BadGateway
502 Bad Gateway
Definition: HttpLayer.h:364
@ Http411LengthRequired
411 Length Required
Definition: HttpLayer.h:293
@ Http407ProxyAuthenticationRequired
407 Proxy Authentication Required
Definition: HttpLayer.h:285
@ Http308PermanentRedirect
308 Permanent Redirect,
Definition: HttpLayer.h:267
@ Http205ResetContent
205 Reset Content
Definition: HttpLayer.h:238
@ Http300MultipleChoices
227-299 Unassigned
Definition: HttpLayer.h:251
@ Http402PaymentRequired
402 Payment Required
Definition: HttpLayer.h:275
@ Http207MultiStatus
207 Multi-Status
Definition: HttpLayer.h:242
@ Http420
420 (various messages)
Definition: HttpLayer.h:311
@ Http400BadRequest
309-399 Unassigned
Definition: HttpLayer.h:271
@ Http509BandwidthLimitExceeded
509 Bandwidth Limit Exceeded
Definition: HttpLayer.h:378
@ Http426UpgradeRequired
426 Upgrade Required
Definition: HttpLayer.h:323
@ Http494RequestHeaderTooLarge
Definition: HttpLayer.h:347
@ Http511NetworkAuthenticationRequired
511 Network Authentication Required
Definition: HttpLayer.h:382
@ Http598NetworkReadTimeoutError
Definition: HttpLayer.h:396
@ Http501NotImplemented
501 Not Implemented
Definition: HttpLayer.h:362
@ Http523ProxyDeclinedRequest
523 Proxy Declined Request
Definition: HttpLayer.h:391
@ Http421MisdirectedRequest
421 Misdirected Request
Definition: HttpLayer.h:313
@ Http404NotFound
404 Not Found
Definition: HttpLayer.h:279
@ Http418ImATeapot
418 I'm a teapot
Definition: HttpLayer.h:307
@ Http305UseProxy
305 Use Proxy
Definition: HttpLayer.h:261
@ Http226IMUsed
Definition: HttpLayer.h:247
@ Http498TokenExpiredInvalid
498 Token expired/invalid
Definition: HttpLayer.h:355
@ Http416RequestedRangeNotSatisfiable
416 Requested Range Not Satisfiable
Definition: HttpLayer.h:303
@ Http524aTimeoutOccurred
524 A timeout occurred
Definition: HttpLayer.h:393
@ Http444NoResponse
Definition: HttpLayer.h:337
@ Http414RequestURITooLong
414 Request-URI Too Long
Definition: HttpLayer.h:299
@ Http425TooEarly
425 Too Early
Definition: HttpLayer.h:321
@ Http401Unauthorized
401 Unauthorized
Definition: HttpLayer.h:273
@ Http429TooManyRequests
429 Too Many Requests
Definition: HttpLayer.h:328
@ Http450BlockedByWindowsParentalControls
450 Blocked by Windows Parental Controls
Definition: HttpLayer.h:342
@ Http204NoContent
204 No Content
Definition: HttpLayer.h:236
@ Http508LoopDetected
508 Loop Detected
Definition: HttpLayer.h:376
@ Http510NotExtended
510 Not Extended
Definition: HttpLayer.h:380
@ Http403Forbidden
403 Forbidden
Definition: HttpLayer.h:277
@ Http408RequestTimeout
408 Request Timeout
Definition: HttpLayer.h:287
@ Http440LoginTimeout
Definition: HttpLayer.h:334
@ Http500InternalServerError
500 Internal Server Error
Definition: HttpLayer.h:360
@ Http505HTTPVersionNotSupported
505 HTTP Version Not Supported
Definition: HttpLayer.h:370
@ Http206PartialContent
206 Partial Content
Definition: HttpLayer.h:240
@ Http520OriginError
Definition: HttpLayer.h:385
@ Http302
302 (various messages)
Definition: HttpLayer.h:255
@ Http409Conflict
409 Conflict
Definition: HttpLayer.h:289
@ Http419AuthenticationTimeout
419 Authentication Timeout
Definition: HttpLayer.h:309
@ Http406NotAcceptable
406 Not Acceptable
Definition: HttpLayer.h:283
@ Http451
451 (various messages)
Definition: HttpLayer.h:344
@ Http496NoCert
496 No Cert
Definition: HttpLayer.h:351
@ Http103EarlyHints
103 Early Hints
Definition: HttpLayer.h:224
@ Http202Accepted
202 Accepted
Definition: HttpLayer.h:232
@ Http522ConnectionTimedOut
522 Connection timed out
Definition: HttpLayer.h:389
@ Http203NonAuthoritativeInformation
203 Non-Authoritative Information
Definition: HttpLayer.h:234
@ Http304NotModified
304 Not Modified
Definition: HttpLayer.h:259
@ Http201Created
201 Created
Definition: HttpLayer.h:230
@ Http101SwitchingProtocols
101 Switching Protocols
Definition: HttpLayer.h:220
@ Http413RequestEntityTooLarge
413 RequestEntity Too Large
Definition: HttpLayer.h:297
@ Http495CertError
495 Cert Error
Definition: HttpLayer.h:349
@ Http497HTTPtoHTTPS
497 HTTP to HTTPS
Definition: HttpLayer.h:353
@ Http200OK
104-199 Unassigned
Definition: HttpLayer.h:228
@ Http431RequestHeaderFieldsTooLarge
Definition: HttpLayer.h:331
@ Http405MethodNotAllowed
405 Method Not Allowed
Definition: HttpLayer.h:281
@ Http449RetryWith
Definition: HttpLayer.h:340
@ Http506VariantAlsoNegotiates
506 Variant Also Negotiates
Definition: HttpLayer.h:372
@ Http503ServiceUnavailable
503 Service Unavailable
Definition: HttpLayer.h:366
@ Http102Processing
102 Processing
Definition: HttpLayer.h:222
@ HttpStatus1xxCodeUnknown
Unknown status code.
Definition: HttpLayer.h:402
@ Http521WebServerIsDown
521 Web server is down
Definition: HttpLayer.h:387
@ Http415UnsupportedMediaType
415 Unsupported Media Type
Definition: HttpLayer.h:301
@ Http504GatewayTimeout
504 Gateway Timeout
Definition: HttpLayer.h:368
@ Http412PreconditionFailed
412 Precondition Failed
Definition: HttpLayer.h:295
@ Http417ExpectationFailed
417 Expectation Failed
Definition: HttpLayer.h:305
@ Http428PreconditionRequired
Definition: HttpLayer.h:326
@ Http303SeeOther
303 See Other
Definition: HttpLayer.h:257
@ Http307TemporaryRedirect
307 Temporary Redirect
Definition: HttpLayer.h:265
@ Http424FailedDependency
424 Failed Dependency
Definition: HttpLayer.h:319
@ Http422UnprocessableEntity
422 Unprocessable Entity
Definition: HttpLayer.h:315
@ Http423Locked
423 Locked
Definition: HttpLayer.h:317
@ Http208AlreadyReported
208 Already Reported
Definition: HttpLayer.h:244
HttpResponseStatusCode(Value statusCode)
Construct HttpResponseStatusCode from Value enum.
Definition: HttpLayer.h:416
Definition: TextBasedProtocol.h:105
The main namespace for the PcapPlusPlus lib.
uint8_t ProtocolType
Definition: ProtocolType.h:13
OsiModelLayer
An enum representing OSI model layers.
Definition: ProtocolType.h:225
@ OsiModelApplicationLayer
Application layer (layer 7)
Definition: ProtocolType.h:239
HttpVersion
An enum for HTTP version.
Definition: HttpLayer.h:16
@ HttpVersionUnknown
Unknown HTTP version.
Definition: HttpLayer.h:24
@ ZeroDotNine
HTTP/0.9.
Definition: HttpLayer.h:18
@ OneDotZero
HTTP/1.0.
Definition: HttpLayer.h:20
@ OneDotOne
HTTP/1.1.
Definition: HttpLayer.h:22