Fetcher tries all proxies when a secondary chunk download error occurs.

This is a fix to issue 18143:

* New test cases for asserting the desired behavior: if a transfer of
  a secondary chunk within a multi-chunk fetch fails, then the fetcher
  needs to retry with other available proxies; it will only fail when no
  additional proxies are available.  The tests ensure both success (one
  of the proxies eventually succeeds) and failure (all proxies fail)
  cases.

* Small fix to LibcurlHttpFetcher to retry with other proxies upon
  failure (error value) of a secondary chunk.

Other changes applied in the course of this fix:

* Massive refactoring of http_fetcher_unittest: substituted template
  specialization in typed test setup with proper subclassing, resulting
  in a safer and more maintainable infrastructure;  extended URLs to
  include all (most) parameters pertaining to test workload, such as
  download size, flakiness, etc.

* Respective changes to test_http_server: it is now much more
  independent of particular kind of tests, and more easily
  parametrizable.  Also, generalized several internal methods for better
  readability and extensibility, such as writing of arbitrary payloads,
  parsing headers,

* Migrated common definitions into http_common.{h,cc} (universal
  HTTP-related stuff) and http_fetcher_unittest.h (shared definitions
  pertaining to unit tests).

* Extended direct proxy resolver to generate a list of (non-) proxies,
  so we can unit test proxy failure.  Also, better logging to improve
  testability.

* Some renaming of classes for better consistency.

BUG=chromium-os:18143
TEST=unit tests

Change-Id: Ib90b53394d7e47184d9953df8fc80348921e8af0
Reviewed-on: https://gerrit.chromium.org/gerrit/12092
Commit-Ready: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
diff --git a/http_common.cc b/http_common.cc
new file mode 100644
index 0000000..647faba
--- /dev/null
+++ b/http_common.cc
@@ -0,0 +1,53 @@
+// Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Implementation of common HTTP related functions.
+
+#include "base/basictypes.h"
+
+#include "update_engine/http_common.h"
+
+
+const char *GetHttpResponseDescription(HttpResponseCode code) {
+  static const struct {
+    HttpResponseCode code;
+    const char* description;
+  } http_response_table[] = {
+    { kHttpResponseOk,                  "OK" },
+    { kHttpResponseCreated,             "Created" },
+    { kHttpResponseAccepted,            "Accepted" },
+    { kHttpResponseNonAuthInfo,         "Non-Authoritative Information" },
+    { kHttpResponseNoContent,           "No Content" },
+    { kHttpResponseResetContent,        "Reset Content" },
+    { kHttpResponsePartialContent,      "Partial Content" },
+    { kHttpResponseMultipleChoices,     "Multiple Choices" },
+    { kHttpResponseMovedPermanently,    "Moved Permanently" },
+    { kHttpResponseFound,               "Found" },
+    { kHttpResponseSeeOther,            "See Other" },
+    { kHttpResponseNotModified,         "Not Modified" },
+    { kHttpResponseUseProxy,            "Use Proxy" },
+    { kHttpResponseTempRedirect,        "Temporary Redirect" },
+    { kHttpResponseBadRequest,          "Bad Request" },
+    { kHttpResponseUnauth,              "Unauthorized" },
+    { kHttpResponseForbidden,           "Forbidden" },
+    { kHttpResponseNotFound,            "Not Found" },
+    { kHttpResponseRequestTimeout,      "Request Timeout" },
+    { kHttpResponseInternalServerError, "Internal Server Error" },
+    { kHttpResponseNotImplemented,      "Not Implemented" },
+    { kHttpResponseServiceUnavailable,  "Service Unavailable" },
+    { kHttpResponseVersionNotSupported, "HTTP Version Not Supported" },
+  };
+
+  bool is_found = false;
+  size_t i;
+  for (i = 0; i < ARRAYSIZE_UNSAFE(http_response_table); i++)
+    if ((is_found = (http_response_table[i].code == code)))
+      break;
+
+  return (is_found ? http_response_table[i].description : "(unsupported)");
+}
+
+HttpResponseCode StringToHttpResponseCode(const char *s) {
+  return static_cast<HttpResponseCode>(strtoul(s, NULL, 10));
+}