Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement HttpResponseStatusCode toString & toInt #1180

Merged
merged 28 commits into from
Aug 26, 2023

Conversation

tigercosmos
Copy link
Collaborator

@tigercosmos tigercosmos commented Aug 11, 2023

fix #1157

  • added new HttpResponseStatusCode enum class, and provided toString & toInt methods
  • updated status code according to the latest spec

@codecov
Copy link

codecov bot commented Aug 11, 2023

Codecov Report

Merging #1180 (e0eb088) into dev (6986e81) will decrease coverage by 0.02%.
The diff coverage is 60.99%.

@@            Coverage Diff             @@
##              dev    #1180      +/-   ##
==========================================
- Coverage   82.11%   82.10%   -0.02%     
==========================================
  Files         157      157              
  Lines       20098    20147      +49     
  Branches     7575     7516      -59     
==========================================
+ Hits        16504    16541      +37     
+ Misses       3092     3074      -18     
- Partials      502      532      +30     
Flag Coverage Δ
alpine315 68.53% <50.00%> (-0.02%) ⬇️
centos7 71.95% <72.72%> (+0.01%) ⬆️
fedora34 68.36% <50.00%> (-0.02%) ⬇️
macos-11 60.61% <54.97%> (+0.48%) ⬆️
macos-12 60.73% <54.97%> (+0.55%) ⬆️
macos-ventura 60.68% <54.97%> (+0.55%) ⬆️
mingw32 68.78% <56.81%> (-0.04%) ⬇️
mingw64 68.80% <56.81%> (-0.04%) ⬇️
npcap 82.08% <91.37%> (-0.11%) ⬇️
ubuntu1804 72.14% <73.33%> (-0.02%) ⬇️
ubuntu2004 69.21% <57.50%> (+0.01%) ⬆️
ubuntu2204 68.12% <50.00%> (-0.03%) ⬇️
ubuntu2204-icpx 59.50% <29.53%> (+0.32%) ⬆️
unittest 82.10% <60.99%> (-0.02%) ⬇️
windows-2019 82.12% <91.37%> (-0.08%) ⬇️
windows-2022 82.13% <91.37%> (-0.08%) ⬇️
winpcap 82.09% <91.37%> (-0.06%) ⬇️
zstd 72.48% <55.41%> (+0.48%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
Packet++/src/HttpLayer.cpp 68.26% <57.84%> (+0.07%) ⬆️
Packet++/header/HttpLayer.h 78.43% <100.00%> (+9.85%) ⬆️
Packet++/src/TcpLayer.cpp 88.42% <100.00%> (ø)

... and 20 files with indirect coverage changes

@tigercosmos
Copy link
Collaborator Author

@seladb please review, I didn't fix the CI, would like to get your agreement on the change first

@egecetin egecetin changed the base branch from master to dev August 11, 2023 20:16
@egecetin
Copy link
Collaborator

egecetin commented Aug 11, 2023

When I was reviewing your PR, I noticed some of the HTTP status codes are missing (not in your PR, but in library). Probably the list is a bit outdated. For example, 103 Early Hints (RFC 8297 from 2017), 421 Misredirected Request and maybe more. Not checked all of that but you can find the latest list here. I think the list of all status codes should also be updated.

@tigercosmos
Copy link
Collaborator Author

@egecetin already updated the code list

Comment on lines 257 to 258
/** 302 Found */
Http302Found = 302,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously 302 could also mean Moved Temporarily, do we want to keep supporting it?

Copy link
Collaborator Author

@tigercosmos tigercosmos Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seladb answer about all comments for adding and removing code in the list:
as @egecetin mentioned, those values are outdated, according to https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml, so I just updated them according to the latest spec (2022)
The question is should we support the old code or not? IMO, we should avoid supporting old specs (but maybe it's okay to keep the current codes), since it takes more effort to maintain and increases the complexity of the code base.
We probably can make this version a breaking change version?

Copy link
Collaborator

@egecetin egecetin Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the unofficial ones should also be supported too as @seladb mentioned because some of them widely used. @tigercosmos so I think there is no need removing old codes only adding missing ones and apply changes enough. But the only problem what will we do when there is a conflict for a status code message (if there are some codes have this situation). Since they are unofficial, different apps can use same code for different messages. What do you think about this @seladb? Should all messages be displayed somehow (maybe comma separated etc), display only most popular one or display a generic message like "various messages" or ...?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The essence of PcapPlusPlus is parsing packets. People use it to parse different kinds of packets, some of which are very old and contain outdated data, such as old HTTP messages. That's why I think we should support outdated/unofficial HTTP data.
It's true that applications can use HTTP status codes for any purpose, even if that purpose doesn't meet the official specifications. However, for most status codes there is only one usage (classic examples are 200 OK, 404 Not Found, 401 Unauthorized, 500 Internal Server Error). If there are cases where there is more than one usage, we can probably say " or other". Please let me know what you think

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree we should support any status code.
actually, even for unknown status codes (1xx-5xx, exclusive other else, e.g. 999), I think we should also support it, e.g. 599 My Customized, because users may want to analyze their internal usage packets.

the current behavior for parsing a packet limits the possibility of the user's customized status code.
how about this, we can add a new std::string m_StatusCodeCustomizedDefination in HttpResponseFirstLine, to allow the user's customized code.

  • if the code is 200, and it's already in our HttpResponseFirstLine, and the definition in the packet is the same as our definition, so m_StatusCodeCustomizedDefination is empty
  • if the code is 599, and the user defines it's My Customized, then m_StatusCodeCustomizedDefination is My Customized.
  • if the code is 302, it's Found in the spec, but the user defines it as Hello World, then m_StatusCodeCustomizedDefination is Hello World.

later on, whenever we need to print or return the definition of the status code, we first see if m_StatusCodeCustomizedDefination is defined; otherwise, we return the default definition.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HttpResponseFirstLine is probably not a great place to put this definition because it has a private constructor and cannot be modified by the user. Besides, it seems that customized codes should be part of HttpResponseStatusCode.

In order to keep this PR simple and focused, I'd suggest supporting the existing status codes and maybe add customized code later. Please let me know what you think

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, let's do it in another PR

Packet++/header/HttpLayer.h Outdated Show resolved Hide resolved
Packet++/header/HttpLayer.h Outdated Show resolved Hide resolved
Packet++/header/HttpLayer.h Outdated Show resolved Hide resolved
Packet++/header/HttpLayer.h Outdated Show resolved Hide resolved
Packet++/header/HttpLayer.h Show resolved Hide resolved
Packet++/header/HttpLayer.h Show resolved Hide resolved
@tigercosmos
Copy link
Collaborator Author

@seladb please take a look

Packet++/src/HttpLayer.cpp Outdated Show resolved Hide resolved
Packet++/src/HttpLayer.cpp Outdated Show resolved Hide resolved
Packet++/src/HttpLayer.cpp Outdated Show resolved Hide resolved
Tests/Packet++Test/Tests/HttpTests.cpp Show resolved Hide resolved
Packet++/src/HttpLayer.cpp Outdated Show resolved Hide resolved
Packet++/src/HttpLayer.cpp Outdated Show resolved Hide resolved
Packet++/src/HttpLayer.cpp Outdated Show resolved Hide resolved
@seladb
Copy link
Owner

seladb commented Aug 25, 2023

@tigercosmos is there anything we can do with this? #1180 (comment)

@seladb seladb merged commit 666e292 into seladb:dev Aug 26, 2023
35 checks passed
@seladb
Copy link
Owner

seladb commented Aug 27, 2023

@tigercosmos thank you so much for your contribution to this project, much appreciated!! 🙏 🙏

If you're interested maybe you can work on: #1180 (comment)

@tigercosmos tigercosmos deleted the 20230812HttpStatusCode branch August 27, 2023 12:28
@tigercosmos
Copy link
Collaborator Author

@seladb thank you for taking time reviewing! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implement HttpResponseStatusCode to string
3 participants