Update engine properly sets Content-Type to text/xml.
Since the payload sent to Omaha is XML encoded, update engine should
properly set the HTTP Content-Type header to text/xml, instead of using
the libcurl default (application/x-www-form-urlencoded).
BUG=chromium-os:7613
TEST=Tested against devserver, ensuring that Content-Type is set
correctly
Change-Id: I9766e8dd67ffd387634a0ab4ef83c2990b16b537
Reviewed-on: https://gerrit.chromium.org/gerrit/16051
Reviewed-by: Andrew de los Reyes <adlr@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
Commit-Ready: Gilad Arnold <garnold@chromium.org>
diff --git a/libcurl_http_fetcher.cc b/libcurl_http_fetcher.cc
index 7af9364..b9da3a7 100644
--- a/libcurl_http_fetcher.cc
+++ b/libcurl_http_fetcher.cc
@@ -91,6 +91,22 @@
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_POSTFIELDSIZE,
post_data_.size()),
CURLE_OK);
+
+ // Set the Content-Type HTTP header, if one was specifically set.
+ CHECK(!curl_http_headers_);
+ if (post_content_type_ != kHttpContentTypeUnspecified) {
+ const string content_type_attr =
+ base::StringPrintf("Content-Type: %s",
+ GetHttpContentTypeString(post_content_type_));
+ curl_http_headers_ = curl_slist_append(NULL, content_type_attr.c_str());
+ CHECK(curl_http_headers_);
+ CHECK_EQ(
+ curl_easy_setopt(curl_handle_, CURLOPT_HTTPHEADER,
+ curl_http_headers_),
+ CURLE_OK);
+ } else {
+ LOG(WARNING) << "no content type set, using libcurl default";
+ }
}
if (bytes_downloaded_ > 0 || download_length_) {
@@ -480,6 +496,10 @@
io_channels_[t].clear();
}
+ if (curl_http_headers_) {
+ curl_slist_free_all(curl_http_headers_);
+ curl_http_headers_ = NULL;
+ }
if (curl_handle_) {
if (curl_multi_handle_) {
CHECK_EQ(curl_multi_remove_handle(curl_multi_handle_, curl_handle_),