Skip to content

Commit

Permalink
Binarycaching: Don't use vector for HTTP headers (#1350)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas1664 authored Feb 21, 2024
1 parent 6cc0086 commit e458596
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions src/vcpkg/binarycaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,12 +796,13 @@ namespace

std::string lookup_cache_entry(StringView name, const std::string& abi) const
{
auto url = format_url_query(m_url, std::vector<std::string>{"keys=" + name + "-" + abi, "version=" + abi});
auto res =
invoke_http_request("GET",
std::vector<std::string>{
m_content_type_header.to_string(), m_token_header, m_accept_header.to_string()},
url);
const auto url = format_url_query(m_url, {{"keys=" + name + "-" + abi, "version=" + abi}});
const std::string headers[] = {
m_content_type_header.to_string(),
m_token_header,
m_accept_header.to_string(),
};
auto res = invoke_http_request("GET", headers, url);
if (auto p = res.get())
{
auto maybe_json = Json::parse_object(*p, m_url);
Expand Down Expand Up @@ -833,7 +834,7 @@ namespace
url_indices.push_back(idx);
}

auto codes = download_files(m_fs, url_paths, {});
const auto codes = download_files(m_fs, url_paths, {});

for (size_t i = 0; i < codes.size(); ++i)
{
Expand Down Expand Up @@ -873,10 +874,11 @@ namespace
payload.insert("version", abi);
payload.insert("cacheSize", Json::Value::integer(cacheSize));

std::vector<std::string> headers;
headers.emplace_back(m_accept_header.data(), m_accept_header.size());
headers.emplace_back(m_content_type_header.data(), m_content_type_header.size());
headers.emplace_back(m_token_header);
const std::string headers[] = {
m_accept_header.to_string(),
m_content_type_header.to_string(),
m_token_header,
};

auto res = invoke_http_request("POST", headers, m_url, stringify(payload));
if (auto p = res.get())
Expand Down Expand Up @@ -907,22 +909,24 @@ namespace

if (auto cacheId = reserve_cache_entry(request.spec.name(), abi, cache_size))
{
std::vector<std::string> custom_headers{
const std::string custom_headers[] = {
m_token_header,
m_accept_header.to_string(),
"Content-Type: application/octet-stream",
"Content-Range: bytes 0-" + std::to_string(cache_size) + "/*",
};
auto url = m_url + "/" + std::to_string(*cacheId.get());

const auto url = m_url + "/" + std::to_string(*cacheId.get());
if (put_file(m_fs, url, {}, custom_headers, zip_path, "PATCH"))
{
Json::Object commit;
commit.insert("size", std::to_string(cache_size));
std::vector<std::string> headers;
headers.emplace_back(m_accept_header.data(), m_accept_header.size());
headers.emplace_back(m_content_type_header.data(), m_content_type_header.size());
headers.emplace_back(m_token_header);
const std::string headers[] = {
m_accept_header.to_string(),
m_content_type_header.to_string(),
m_token_header,
};

auto res = invoke_http_request("POST", headers, url, stringify(commit));
if (res)
{
Expand Down Expand Up @@ -1747,7 +1751,7 @@ namespace vcpkg
});
if (!result)
{
return result.error();
return std::move(result).error();
}
if (!invalid_keys.empty())
{
Expand Down

0 comments on commit e458596

Please sign in to comment.