Support HTTP responses with no body Successful upsertLocalAuthInfo cloud requests returns no body and no content type. BUG=25766813 Change-Id: Id4deb57c8dfea04196f77c80b6f40ce62db9fa6f Reviewed-on: https://weave-review.googlesource.com/1799 Reviewed-by: Alex Vakulenko <avakulenko@google.com>
diff --git a/examples/provider/curl_http_client.cc b/examples/provider/curl_http_client.cc index 774c07b..6f0ba64 100644 --- a/examples/provider/curl_http_client.cc +++ b/examples/provider/curl_http_client.cc
@@ -118,12 +118,6 @@ response->content_type = header.second; } - if (response->content_type.empty()) { - Error::AddTo(&error, FROM_HERE, "curl", "no_content_header", - "Content-Type header is missing"); - return {nullptr, std::move(error)}; - } - CHECK_EQ(CURLE_OK, curl_easy_getinfo(curl.get(), CURLINFO_RESPONSE_CODE, &response->status));
diff --git a/src/device_registration_info.cc b/src/device_registration_info.cc index 3bc7515..110ba81 100644 --- a/src/device_registration_info.cc +++ b/src/device_registration_info.cc
@@ -712,6 +712,12 @@ return; } + if (data->allow_response_without_content && + response->GetContentType().empty()) { + cloud_backoff_entry_->InformOfRequest(true); + return data->callback.Run({}, nullptr); + } + auto json_resp = ParseJsonResponse(*response, &error); if (!json_resp) { cloud_backoff_entry_->InformOfRequest(true);
diff --git a/src/device_registration_info.h b/src/device_registration_info.h index ff9c29b..bacab48 100644 --- a/src/device_registration_info.h +++ b/src/device_registration_info.h
@@ -178,6 +178,8 @@ provider::HttpClient::Method method; std::string url; std::string body; + // Workaround for inconsistent APIs which returns no body. + bool allow_response_without_content = false; CloudRequestDoneCallback callback; }; void SendCloudRequest(const std::shared_ptr<const CloudRequestData>& data);
diff --git a/src/weave_unittest.cc b/src/weave_unittest.cc index b8c4d9b..66850cf 100644 --- a/src/weave_unittest.cc +++ b/src/weave_unittest.cc
@@ -198,7 +198,6 @@ .Times(AtLeast(1)) .WillRepeatedly(Return("application/json; charset=utf-8")); EXPECT_CALL(*response, GetData()) - .Times(AtLeast(1)) .WillRepeatedly(Return(json_response)); callback.Run(std::move(response), nullptr); })));