example: send response content-length as part of http header from server#808
example: send response content-length as part of http header from server#808deanberris merged 3 commits intocpp-netlib:0.13-releasefrom carun:fix-content-length
Conversation
|
ping @deanberris |
| void operator()(server::request const& req, const server::connection_ptr& conn) { | ||
| static std::map<std::string, std::string> headers = { | ||
| {"Connection","close"}, | ||
| {"Content-Length", "0"}, |
There was a problem hiding this comment.
I think I understand now, that you want to always define this for every new response. That makes sense.
There was a problem hiding this comment.
I think this map really ought to not be static, unless you're going to make copies of it for every instance of this handler -- note that there could be multiple threads accessing this map, and updating it on the fly will cause all sorts of threading issues. Aside from that, the other changes look good.
| conn->write(err); | ||
| } | ||
| } else { | ||
| static std::string body("Only path allowed is /upload"); |
There was a problem hiding this comment.
It's usually a bad idea to have function-local static objects with non-trivial destructors. Consider just turning this into a character array that's also constexpr:
static constexpr char body[] = "Only path allowed is /upload";
| std::this_thread::sleep_for(std::chrono::seconds(10)); | ||
|
|
||
| std::map<std::string, std::string> headers = { | ||
| static std::map<std::string, std::string> headers = { |
There was a problem hiding this comment.
Why does this need to be static?
There was a problem hiding this comment.
so that the map doesn't get created every time the function is called.
| data << "Hello, " << ip << ':' << port << '!'; | ||
|
|
||
| std::map<std::string, std::string> headers = { | ||
| static std::map<std::string, std::string> headers = { |
There was a problem hiding this comment.
ditto.. if it is not required, I can remove it.
|
ping @deanberris |
deanberris
left a comment
There was a problem hiding this comment.
Just one more change, and I think we're good to go. Thanks for the patience, vacation and travel taking too much time for me recently. 😄
| void operator()(server::request const& req, const server::connection_ptr& conn) { | ||
| static std::map<std::string, std::string> headers = { | ||
| {"Connection","close"}, | ||
| {"Content-Length", "0"}, |
There was a problem hiding this comment.
I think this map really ought to not be static, unless you're going to make copies of it for every instance of this handler -- note that there could be multiple threads accessing this map, and updating it on the fly will cause all sorts of threading issues. Aside from that, the other changes look good.
|
Hey @deanberris Thank you for creating a wonderful library. 😄 |
fixes issue #681