Skip to content
This repository has been archived by the owner on Aug 19, 2019. It is now read-only.

Set Content-Length when writing responses to close client connections. #168

Merged
merged 3 commits into from
Jul 23, 2018

Conversation

bmoyles0117
Copy link
Contributor

No description provided.


std::string response = "unhealthy components:\n";
for (const auto& component : unhealthy_components) {
response.append(component + "\n");
Copy link
Member

Choose a reason for hiding this comment

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

Let's use std::ostringstrean instead of std::string::append.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

conn->set_headers(std::map<std::string, std::string>({
{"Content-Type", "application/json"},
{"Content-Length", std::to_string(response.length())},
Copy link
Member

Choose a reason for hiding this comment

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

I believe we use std::string::size everywhere else...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

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

LGTM :shipit:

} else {
LOG(WARNING) << "/healthz returning 500; unhealthy components: "
<< boost::algorithm::join(unhealthy_components, ", ");
conn->set_status(HttpServer::connection::internal_server_error);

std::ostringstream response_stream;
response_stream << "unhealthy components:\n";
Copy link
Member

Choose a reason for hiding this comment

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

[Optional] You can combine these:

    std::ostringstream response_stream("unhealthy components:\n");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks!

Copy link
Member

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

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

LGTM :shipit:

@igorpeshansky igorpeshansky merged commit d156d81 into master Jul 23, 2018
@igorpeshansky igorpeshansky deleted the bmoyles-set-content-length branch July 23, 2018 04:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants