Delete unused HTTP server code

There were remnants of use in proxy_unittest.cc, instantiating an
HttpListenServer but not using it for anything.

Also trim down httpcommon.h, the only function still in use is
HttpAuthenticate.

Bug: webrtc:6424
Change-Id: I9b122dedd6e8c923ed7bc721a336fe54192328c4
Reviewed-on: https://webrtc-review.googlesource.com/102141
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24884}
diff --git a/rtc_base/httpcommon.cc b/rtc_base/httpcommon.cc
index 40a9cb9..716a41e 100644
--- a/rtc_base/httpcommon.cc
+++ b/rtc_base/httpcommon.cc
@@ -108,154 +108,9 @@
 #undef KLABEL
 #undef LASTLABEL
 #endif  // defined(WEBRTC_WIN)
-}  // namespace
 
-//////////////////////////////////////////////////////////////////////
-// Enum - TODO: expose globally later?
-//////////////////////////////////////////////////////////////////////
-
-bool find_string(size_t& index,
-                 const std::string& needle,
-                 const char* const haystack[],
-                 size_t max_index) {
-  for (index = 0; index < max_index; ++index) {
-    if (_stricmp(needle.c_str(), haystack[index]) == 0) {
-      return true;
-    }
-  }
-  return false;
-}
-
-template <class E>
-struct Enum {
-  static const char** Names;
-  static size_t Size;
-
-  static inline const char* Name(E val) { return Names[val]; }
-  static inline bool Parse(E& val, const std::string& name) {
-    size_t index;
-    if (!find_string(index, name, Names, Size))
-      return false;
-    val = static_cast<E>(index);
-    return true;
-  }
-
-  E val;
-
-  inline operator E&() { return val; }
-  inline Enum& operator=(E rhs) {
-    val = rhs;
-    return *this;
-  }
-
-  inline const char* name() const { return Name(val); }
-  inline bool assign(const std::string& name) { return Parse(val, name); }
-  inline Enum& operator=(const std::string& rhs) {
-    assign(rhs);
-    return *this;
-  }
-};
-
-#define ENUM(e, n)                 \
-  template <>                      \
-  const char** Enum<e>::Names = n; \
-  template <>                      \
-  size_t Enum<e>::Size = sizeof(n) / sizeof(n[0])
-
-//////////////////////////////////////////////////////////////////////
-// HttpCommon
-//////////////////////////////////////////////////////////////////////
-
-static const char* kHttpVersions[HVER_LAST + 1] = {"1.0", "1.1", "Unknown"};
-ENUM(HttpVersion, kHttpVersions);
-
-static const char* kHttpHeaders[HH_LAST + 1] = {
-    "Age",
-    "Cache-Control",
-    "Connection",
-    "Content-Disposition",
-    "Content-Length",
-    "Content-Range",
-    "Content-Type",
-    "Cookie",
-    "Date",
-    "ETag",
-    "Expires",
-    "Host",
-    "If-Modified-Since",
-    "If-None-Match",
-    "Keep-Alive",
-    "Last-Modified",
-    "Location",
-    "Proxy-Authenticate",
-    "Proxy-Authorization",
-    "Proxy-Connection",
-    "Range",
-    "Set-Cookie",
-    "TE",
-    "Trailers",
-    "Transfer-Encoding",
-    "Upgrade",
-    "User-Agent",
-    "WWW-Authenticate",
-};
-ENUM(HttpHeader, kHttpHeaders);
-
-const char* ToString(HttpVersion version) {
-  return Enum<HttpVersion>::Name(version);
-}
-
-bool FromString(HttpVersion& version, const std::string& str) {
-  return Enum<HttpVersion>::Parse(version, str);
-}
-
-const char* ToString(HttpHeader header) {
-  return Enum<HttpHeader>::Name(header);
-}
-
-bool FromString(HttpHeader& header, const std::string& str) {
-  return Enum<HttpHeader>::Parse(header, str);
-}
-
-bool HttpHeaderIsEndToEnd(HttpHeader header) {
-  switch (header) {
-    case HH_CONNECTION:
-    case HH_KEEP_ALIVE:
-    case HH_PROXY_AUTHENTICATE:
-    case HH_PROXY_AUTHORIZATION:
-    case HH_PROXY_CONNECTION:  // Note part of RFC... this is non-standard
-                               // header
-    case HH_TE:
-    case HH_TRAILERS:
-    case HH_TRANSFER_ENCODING:
-    case HH_UPGRADE:
-      return false;
-    default:
-      return true;
-  }
-}
-
-bool HttpHeaderIsCollapsible(HttpHeader header) {
-  switch (header) {
-    case HH_SET_COOKIE:
-    case HH_PROXY_AUTHENTICATE:
-    case HH_WWW_AUTHENTICATE:
-      return false;
-    default:
-      return true;
-  }
-}
-
-bool HttpShouldKeepAlive(const HttpData& data) {
-  std::string connection;
-  if ((data.hasHeader(HH_PROXY_CONNECTION, &connection) ||
-       data.hasHeader(HH_CONNECTION, &connection))) {
-    return (_stricmp(connection.c_str(), "Keep-Alive") == 0);
-  }
-  return (data.version >= HVER_1_1);
-}
-
-namespace {
+typedef std::pair<std::string, std::string> HttpAttribute;
+typedef std::vector<HttpAttribute> HttpAttributeList;
 
 inline bool IsEndOfAttributeName(size_t pos, size_t len, const char* data) {
   if (pos >= len)
@@ -272,8 +127,6 @@
   return false;
 }
 
-}  // anonymous namespace
-
 void HttpParseAttributes(const char* data,
                          size_t len,
                          HttpAttributeList& attributes) {
@@ -354,274 +207,6 @@
   return true;
 }
 
