proxygen
HTTPTime.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
11 
12 #include <glog/logging.h>
13 
14 #include <folly/portability/Time.h>
15 
16 namespace proxygen {
17 
19  struct tm tm = {};
20 
21  if (s.empty()) {
22  return folly::none;
23  }
24 
25  // Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
26  // Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
27  // Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
28  // Assume GMT as per rfc2616 (see HTTP-date):
29  // - https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html
30  if (strptime(s.c_str(), "%a, %d %b %Y %H:%M:%S GMT", &tm) != nullptr ||
31  strptime(s.c_str(), "%a, %d-%b-%y %H:%M:%S GMT", &tm) != nullptr ||
32  strptime(s.c_str(), "%a %b %d %H:%M:%S %Y", &tm) != nullptr) {
33  return folly::Optional<int64_t>(timegm(&tm));
34  }
35 
36  LOG(INFO) << "Invalid http time: " << s;
37  return folly::none;
38 }
39 
40 } // proxygen
const char * string
Definition: Conv.cpp:212
static set< string > s
folly::Optional< int64_t > parseHTTPDateTime(const std::string &s)
Definition: HTTPTime.cpp:18
constexpr None none
Definition: Optional.h:87