aboutsummaryrefslogtreecommitdiff
path: root/backends/cloud/googledrive/googledriveuploadrequest.cpp
diff options
context:
space:
mode:
authorAlexander Tkachev2019-08-25 14:02:02 +0700
committerFilippos Karapetis2019-08-25 12:15:14 +0300
commit24b1ec0dedf31097396741aa811dfabf9335b397 (patch)
treeba2e9c4c387aa953cd09fe6534bf4712526396be /backends/cloud/googledrive/googledriveuploadrequest.cpp
parent0c479251c794f536c9bcaf18c2ce10fcb1537be2 (diff)
downloadscummvm-rg350-24b1ec0dedf31097396741aa811dfabf9335b397.tar.gz
scummvm-rg350-24b1ec0dedf31097396741aa811dfabf9335b397.tar.bz2
scummvm-rg350-24b1ec0dedf31097396741aa811dfabf9335b397.zip
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.
Diffstat (limited to 'backends/cloud/googledrive/googledriveuploadrequest.cpp')
-rw-r--r--backends/cloud/googledrive/googledriveuploadrequest.cpp46
1 files changed, 15 insertions, 31 deletions
diff --git a/backends/cloud/googledrive/googledriveuploadrequest.cpp b/backends/cloud/googledrive/googledriveuploadrequest.cpp
index f921f5c96d..c4728c5ac1 100644
--- a/backends/cloud/googledrive/googledriveuploadrequest.cpp
+++ b/backends/cloud/googledrive/googledriveuploadrequest.cpp
@@ -152,20 +152,10 @@ void GoogleDriveUploadRequest::startUploadCallback(Networking::JsonResponse resp
const Networking::NetworkReadStream *stream = rq->getNetworkReadStream();
if (stream) {
long code = stream->httpResponseCode();
- Common::String headers = stream->responseHeaders();
if (code == 200) {
- const char *cstr = headers.c_str();
- const char *position = strstr(cstr, "Location: ");
-
- if (position) {
- Common::String result = "";
- char c;
- for (const char *i = position + 10; c = *i, c != 0; ++i) {
- if (c == '\n' || c == '\r')
- break;
- result += c;
- }
- _uploadUrl = result;
+ Common::HashMap<Common::String, Common::String> headers = stream->responseHeadersMap();
+ if (headers.contains("location")) {
+ _uploadUrl = headers["location"];
uploadNextPart();
return;
}
@@ -230,25 +220,19 @@ bool GoogleDriveUploadRequest::handleHttp308(const Networking::NetworkReadStream
if (stream->httpResponseCode() != 308)
return false; //seriously
- Common::String headers = stream->responseHeaders();
- const char *cstr = headers.c_str();
- for (int rangeTry = 0; rangeTry < 2; ++rangeTry) {
- const char *needle = (rangeTry == 0 ? "Range: 0-" : "Range: bytes=0-");
- uint32 needleLength = (rangeTry == 0 ? 9 : 15);
-
- const char *position = strstr(cstr, needle); //if it lost the first part, I refuse to talk with it
-
- if (position) {
- Common::String result = "";
- char c;
- for (const char *i = position + needleLength; c = *i, c != 0; ++i) {
- if (c == '\n' || c == '\r')
- break;
- result += c;
+ Common::HashMap<Common::String, Common::String> headers = stream->responseHeadersMap();
+ if (headers.contains("range")) {
+ Common::String range = headers["range"];
+ for (int rangeTry = 0; rangeTry < 2; ++rangeTry) {
+ const char *needle = (rangeTry == 0 ? "0-" : "bytes=0-"); //if it lost the first part, I refuse to talk with it
+ uint32 needleLength = (rangeTry == 0 ? 2 : 8);
+
+ if (range.hasPrefix(needle)) {
+ range.erase(0, needleLength);
+ _serverReceivedBytes = range.asUint64() + 1;
+ uploadNextPart();
+ return true;
}
- _serverReceivedBytes = result.asUint64() + 1;
- uploadNextPart();
- return true;
}
}