-bool HttpDateToSeconds(const std::string& date, time_t* seconds) {
-  const char* const kTimeZones[] = {
-      "UT",  "GMT", "EST", "EDT", "CST", "CDT", "MST", "MDT", "PST",
-      "PDT", "A",   "B",   "C",   "D",   "E",   "F",   "G",   "H",
-      "I",   "K",   "L",   "M",   "N",   "O",   "P",   "Q",   "R",
-      "S",   "T",   "U",   "V",   "W",   "X",   "Y"};
-  const int kTimeZoneOffsets[] = {
-      0,  0,  -5,  -4,  -6,  -5, -7, -6, -8, -7, -1, -2, -3, -4, -5, -6, -7,
-      -8, -9, -10, -11, -12, 1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12};
-
-  RTC_DCHECK(nullptr != seconds);
-  struct tm tval;
-  memset(&tval, 0, sizeof(tval));
-  char month[4], zone[6];
-  memset(month, 0, sizeof(month));
-  memset(zone, 0, sizeof(zone));
-
-  if (7 != sscanf(date.c_str(), "%*3s, %d %3s %d %d:%d:%d %5c", &tval.tm_mday,
-                  month, &tval.tm_year, &tval.tm_hour, &tval.tm_min,
-                  &tval.tm_sec, zone)) {
-    return false;
-  }
-  switch (toupper(month[2])) {
-    case 'N':
-      tval.tm_mon = (month[1] == 'A') ? 0 : 5;
-      break;
-    case 'B':
-      tval.tm_mon = 1;
-      break;
-    case 'R':
-      tval.tm_mon = (month[0] == 'M') ? 2 : 3;
-      break;
-    case 'Y':
-      tval.tm_mon = 4;
-      break;
-    case 'L':
-      tval.tm_mon = 6;
-      break;
-    case 'G':
-      tval.tm_mon = 7;
-      break;
-    case 'P':
-      tval.tm_mon = 8;
-      break;
-    case 'T':
-      tval.tm_mon = 9;
-      break;
-    case 'V':
-      tval.tm_mon = 10;
-      break;
-    case 'C':
-      tval.tm_mon = 11;
-      break;
-  }
-  tval.tm_year -= 1900;
-  time_t gmt, non_gmt = mktime(&tval);
-  if ((zone[0] == '+') || (zone[0] == '-')) {
-    if (!isdigit(zone[1]) || !isdigit(zone[2]) || !isdigit(zone[3]) ||
-        !isdigit(zone[4])) {
-      return false;
-    }
-    int hours = (zone[1] - '0') * 10 + (zone[2] - '0');
-    int minutes = (zone[3] - '0') * 10 + (zone[4] - '0');
-    int offset = (hours * 60 + minutes) * 60;
-    gmt = non_gmt + ((zone[0] == '+') ? offset : -offset);
-  } else {
-    size_t zindex;
-    if (!find_string(zindex, zone, kTimeZones, arraysize(kTimeZones))) {
-      return false;
-    }
-    gmt = non_gmt + kTimeZoneOffsets[zindex] * 60 * 60;
-  }
-// TODO: Android should support timezone, see b/2441195
-#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) || defined(WEBRTC_ANDROID) || \
-    defined(BSD)
-  tm* tm_for_timezone = localtime(&gmt);
-  *seconds = gmt + tm_for_timezone->tm_gmtoff;
-#else
-#if defined(_MSC_VER) && _MSC_VER >= 1900
-  long timezone = 0;
-  _get_timezone(&timezone);
-#endif
-  *seconds = gmt - timezone;
-#endif
-  return true;
-}
-
-std::string HttpAddress(const SocketAddress& address, bool secure) {
-  return (address.port() == HttpDefaultPort(secure)) ? address.hostname()
-                                                     : address.ToString();
-}
-
-//////////////////////////////////////////////////////////////////////
-// HttpData
-//////////////////////////////////////////////////////////////////////
-
-HttpData::HttpData() : version(HVER_1_1) {}
-
-HttpData::~HttpData() = default;
-
-void HttpData::clear(bool release_document) {
-  // Clear headers first, since releasing a document may have far-reaching
-  // effects.
-  headers_.clear();
-  if (release_document) {
-    document.reset();
-  }
-}
-
-void HttpData::changeHeader(const std::string& name,
-                            const std::string& value,
-                            HeaderCombine combine) {
-  if (combine == HC_AUTO) {
-    HttpHeader header;
-    // Unrecognized headers are collapsible
-    combine = !FromString(header, name) || HttpHeaderIsCollapsible(header)
-                  ? HC_YES
-                  : HC_NO;
-  } else if (combine == HC_REPLACE) {
-    headers_.erase(name);
-    combine = HC_NO;
-  }
-  // At this point, combine is one of (YES, NO, NEW)
-  if (combine != HC_NO) {
-    HeaderMap::iterator it = headers_.find(name);
-    if (it != headers_.end()) {
-      if (combine == HC_YES) {
-        it->second.append(",");
-        it->second.append(value);
-      }
-      return;
-    }
-  }
-  headers_.insert(HeaderMap::value_type(name, value));
-}
-
-size_t HttpData::clearHeader(const std::string& name) {
-  return headers_.erase(name);
-}
-
-HttpData::iterator HttpData::clearHeader(iterator header) {
-  iterator deprecated = header++;
-  headers_.erase(deprecated);
-  return header;
-}
-
-bool HttpData::hasHeader(const std::string& name, std::string* value) const {
-  HeaderMap::const_iterator it = headers_.find(name);
-  if (it == headers_.end()) {
-    return false;
-  } else if (value) {
-    *value = it->second;
-  }
-  return true;
-}
-
-//
-// HttpRequestData
-//
-
-void HttpRequestData::clear(bool release_document) {
-  path.clear();
-  HttpData::clear(release_document);
-}
-
-size_t HttpRequestData::formatLeader(char* buffer, size_t size) const {
-  RTC_DCHECK(path.find(' ') == std::string::npos);
-  return sprintfn(buffer, size, "GET %.*s HTTP/%s", path.size(), path.data(),
-                  ToString(version));
-}
-
-HttpError HttpRequestData::parseLeader(const char* line, size_t len) {
-  unsigned int vmajor, vminor;
-  int vend, dstart, dend;
-  // sscanf isn't safe with strings that aren't null-terminated, and there is
-  // no guarantee that |line| is. Create a local copy that is null-terminated.
-  std::string line_str(line, len);
-  line = line_str.c_str();
-  if ((sscanf(line, "%*s%n %n%*s%n HTTP/%u.%u", &vend, &dstart, &dend, &vmajor,
-              &vminor) != 2) ||
-      (vmajor != 1)) {
-    return HE_PROTOCOL;
-  }
-  if (vminor == 0) {
-    version = HVER_1_0;
-  } else if (vminor == 1) {
-    version = HVER_1_1;
-  } else {
-    return HE_PROTOCOL;
-  }
-  if (vend != 3 || memcmp(line, "GET", 3)) {
-    return HE_PROTOCOL;  // !?! HC_METHOD_NOT_SUPPORTED?
-  }
-  path.assign(line + dstart, line + dend);
-  return HE_NONE;
-}
-
-//
-// HttpResponseData
-//
-
-void HttpResponseData::clear(bool release_document) {
-  scode = HC_INTERNAL_SERVER_ERROR;
-  message.clear();
-  HttpData::clear(release_document);
-}
-
-void HttpResponseData::set_success(uint32_t scode) {
-  this->scode = scode;
-  message.clear();
-  setHeader(HH_CONTENT_LENGTH, "0", false);
-}
-
-void HttpResponseData::set_error(uint32_t scode) {
-  this->scode = scode;
-  message.clear();
-  setHeader(HH_CONTENT_LENGTH, "0", false);
-}
-
-size_t HttpResponseData::formatLeader(char* buffer, size_t size) const {
-  size_t len = sprintfn(buffer, size, "HTTP/%s %lu", ToString(version), scode);
-  if (!message.empty()) {
-    len += sprintfn(buffer + len, size - len, " %.*s", message.size(),
-                    message.data());
-  }
-  return len;
-}
-
-HttpError HttpResponseData::parseLeader(const char* line, size_t len) {
-  size_t pos = 0;
-  unsigned int vmajor, vminor, temp_scode;
-  int temp_pos;
-  // sscanf isn't safe with strings that aren't null-terminated, and there is
-  // no guarantee that |line| is. Create a local copy that is null-terminated.
-  std::string line_str(line, len);
-  line = line_str.c_str();
-  if (sscanf(line, "HTTP %u%n", &temp_scode, &temp_pos) == 1) {
-    // This server's response has no version. :( NOTE: This happens for every
-    // response to requests made from Chrome plugins, regardless of the server's
-    // behaviour.
-    RTC_LOG(LS_VERBOSE) << "HTTP version missing from response";
-    version = HVER_UNKNOWN;
-  } else if ((sscanf(line, "HTTP/%u.%u %u%n", &vmajor, &vminor, &temp_scode,
-                     &temp_pos) == 3) &&
-             (vmajor == 1)) {
-    // This server's response does have a version.
-    if (vminor == 0) {
-      version = HVER_1_0;
-    } else if (vminor == 1) {
-      version = HVER_1_1;
-    } else {
-      return HE_PROTOCOL;
-    }
-  } else {
-    return HE_PROTOCOL;
-  }
-  scode = temp_scode;
-  pos = static_cast<size_t>(temp_pos);
-  while ((pos < len) && isspace(static_cast<unsigned char>(line[pos])))
-    ++pos;
-  message.assign(line + pos, len - pos);
-  return HE_NONE;
-}
-
-//////////////////////////////////////////////////////////////////////
-// Http Authentication
-//////////////////////////////////////////////////////////////////////
-
 std::string quote(const std::string& str) {
   std::string result;
   result.push_back('"');
@@ -655,6 +240,8 @@
 };
 #endif  // WEBRTC_WIN
 
+}  // anonymous namespace
+
 HttpAuthResult HttpAuthenticate(const char* challenge,
                                 size_t len,
                                 const SocketAddress& server,