-
Notifications
You must be signed in to change notification settings - Fork 56
Finished listing status codes which SHOULD NOT contain body #98
Conversation
👍 |
Must have used |
@pksunkara You plan to add on this PR or open a new one for the rest? I would prefer to split it in two thus remove the part related to status codes. It would be easier to review it. |
Added the test. I want to open a new one for the rest. Thanks. |
@zdne I was planning on opening a new pull request for the second part. But since this isn't merged yet, here they are. |
Well done Pavan! I must say I am impressed. Let's throw out the old Content-Type - based checks and possibly address the edged CONNECT case and we are good with HTTP1.1! |
Also (some non-programing) work - It would be good at the end to summarize the change and explain the new behavior for users. Either on this PR or on #77 |
Shall I clean this up now? |
@pksunkara absolutely! Please proceed when you can. Also feel free to squash some commits where it makes sense. |
Squashed related commits and cleaned up the code. Added the case for |
Awesome! Will check it tomorrow. Thanks! |
traits.method = method; | ||
|
||
// Following HTTP methods MUST NOT contain response body | ||
if (method == "HEAD" || method == "CONNECT") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Careful CONNECT outside of 2xx range (and 1xx) can include a response!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also best to define used methods similar to headers e.g.
struct HTTPMethods {
...
}
...
const std::string HTTPMethods::HEAD = "HEAD";
or something like this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am checking for that when generating the warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood but, lets refrain from retyping constants by defining them and reusing the definitions (rather then typing the same strings over and over).
Shall I remove the Content-Type stuff and fix the HTTPMethod strings? |
What about something along these lines: struct HTTPPayloadTraits {
bool allowBody;
HTTPPayloadTraits (): allowBody(true) {}
};
struct XStatusCodeTraits : HTTPPayloadTraits {
XStatusCodeTraits() {}
XStatusCodeTraits(const HTTPStatusCode& code)
{
if (code == 204 || code == 304 || code / 100 == 1) {
allowBody = false;
}
}
};
typedef std::string XHTTPMethod;
struct XMethodTraits : XStatusCodeTraits {
XMethodTraits() {}
XMethodTraits(const XHTTPMethod& method) : XStatusCodeTraits()
{
// TODO:
}
XMethodTraits(const XHTTPMethod& method, const HTTPStatusCode& code) : XStatusCodeTraits(code)
{
// TODO:
}
}; |
Ad my previous comment: Then Note the X-names are just temporary. But maybe I am just over-engineering things? |
Either way, I will leave the final decision up to you. |
In my opinion, this looks too much. If we are going to have a function which takes both I fixed the method name stuff you asked me for. |
I would like to remove the |
Agree, please proceed when you can. |
Fixed the content-type stuff. |
traits.method = method; | ||
|
||
// Following HTTP methods MUST NOT contain response body | ||
if (method == HTTPMethodName::Head || method == HTTPMethodName::Connect) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Lets at least add comment that for Connect the allowBody is false only for 1xx - 2xx range so we (or someone else) won't forget it when refactoring traits (as this probably won't happen anytime soon).
Done. 😄 |
Follow HTTP1.1 rules for allowed message body
Content-Length
orTransfer-Encoding
header in request is set.HEAD
1xx
CONNECT
and response status code is2xx