CLOUD: Handle HTTP response headers case-insensitively

RFC 2616 states that HTTP headers are not case-sensitive and also allows
arbitrary number of whitespace characters around header value. Previous
implementation was dependant on headers to be in "Title-Case" and to
have only one space before header value. That has lead to cloud sync
failure on Debian x64 (user's network environment was probably the
reason though).

This commit adds a new method, which parses headers name-value pairs
into HashMap. To ensure case-insensitivity, all headers names are
converted to lowercase, and thus code that uses this method should
specify headers in lowercase. All usages of raw headers contents were
updated to use this method.
This commit is contained in:
Alexander Tkachev 2019-08-25 14:02:02 +07:00 committed by Filippos Karapetis
parent 0c479251c7
commit 24b1ec0ded
4 changed files with 97 additions and 44 deletions

View file

@ -71,20 +71,9 @@ void CurlRequest::restart() {
Common::String CurlRequest::date() const {
if (_stream) {
Common::String headers = _stream->responseHeaders();
const char *cstr = headers.c_str();
const char *position = strstr(cstr, "Date: ");
if (position) {
Common::String result = "";
char c;
for (const char *i = position + 6; c = *i, c != 0; ++i) {
if (c == '\n' || c == '\r')
break;
result += c;
}
return result;
}
Common::HashMap<Common::String, Common::String> headers = _stream->responseHeadersMap();
if (headers.contains("date"))
return headers["date"];
}
return "";
}