Commit 32c60fdc authored by Min Qin's avatar Min Qin Committed by Commit Bot

Fix an issue that EmbeddedTestServer may not send headers that can be parsed correctly

HttpUtils is looking for "\n\n" and "\n\r\n" as the end of the header.
So if the headers are already ending with "\n\n", we shouldn't append "\r\n" to it.
Otherwise, the appended "\r\n" will be treated as the body

BUG=715630

Change-Id: Ia087f3ec7f7644c088635f375782841f2c6a32d0
Reviewed-on: https://chromium-review.googlesource.com/693323Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505856}
parent 20d80e81
...@@ -27,9 +27,13 @@ void RawHttpResponse::SendResponse(const SendBytesCallback& send, ...@@ -27,9 +27,13 @@ void RawHttpResponse::SendResponse(const SendBytesCallback& send,
std::string response; std::string response;
if (!headers_.empty()) { if (!headers_.empty()) {
response = headers_; response = headers_;
if (!base::EndsWith(response, "\n", base::CompareCase::SENSITIVE)) // LocateEndOfHeadersHelper() searches for the first "\n\n" and "\n\r\n" as
response += "\r\n"; // the end of the header.
response += "\r\n" + contents_; std::size_t index = response.find_last_not_of("\r\n");
if (index != std::string::npos)
response.erase(index + 1);
response += "\n\n";
response += contents_;
} else { } else {
response = contents_; response = contents_;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment