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;
104 static std::vector<FieldDescriptor>
all()
131 HttpMessage(
const HttpMessage& other) : TextBasedProtocolMessage(other)
133 HttpMessage& operator=(
const HttpMessage& other)
135 TextBasedProtocolMessage::operator=(other);
140 char getHeaderFieldNameValueSeparator()
const override
144 bool spacesAllowedBetweenHeaderFieldNameAndValue()
const override
149 void serializeHeader(ObjectScope& serializer)
const;
244 static std::vector<FieldDescriptor>
all()
248 std::copy(extra.begin(), extra.end(), std::back_inserter(result));
467 HttpStatus2xxCodeUnknown = 900002,
468 HttpStatus3xxCodeUnknown = 900003,
469 HttpStatus4xxCodeUnknown = 900004,
470 HttpStatus5xxCodeUnknown = 900005,
471 HttpStatusCodeUnknown = 999999,
494 operator Value()
const
499 explicit operator bool()
const =
delete;
504 return std::to_string(m_Value);
510 return static_cast<int>(m_Value);
519 return m_Value > 599;
523 Value m_Value = HttpStatusCodeUnknown;
524 std::string m_CustomizedMessage;
564 const std::
string& statusCodeString);
623 static std::vector<FieldDescriptor>
all()
628 std::copy(extra.begin(), extra.end(), std::back_inserter(result));
709 return m_FirstLineEndOffset;
730 void setMessage(
const std::string& message)
734 virtual const char* what()
const noexcept
736 return m_Message.c_str();
740 std::string m_Message;
746 const std::string& uri =
"/");
755 int m_FirstLineEndOffset;
829 return m_FirstLineEndOffset;
851 void setMessage(
const std::string& message)
855 virtual const char* what()
const noexcept
857 return m_Message.c_str();
861 std::string m_Message;
872 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:726
Definition: HttpLayer.h:664
bool setMethod(HttpRequestLayer::HttpMethod newMethod)
int getSize() const
Definition: HttpLayer.h:707
HttpRequestLayer::HttpMethod getMethod() const
Definition: HttpLayer.h:669
bool isComplete() const
Definition: HttpLayer.h:716
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:690
Definition: HttpLayer.h:166
void serializeLayer(ObjectScope &serializer) const override
HttpRequestLayer & operator=(const HttpRequestLayer &other)
HttpMethod
HTTP request methods.
Definition: HttpLayer.h:172
@ HttpDELETE
DELETE.
Definition: HttpLayer.h:182
@ HttpCONNECT
CONNECT.
Definition: HttpLayer.h:188
@ HttpPOST
POST.
Definition: HttpLayer.h:178
@ HttpMethodUnknown
Unknown HTTP method.
Definition: HttpLayer.h:192
@ HttpTRACE
TRACE.
Definition: HttpLayer.h:184
@ HttpOPTIONS
OPTIONS.
Definition: HttpLayer.h:186
@ HttpHEAD
HEAD.
Definition: HttpLayer.h:176
@ HttpPATCH
PATCH.
Definition: HttpLayer.h:190
@ HttpGET
GET.
Definition: HttpLayer.h:174
@ HttpPUT
PUT.
Definition: HttpLayer.h:180
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:223
Definition: HttpLayer.h:847
Definition: HttpLayer.h:772
int getStatusCodeAsInt() const
bool isComplete() const
Definition: HttpLayer.h:836
HttpVersion getVersion() const
Definition: HttpLayer.h:804
static HttpVersion parseVersion(const char *data, size_t dataLen)
HttpResponseStatusCode getStatusCode() const
Definition: HttpLayer.h:777
std::string getStatusCodeString() const
bool setStatusCode(const HttpResponseStatusCode &newStatusCode, const std::string &statusCodeString)
void setVersion(HttpVersion newVersion)
int getSize() const
Definition: HttpLayer.h:827
static HttpResponseStatusCode parseStatusCode(const char *data, size_t dataLen)
Definition: HttpLayer.h:540
std::string toString() const override
HttpResponseLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
HttpResponseFirstLine * getFirstLine() const
Definition: HttpLayer.h:586
HeaderField * setContentLength(int contentLength, const std::string &prevFieldName="")
int getContentLength() const
void serializeLayer(ObjectScope &serializer) const override
The enum wrapper class of HTTP response status codes.
Definition: HttpLayer.h:276
int toInt() const
get status code number as int
Definition: HttpLayer.h:508
bool isUnsupportedCode() const
Definition: HttpLayer.h:517
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:502
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:280
@ Http507InsufficientStorage
507 Insufficient Storage
Definition: HttpLayer.h:438
@ Http301MovedPermanently
301 Moved Permanently
Definition: HttpLayer.h:317
@ Http306SwitchProxy
306 Switch Proxy
Definition: HttpLayer.h:327
@ Http499
499 (various messages)
Definition: HttpLayer.h:421
@ Http599NetworkConnectTimeoutError
599 Network connect timeout error
Definition: HttpLayer.h:462
@ Http410Gone
410 Gone
Definition: HttpLayer.h:355
@ Http100Continue
100 Continue
Definition: HttpLayer.h:282
@ Http502BadGateway
502 Bad Gateway
Definition: HttpLayer.h:428
@ Http411LengthRequired
411 Length Required
Definition: HttpLayer.h:357
@ Http407ProxyAuthenticationRequired
407 Proxy Authentication Required
Definition: HttpLayer.h:349
@ Http308PermanentRedirect
308 Permanent Redirect,
Definition: HttpLayer.h:331
@ Http205ResetContent
205 Reset Content
Definition: HttpLayer.h:302
@ Http300MultipleChoices
227-299 Unassigned
Definition: HttpLayer.h:315
@ Http402PaymentRequired
402 Payment Required
Definition: HttpLayer.h:339
@ Http207MultiStatus
207 Multi-Status
Definition: HttpLayer.h:306
@ Http420
420 (various messages)
Definition: HttpLayer.h:375
@ Http400BadRequest
309-399 Unassigned
Definition: HttpLayer.h:335
@ Http509BandwidthLimitExceeded
509 Bandwidth Limit Exceeded
Definition: HttpLayer.h:442
@ Http426UpgradeRequired
426 Upgrade Required
Definition: HttpLayer.h:387
@ Http494RequestHeaderTooLarge
Definition: HttpLayer.h:411
@ Http511NetworkAuthenticationRequired
511 Network Authentication Required
Definition: HttpLayer.h:446
@ Http598NetworkReadTimeoutError
Definition: HttpLayer.h:460
@ Http501NotImplemented
501 Not Implemented
Definition: HttpLayer.h:426
@ Http523ProxyDeclinedRequest
523 Proxy Declined Request
Definition: HttpLayer.h:455
@ Http421MisdirectedRequest
421 Misdirected Request
Definition: HttpLayer.h:377
@ Http404NotFound
404 Not Found
Definition: HttpLayer.h:343
@ Http418ImATeapot
418 I'm a teapot
Definition: HttpLayer.h:371
@ Http305UseProxy
305 Use Proxy
Definition: HttpLayer.h:325
@ Http226IMUsed
Definition: HttpLayer.h:311
@ Http498TokenExpiredInvalid
498 Token expired/invalid
Definition: HttpLayer.h:419
@ Http416RequestedRangeNotSatisfiable
416 Requested Range Not Satisfiable
Definition: HttpLayer.h:367
@ Http524aTimeoutOccurred
524 A timeout occurred
Definition: HttpLayer.h:457
@ Http444NoResponse
Definition: HttpLayer.h:401
@ Http414RequestURITooLong
414 Request-URI Too Long
Definition: HttpLayer.h:363
@ Http425TooEarly
425 Too Early
Definition: HttpLayer.h:385
@ Http401Unauthorized
401 Unauthorized
Definition: HttpLayer.h:337
@ Http429TooManyRequests
429 Too Many Requests
Definition: HttpLayer.h:392
@ Http450BlockedByWindowsParentalControls
450 Blocked by Windows Parental Controls
Definition: HttpLayer.h:406
@ Http204NoContent
204 No Content
Definition: HttpLayer.h:300
@ Http508LoopDetected
508 Loop Detected
Definition: HttpLayer.h:440
@ Http510NotExtended
510 Not Extended
Definition: HttpLayer.h:444
@ Http403Forbidden
403 Forbidden
Definition: HttpLayer.h:341
@ Http408RequestTimeout
408 Request Timeout
Definition: HttpLayer.h:351
@ Http440LoginTimeout
Definition: HttpLayer.h:398
@ Http500InternalServerError
500 Internal Server Error
Definition: HttpLayer.h:424
@ Http505HTTPVersionNotSupported
505 HTTP Version Not Supported
Definition: HttpLayer.h:434
@ Http206PartialContent
206 Partial Content
Definition: HttpLayer.h:304
@ Http520OriginError
Definition: HttpLayer.h:449
@ Http302
302 (various messages)
Definition: HttpLayer.h:319
@ Http409Conflict
409 Conflict
Definition: HttpLayer.h:353
@ Http419AuthenticationTimeout
419 Authentication Timeout
Definition: HttpLayer.h:373
@ Http406NotAcceptable
406 Not Acceptable
Definition: HttpLayer.h:347
@ Http451
451 (various messages)
Definition: HttpLayer.h:408
@ Http496NoCert
496 No Cert
Definition: HttpLayer.h:415
@ Http103EarlyHints
103 Early Hints
Definition: HttpLayer.h:288
@ Http202Accepted
202 Accepted
Definition: HttpLayer.h:296
@ Http522ConnectionTimedOut
522 Connection timed out
Definition: HttpLayer.h:453
@ Http203NonAuthoritativeInformation
203 Non-Authoritative Information
Definition: HttpLayer.h:298
@ Http304NotModified
304 Not Modified
Definition: HttpLayer.h:323
@ Http201Created
201 Created
Definition: HttpLayer.h:294
@ Http101SwitchingProtocols
101 Switching Protocols
Definition: HttpLayer.h:284
@ Http413RequestEntityTooLarge
413 RequestEntity Too Large
Definition: HttpLayer.h:361
@ Http495CertError
495 Cert Error
Definition: HttpLayer.h:413
@ Http497HTTPtoHTTPS
497 HTTP to HTTPS
Definition: HttpLayer.h:417
@ Http200OK
104-199 Unassigned
Definition: HttpLayer.h:292
@ Http431RequestHeaderFieldsTooLarge
Definition: HttpLayer.h:395
@ Http405MethodNotAllowed
405 Method Not Allowed
Definition: HttpLayer.h:345
@ Http449RetryWith
Definition: HttpLayer.h:404
@ Http506VariantAlsoNegotiates
506 Variant Also Negotiates
Definition: HttpLayer.h:436
@ Http503ServiceUnavailable
503 Service Unavailable
Definition: HttpLayer.h:430
@ Http102Processing
102 Processing
Definition: HttpLayer.h:286
@ HttpStatus1xxCodeUnknown
Unknown status code.
Definition: HttpLayer.h:466
@ Http521WebServerIsDown
521 Web server is down
Definition: HttpLayer.h:451
@ Http415UnsupportedMediaType
415 Unsupported Media Type
Definition: HttpLayer.h:365
@ Http504GatewayTimeout
504 Gateway Timeout
Definition: HttpLayer.h:432
@ Http412PreconditionFailed
412 Precondition Failed
Definition: HttpLayer.h:359
@ Http417ExpectationFailed
417 Expectation Failed
Definition: HttpLayer.h:369
@ Http428PreconditionRequired
Definition: HttpLayer.h:390
@ Http303SeeOther
303 See Other
Definition: HttpLayer.h:321
@ Http307TemporaryRedirect
307 Temporary Redirect
Definition: HttpLayer.h:329
@ Http424FailedDependency
424 Failed Dependency
Definition: HttpLayer.h:383
@ Http422UnprocessableEntity
422 Unprocessable Entity
Definition: HttpLayer.h:379
@ Http423Locked
423 Locked
Definition: HttpLayer.h:381
@ Http208AlreadyReported
208 Already Reported
Definition: HttpLayer.h:308
HttpResponseStatusCode(Value statusCode)
Construct HttpResponseStatusCode from Value enum.
Definition: HttpLayer.h:480
Definition: Serializers.h:230
Definition: TextBasedProtocol.h:105
uint8_t ProtocolType
Definition: ProtocolType.h:38
The main namespace for the PcapPlusPlus lib.
Definition: AssertionUtils.h:19
OsiModelLayer
An enum representing OSI model layers.
Definition: ProtocolType.h:430
@ PCPP_DEPRECATED
Deprecated typo, use OsiModelSessionLayer instead.
Definition: ProtocolType.h:442
@ OsiModelApplicationLayer
Application layer (layer 7)
Definition: ProtocolType.h:446
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
Definition: Serializers.h:18
Fields shared by HttpRequestLayer and HttpResponseLayer. They're written after the first line fields,...
Definition: HttpLayer.h:96
static const FieldDescriptor HeaderFields
Field descriptor for the array of HTTP header fields, in the order they appear in the message....
Definition: HttpLayer.h:122
static const FieldDescriptor HeaderComplete
Field descriptor for whether the HTTP header is complete (i.e. ends with an empty line) or is partial...
Definition: HttpLayer.h:118
Fields written by HttpRequestLayer's serializeLayer(), in addition to HttpMessage::SerializedFields.
Definition: HttpLayer.h:242
static const FieldDescriptor Method
Field descriptor for the HTTP method, written as a string (for example "GET"), or "Unknown" if the me...
Definition: HttpLayer.h:254
static const FieldDescriptor Version
Field descriptor for the HTTP version, written as a string (for example "HTTP/1.1"),...
Definition: HttpLayer.h:261
static const FieldDescriptor Uri
Field descriptor for the request URI, written as a string.
Definition: HttpLayer.h:257
static std::vector< FieldDescriptor > all()
Definition: HttpLayer.h:244
Fields written by HttpResponseLayer's serializeLayer(), in addition to HttpMessage::SerializedFields.
Definition: HttpLayer.h:621
static const FieldDescriptor StatusCodeDescription
Field descriptor for the status code string, written as a string (see HttpResponseFirstLine::getStatu...
Definition: HttpLayer.h:642
static const FieldDescriptor Version
Field descriptor for the HTTP version, written as a string (for example "HTTP/1.1"),...
Definition: HttpLayer.h:634
static const FieldDescriptor StatusCode
Field descriptor for the status code, written as a number (for example 200).
Definition: HttpLayer.h:637
static std::vector< FieldDescriptor > all()
Definition: HttpLayer.h:623
static std::vector< FieldDescriptor > all()
Definition: Layer.h:214
Definition: Serializers.h:49
ObjectFieldDescriptor(uint16_t fieldId, std::string fieldName)
Definition: Serializers.h:53