summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/android/src/http_request_android.cpp13
-rw-r--r--platform/darwin/http_request_nsurl.mm5
-rw-r--r--platform/default/http_request_curl.cpp15
3 files changed, 11 insertions, 22 deletions
diff --git a/platform/android/src/http_request_android.cpp b/platform/android/src/http_request_android.cpp
index 390334627a..105ba5860c 100644
--- a/platform/android/src/http_request_android.cpp
+++ b/platform/android/src/http_request_android.cpp
@@ -199,17 +199,14 @@ void HTTPAndroidRequest::onResponse(JNIEnv* env, int code, jstring /* message */
response->expires = util::parseTimePoint(mbgl::android::std_string_from_jstring(env, expires).c_str());
}
- if (body != nullptr) {
- jbyte* bodyData = env->GetByteArrayElements(body, nullptr);
- response->data = std::make_shared<std::string>(reinterpret_cast<char*>(bodyData), env->GetArrayLength(body));
- env->ReleaseByteArrayElements(body, bodyData, JNI_ABORT);
- }
-
if (code == 200) {
- // Nothing to do; this is what we want
+ if (body != nullptr) {
+ jbyte* bodyData = env->GetByteArrayElements(body, nullptr);
+ response->data = std::make_shared<std::string>(reinterpret_cast<char*>(bodyData), env->GetArrayLength(body));
+ env->ReleaseByteArrayElements(body, bodyData, JNI_ABORT);
+ }
} else if (code == 304) {
response->notModified = true;
- response->data.reset();
} else if (code == 404) {
response->error = std::make_unique<Error>(Error::Reason::NotFound, "HTTP status code 404");
} else if (code >= 500 && code < 600) {
diff --git a/platform/darwin/http_request_nsurl.mm b/platform/darwin/http_request_nsurl.mm
index fa705638b4..890e347afc 100644
--- a/platform/darwin/http_request_nsurl.mm
+++ b/platform/darwin/http_request_nsurl.mm
@@ -194,8 +194,6 @@ void HTTPNSURLRequest::handleResult(NSData *data, NSURLResponse *res, NSError *e
} else if ([res isKindOfClass:[NSHTTPURLResponse class]]) {
const long responseCode = [(NSHTTPURLResponse *)res statusCode];
- response->data = std::make_shared<std::string>((const char *)[data bytes], [data length]);
-
NSDictionary *headers = [(NSHTTPURLResponse *)res allHeaderFields];
NSString *cache_control = [headers objectForKey:@"Cache-Control"];
if (cache_control) {
@@ -218,10 +216,9 @@ void HTTPNSURLRequest::handleResult(NSData *data, NSURLResponse *res, NSError *e
}
if (responseCode == 200) {
- // Nothing to do; this is what we want.
+ response->data = std::make_shared<std::string>((const char *)[data bytes], [data length]);
} else if (responseCode == 304) {
response->notModified = true;
- response->data.reset();
} else if (responseCode == 404) {
response->error =
std::make_unique<Error>(Error::Reason::NotFound, "HTTP status code 404");
diff --git a/platform/default/http_request_curl.cpp b/platform/default/http_request_curl.cpp
index f7fb27afc5..660da4c43e 100644
--- a/platform/default/http_request_curl.cpp
+++ b/platform/default/http_request_curl.cpp
@@ -509,19 +509,14 @@ void HTTPCURLRequest::handleResult(CURLcode code) {
long responseCode = 0;
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &responseCode);
- // Move over any data we got. We're storing this in a separate object because the Response
- // object defines it as const.
- if (data) {
- response->data = std::move(data);
- } else {
- response->data = std::make_shared<std::string>();
- }
-
if (responseCode == 200) {
- // Nothing to do; this is what we want.
+ if (data) {
+ response->data = std::move(data);
+ } else {
+ response->data = std::make_shared<std::string>();
+ }
} else if (responseCode == 304) {
response->notModified = true;
- response->data.reset();
} else if (responseCode == 404) {
response->error =
std::make_unique<Error>(Error::Reason::NotFound, "HTTP status code 404");