Commit 50ead5c5 authored by Maciek Kumorek's avatar Maciek Kumorek Committed by Commit Bot

Fix how content-type is set in WinHTTP network fetcher


The WinHttpAddRequestHeaders expects a fully formatted header:
 Key: Value\r\n

Only the value of content-type header was passed. This change fixes
the issue.

Bug: 1102579
Change-Id: I1b432312bbba161f833de99dfda1ef9e4b39135d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2283927Reviewed-by: default avatarSorin Jianu <sorin@chromium.org>
Commit-Queue: Maciek Kumorek <makumo@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#786285}
parent aae7c667
......@@ -134,7 +134,7 @@ void NetworkFetcherWinHTTP::PostRequest(
CrackUrl(url, &is_https_, &host_, &port_, &path_for_request_);
verb_ = L"POST";
content_type_ = base::SysUTF8ToWide(content_type);
content_type_ = content_type;
write_data_callback_ =
base::BindRepeating(&NetworkFetcherWinHTTP::WriteDataToMemory, this);
......@@ -171,7 +171,7 @@ void NetworkFetcherWinHTTP::DownloadToFile(
HRESULT NetworkFetcherWinHTTP::BeginFetch(
const std::string& data,
const base::flat_map<std::string, std::string>& additional_headers) {
base::flat_map<std::string, std::string> additional_headers) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
connect_handle_ = Connect();
if (!connect_handle_.get())
......@@ -200,17 +200,17 @@ HRESULT NetworkFetcherWinHTTP::BeginFetch(
if (FAILED(hr))
return hr;
if (!content_type_.empty()) {
::WinHttpAddRequestHeaders(
request_handle_.get(), content_type_.data(), content_type_.size(),
WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE);
}
if (!content_type_.empty())
additional_headers.insert({"Content-Type", content_type_});
for (const auto& header : additional_headers) {
const auto raw_header = base::SysUTF8ToWide(
base::StrCat({header.first, ": ", header.second, "\r\n"}));
::WinHttpAddRequestHeaders(
request_handle_.get(), raw_header.c_str(), raw_header.size(),
WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE);
if (!::WinHttpAddRequestHeaders(
request_handle_.get(), raw_header.c_str(), raw_header.size(),
WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE)) {
PLOG(ERROR) << "Failed to set the request header: " << raw_header;
}
}
hr = SendRequest(data);
......
......@@ -95,7 +95,7 @@ class NetworkFetcherWinHTTP
HRESULT BeginFetch(
const std::string& data,
const base::flat_map<std::string, std::string>& additional_headers);
base::flat_map<std::string, std::string> additional_headers);
scoped_hinternet Connect();
scoped_hinternet OpenRequest();
HRESULT SendRequest(const std::string& data);
......@@ -131,7 +131,8 @@ class NetworkFetcherWinHTTP
std::string path_for_request_;
base::StringPiece16 verb_;
base::string16 content_type_;
// The value of Content-Type header, e.g. "application/json".
std::string content_type_;
WriteDataCallback write_data_callback_;
HRESULT net_error_ = S_OK;
std::string header_etag_;
......
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