Skip to content

Commit

Permalink
Forward query/headers properly during HEAD requests and fix a warning.
Browse files Browse the repository at this point in the history
…Closes #3291. (#3439)
  • Loading branch information
connormanning committed May 6, 2021
1 parent 4dee056 commit 3c08cc4
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 11 deletions.
61 changes: 50 additions & 11 deletions vendor/arbiter/arbiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ namespace

return merge(in, config);
}

inline bool iequals(const std::string& s, const std::string& s2)
{
if (s.length() != s2.length())
Expand Down Expand Up @@ -683,7 +683,7 @@ LocalHandle Endpoint::getLocalHandle(
const std::string local(tmp + basename);
if (isHttpDerived())
{
if (auto fileSize = tryGetSize(subpath))
if (auto fileSize = tryGetSize(subpath, headers, query))
{
std::ofstream stream(local, streamFlags);
if (!stream.good())
Expand Down Expand Up @@ -805,6 +805,22 @@ std::unique_ptr<std::vector<char>> Endpoint::tryGetBinary(
return getHttpDriver().tryGetBinary(fullPath(subpath), headers, query);
}

std::size_t Endpoint::getSize(
const std::string subpath,
const http::Headers headers,
const http::Query query) const
{
return getHttpDriver().getSize(fullPath(subpath), headers, query);
}

std::unique_ptr<std::size_t> Endpoint::tryGetSize(
const std::string subpath,
const http::Headers headers,
const http::Query query) const
{
return getHttpDriver().tryGetSize(fullPath(subpath), headers, query);
}

void Endpoint::put(
const std::string path,
const std::string& data,
Expand Down Expand Up @@ -1268,7 +1284,7 @@ std::vector<std::string> glob(std::string path)
const auto pre(path.substr(0, recPos)); // Cut off before the '*'.
const auto post(path.substr(recPos + 1)); // Includes the second '*'.

for (const auto d : walk(pre)) dirs.push_back(d + post);
for (const auto& d : walk(pre)) dirs.push_back(d + post);
}
else
{
Expand Down Expand Up @@ -1386,15 +1402,38 @@ std::unique_ptr<Http> Http::create(Pool& pool)
}

std::unique_ptr<std::size_t> Http::tryGetSize(std::string path) const
{
return tryGetSize(path, http::Headers());
}

std::size_t Http::getSize(
std::string path,
Headers headers,
Query query) const
{
auto s = tryGetSize(path, headers, query);
if (!s)
{
throw ArbiterError("Could not get size from " + path);
}
return *s;
}

std::unique_ptr<std::size_t> Http::tryGetSize(
std::string path,
Headers headers,
Query query) const
{
std::unique_ptr<std::size_t> size;

auto http(m_pool.acquire());
Response res(http.head(typedPath(path)));
Response res(http.head(typedPath(path), headers, query));

std::string val;
if (res.ok() && findEntry(res.headers(), "Content-Length", val))
{
size.reset(new std::size_t(std::stoul(val)));
}

return size;
}
Expand Down Expand Up @@ -2647,7 +2686,7 @@ std::string AZ::Config::extractStorageAccount(
{
return *p;
}

if (!c.is_null() && c.value("verbose", false))
{
std::cout << "account not found" << std::endl;
Expand Down Expand Up @@ -3027,7 +3066,7 @@ std::string AZ::ApiV1::buildCanonicalHeader(
canonicalizeHeaders));

return canonicalHeader;
}
}

std::string AZ::ApiV1::buildCanonicalResource(
const Resource& resource,
Expand Down Expand Up @@ -3069,16 +3108,16 @@ std::string AZ::ApiV1::buildStringToSign(
headerValues += makeLine("");
else
headerValues += makeLine(h["Content-Length"]);

headerValues += makeLine(h["Content-MD5"]);
headerValues += makeLine(h["Content-Type"]);
headerValues += makeLine(h["Date"]);
headerValues += makeLine(h["If-Modified-Since"]);
headerValues += makeLine(h["If-Match"]);
headerValues += makeLine(h["If-None-Match"]);
headerValues += makeLine(h["If-Unmodified-Since"]);
headerValues += h["Range"];
headerValues += h["Range"];


return
makeLine(verb) +
Expand All @@ -3096,7 +3135,7 @@ std::string AZ::ApiV1::calculateSignature(
std::string AZ::ApiV1::getAuthHeader(
const std::string& signedHeadersString) const
{
return "SharedKey " +
return "SharedKey " +
m_authFields.account() + ":" +
signedHeadersString;
}
Expand Down Expand Up @@ -5204,7 +5243,7 @@ namespace
//
// Return the position of chr within base64_encode()
//

if (chr >= 'A' && chr <= 'Z') return chr - 'A';
else if (chr >= 'a' && chr <= 'z') return chr - 'a' + ('Z' - 'A') + 1;
else if (chr >= '0' && chr <= '9') return chr - '0' + ('Z' - 'A') + ('z' - 'a') + 2;
Expand Down
28 changes: 28 additions & 0 deletions vendor/arbiter/arbiter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4059,6 +4059,18 @@ class ARBITER_DLL Http : public Driver
http::Headers headers = http::Headers(),
http::Query query = http::Query()) const;

/* Perform an HTTP HEAD request. */
std::size_t getSize(
std::string path,
http::Headers headers,
http::Query query = http::Query()) const;

/* Perform an HTTP HEAD request. */
std::unique_ptr<std::size_t> tryGetSize(
std::string path,
http::Headers headers,
http::Query query = http::Query()) const;

/** Perform an HTTP GET request. */
std::vector<char> getBinary(
std::string path,
Expand Down Expand Up @@ -5046,6 +5058,22 @@ class ARBITER_DLL Endpoint
http::Headers headers,
http::Query query = http::Query()) const;

/** Passthrough to
* drivers::Http::getSize(std::string, http::Headers, http::Query) const.
*/
std::size_t getSize(
std::string subpath,
http::Headers headers,
http::Query = http::Query()) const;

/** Passthrough to
* drivers::Http::tryGetSize(std::string, http::Headers, http::Query) const.
*/
std::unique_ptr<std::size_t> tryGetSize(
std::string subpath,
http::Headers headers,
http::Query = http::Query()) const;

/** Passthrough to
* drivers::Http::put(std::string, const std::string&, http::Headers, http::Query) const.
*/
Expand Down

0 comments on commit 3c08cc4

Please sign in to comment.