1 #ifndef PACKETPP_HTTP_LAYER 2 #define PACKETPP_HTTP_LAYER 8 #ifndef PCPP_DEPRECATED 9 #if defined(__GNUC__) || defined(__clang__) 10 #define PCPP_DEPRECATED __attribute__((deprecated)) 11 #elif defined(_MSC_VER) 12 #define PCPP_DEPRECATED __declspec(deprecated) 14 #pragma message("WARNING: DEPRECATED feature is not implemented for this compiler") 15 #define PCPP_DEPRECATED 46 #define PCPP_HTTP_HOST_FIELD "Host" 48 #define PCPP_HTTP_CONNECTION_FIELD "Connection" 50 #define PCPP_HTTP_USER_AGENT_FIELD "User-Agent" 52 #define PCPP_HTTP_REFERER_FIELD "Referer" 54 #define PCPP_HTTP_ACCEPT_FIELD "Accept" 56 #define PCPP_HTTP_ACCEPT_ENCODING_FIELD "Accept-Encoding" 58 #define PCPP_HTTP_ACCEPT_LANGUAGE_FIELD "Accept-Language" 60 #define PCPP_HTTP_COOKIE_FIELD "Cookie" 62 #define PCPP_HTTP_CONTENT_LENGTH_FIELD "Content-Length" 64 #define PCPP_HTTP_CONTENT_ENCODING_FIELD "Content-Encoding" 66 #define PCPP_HTTP_CONTENT_TYPE_FIELD "Content-Type" 68 #define PCPP_HTTP_TRANSFER_ENCODING_FIELD "Transfer-Encoding" 70 #define PCPP_HTTP_SERVER_FIELD "Server" 76 class HttpRequestFirstLine;
77 class HttpResponseFirstLine;
98 static bool isHttpPort(uint16_t port) {
return port == 80 || port == 8080; }
102 virtual HeaderField*
addField(
const std::string& fieldName,
const std::string& fieldValue);
113 HttpMessage& operator=(
const HttpMessage& other) { TextBasedProtocolMessage::operator=(other);
return *
this; }
116 char getHeaderFieldNameValueSeparator()
const {
return ':'; }
117 bool spacesAllowedBetweenHeaderFieldNameAndValue()
const {
return true; }
212 std::string getUrl()
const;
236 Http100Continue = 100,
238 Http101SwitchingProtocols = 101,
240 Http102Processing = 102,
242 Http103EarlyHints = 103,
248 Http201Created = 201,
250 Http202Accepted = 202,
252 Http203NonAuthoritativeInformation = 203,
254 Http204NoContent = 204,
256 Http205ResetContent = 205,
258 Http206PartialContent = 206,
260 Http207MultiStatus = 207,
262 Http208AlreadyReported = 208,
269 Http300MultipleChoices = 300,
271 Http301MovedPermanently = 301,
275 Http303SeeOther = 303,
277 Http304NotModified = 304,
279 Http305UseProxy = 305,
281 Http306SwitchProxy = 306,
283 Http307TemporaryRedirect = 307,
285 Http308PermanentRedirect = 308,
289 Http400BadRequest = 400,
291 Http401Unauthorized = 401,
293 Http402PaymentRequired = 402,
295 Http403Forbidden = 403,
297 Http404NotFound = 404,
299 Http405MethodNotAllowed = 405,
301 Http406NotAcceptable = 406,
303 Http407ProxyAuthenticationRequired = 407,
305 Http408RequestTimeout = 408,
307 Http409Conflict = 409,
311 Http411LengthRequired = 411,
313 Http412PreconditionFailed = 412,
315 Http413RequestEntityTooLarge = 413,
317 Http414RequestURITooLong = 414,
319 Http415UnsupportedMediaType = 415,
321 Http416RequestedRangeNotSatisfiable = 416,
323 Http417ExpectationFailed = 417,
325 Http418ImATeapot = 418,
327 Http419AuthenticationTimeout = 419,
331 Http421MisdirectedRequest = 421,
333 Http422UnprocessableEntity = 422,
337 Http424FailedDependency = 424,
339 Http425TooEarly = 425,
341 Http426UpgradeRequired = 426,
344 Http428PreconditionRequired = 428,
346 Http429TooManyRequests = 429,
349 Http431RequestHeaderFieldsTooLarge = 431,
352 Http440LoginTimeout = 440,
355 Http444NoResponse = 444,
358 Http449RetryWith = 449,
360 Http450BlockedByWindowsParentalControls = 450,
365 Http494RequestHeaderTooLarge = 494,
367 Http495CertError = 495,
371 Http497HTTPtoHTTPS = 497,
373 Http498TokenExpiredInvalid = 498,
378 Http500InternalServerError = 500,
380 Http501NotImplemented = 501,
382 Http502BadGateway = 502,
384 Http503ServiceUnavailable = 503,
386 Http504GatewayTimeout = 504,
388 Http505HTTPVersionNotSupported = 505,
390 Http506VariantAlsoNegotiates = 506,
392 Http507InsufficientStorage = 507,
394 Http508LoopDetected = 508,
396 Http509BandwidthLimitExceeded = 509,
398 Http510NotExtended = 510,
400 Http511NetworkAuthenticationRequired = 511,
403 Http520OriginError = 520,
405 Http521WebServerIsDown = 521,
407 Http522ConnectionTimedOut = 522,
409 Http523ProxyDeclinedRequest = 523,
411 Http524aTimeoutOccurred = 524,
414 Http598NetworkReadTimeoutError = 598,
416 Http599NetworkConnectTimeoutError = 599,
419 HttpStatus1xxCodeUnknown = 900001,
420 HttpStatus2xxCodeUnknown = 900002,
421 HttpStatus3xxCodeUnknown = 900003,
422 HttpStatus4xxCodeUnknown = 900004,
423 HttpStatus5xxCodeUnknown = 900005,
424 HttpStatusCodeUnknown = 999999,
451 operator Value()
const {
return m_Value; }
453 explicit operator bool()
const =
delete;
460 return std::to_string(m_Value);
468 return static_cast<int>(m_Value);
474 std::string getMessage()
const;
481 return m_Value > 599;
485 Value m_Value = HttpStatusCodeUnknown;
486 std::string m_CustomizedMessage;
538 virtual ~HttpResponseLayer();
545 HttpResponseLayer(
const HttpResponseLayer& other);
553 HttpResponseLayer& operator=(
const HttpResponseLayer& other);
572 HeaderField* setContentLength(
int contentLength,
const std::string &prevFieldName =
"");
579 int getContentLength()
const;
626 std::string getUri()
const;
633 bool setUri(std::string newUri);
658 int getSize()
const {
return m_FirstLineEndOffset; }
678 void setMessage(
const std::string &message) { m_Message = message; }
679 virtual const char* what()
const throw()
681 return m_Message.c_str();
684 std::string m_Message;
697 int m_FirstLineEndOffset;
730 int getStatusCodeAsInt()
const;
735 std::string getStatusCodeString()
const;
745 PCPP_DEPRECATED
bool setStatusCode(
const HttpResponseStatusCode& newStatusCode,
const std::string& statusCodeString);
780 static HttpVersion parseVersion(
const char* data,
size_t dataLen);
785 int getSize()
const {
return m_FirstLineEndOffset; }
805 void setMessage(
const std::string &message) { m_Message = message; }
806 virtual const char* what()
const throw()
808 return m_Message.c_str();
811 std::string m_Message;
821 int m_FirstLineEndOffset;
The main namespace for the PcapPlusPlus lib.
HttpVersion getVersion() const
Definition: HttpLayer.h:638
OsiModelLayer
Definition: ProtocolType.h:333
Definition: HttpLayer.h:135
Definition: HttpLayer.h:157
int getSize() const
Definition: HttpLayer.h:658
HttpResponseStatusCode(Value statusCode)
Construct HttpResponseStatusCode from Value enum.
Definition: HttpLayer.h:434
Definition: HttpLayer.h:159
Definition: HttpLayer.h:161
Definition: ProtocolType.h:348
Definition: HttpLayer.h:36
virtual HeaderField * addField(const std::string &fieldName, const std::string &fieldValue)
HttpResponseFirstLine * getFirstLine() const
Definition: HttpLayer.h:558
Definition: HttpLayer.h:149
HttpResponseStatusCode getStatusCode() const
Definition: HttpLayer.h:725
bool isComplete() const
Definition: HttpLayer.h:666
Definition: HttpLayer.h:801
OsiModelLayer getOsiModelLayer() const
Definition: HttpLayer.h:107
HttpRequestLayer::HttpMethod getMethod() const
Definition: HttpLayer.h:614
HttpVersion getVersion() const
Definition: HttpLayer.h:757
HttpRequestFirstLine * getFirstLine() const
Definition: HttpLayer.h:203
Definition: HttpLayer.h:503
Definition: TextBasedProtocol.h:115
Definition: HttpLayer.h:147
std::string toString() const
get status code number as string
Definition: HttpLayer.h:458
Definition: HttpLayer.h:674
Definition: HttpLayer.h:40
The enum wrapper class of HTTP response status codes.
Definition: HttpLayer.h:227
HttpMethod
Definition: HttpLayer.h:142
Definition: HttpLayer.h:87
Definition: HttpLayer.h:718
bool isComplete() const
Definition: HttpLayer.h:793
virtual HeaderField * insertField(HeaderField *prevField, const std::string &fieldName, const std::string &fieldValue)
Definition: HttpLayer.h:145
Definition: HttpLayer.h:155
Definition: HttpLayer.h:38
Definition: HttpLayer.h:607
bool isUnsupportedCode() const
Definition: HttpLayer.h:479
Value
Define enum types and the corresponding int values.
Definition: HttpLayer.h:233
virtual std::string toString() const =0
static bool isHttpPort(uint16_t port)
Definition: HttpLayer.h:98
Definition: HttpLayer.h:153
Definition: HttpLayer.h:34
Definition: HttpLayer.h:151
int toInt() const
get status code number as int
Definition: HttpLayer.h:466
HttpVersion
Definition: HttpLayer.h:31
int getSize() const
Definition: HttpLayer.h:785