cashew: Allow specification of nameservers in http_fetcher

Allow specification of nameservers in http_fetcher

BUG=chromium-os:27904
TEST=get usage information while attached to an Ethernet

Change-Id: I7222c4c852b3b70dc09c52b49a1633a3529849a7
Reviewed-on: https://gerrit.chromium.org/gerrit/18800
Reviewed-by: Nathan J. Williams <njw@chromium.org>
Commit-Ready: <jglasgow@google.com>
Tested-by: <jglasgow@google.com>
diff --git a/src/http_fetcher.h b/src/http_fetcher.h
index 06d07bb..d0fd827 100644
--- a/src/http_fetcher.h
+++ b/src/http_fetcher.h
@@ -39,6 +39,10 @@
   HttpFetcherDelegate* delegate() const { return delegate_; }
   int http_response_code() const { return http_response_code_; }
 
+  // Optional: Set the name servers to use
+  void set_nameservers(const std::vector<std::string>& nameservers) {
+    nameservers_ = nameservers; }
+
   // Optional: Post data to the server. The HttpFetcher should make a copy
   // of this data and upload it via HTTP POST during the transfer.
   void SetPostData(const void* data, size_t size) {
@@ -69,6 +73,9 @@
   // The URL we're actively fetching from
   std::string url_;
 
+  // The name servers to use (if not empty).
+  std::vector<std::string> nameservers_;
+
   // POST data for the transfer, and whether or not it was ever set
   bool post_data_set_;
   std::vector<char> post_data_;
diff --git a/src/libcurl_http_fetcher.cc b/src/libcurl_http_fetcher.cc
index 94b0e2c..59352b5 100644
--- a/src/libcurl_http_fetcher.cc
+++ b/src/libcurl_http_fetcher.cc
@@ -10,11 +10,13 @@
 #include <config.h>
 
 #include <algorithm>
+#include <vector>
 
 #include <glog/logging.h>  // NOLINT
 
 using std::max;
 using std::make_pair;
+using std::vector;
 
 // This is a concrete implementation of HttpFetcher that uses libcurl to do the
 // http work.
@@ -43,6 +45,22 @@
   curl_handle_ = curl_easy_init();
   CHECK(curl_handle_);
 
+  std::string nameservers_str;
+  for (vector<std::string>::const_iterator it(nameservers_.begin());
+       it != nameservers_.end(); it++) {
+    if (!nameservers_str.empty())
+      nameservers_str += ",";
+    nameservers_str += *it;
+  }
+  LOG(INFO) << "LibcurlHttpFetcher: nameservers = " << nameservers_str;
+
+  if (!nameservers_str.empty()) {
+    CHECK_EQ(curl_easy_setopt(curl_handle_,
+                              CURLOPT_DNS_SERVERS,
+                              nameservers_str.c_str()),
+             CURLE_OK);
+  }
+
   if (post_data_set_) {
     CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_POST, 1), CURLE_OK);
     CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_POSTFIELDS,