Skip to content
This repository was 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
igorpeshansky merged 3 commits intomasterfrom
bmoyles-set-content-length
Jul 23, 2018
Merged

Set Content-Length when writing responses to close client connections.#168
igorpeshansky merged 3 commits intomasterfrom
bmoyles-set-content-length

Conversation

@bmoyles0117
Copy link
Copy Markdown
Contributor

No description provided.

Comment thread src/api_server.cc Outdated

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

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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread src/api_server.cc Outdated

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

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
Copy Markdown
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
Copy Markdown
Contributor

@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:

Comment thread src/api_server.cc Outdated
conn->set_status(HttpServer::connection::internal_server_error);

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

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
Copy Markdown
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
Copy Markdown
Contributor

@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