Changed the http::Headers to be a derived class from Hashmap. The http::Headers should simply derive from the Hashmap class so that all other projects (e.g., an isolator module using libprocess) will not be broken by the recent http::Headers change (it was changed from a hashmap to a class recently in https://reviews.apache.org/r/56116/).
Review: https://reviews.apache.org/r/56609/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/75340d70 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/75340d70 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/75340d70 Branch: refs/heads/1.2.x Commit: 75340d705414a944e2c55eb0590de6870b1d705e Parents: 637b3c6 Author: Gilbert Song <[email protected]> Authored: Thu Feb 23 16:18:36 2017 -0800 Committer: Jie Yu <[email protected]> Committed: Thu Feb 23 17:05:49 2017 -0800 ---------------------------------------------------------------------- 3rdparty/libprocess/include/process/http.hpp | 64 ++++++++++------------ 3rdparty/libprocess/src/http.cpp | 65 ----------------------- 3rdparty/libprocess/src/tests/http_tests.cpp | 18 +++---- 3 files changed, 36 insertions(+), 111 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/75340d70/3rdparty/libprocess/include/process/http.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/http.hpp b/3rdparty/libprocess/include/process/http.hpp index 3a40696..52828ee 100644 --- a/3rdparty/libprocess/include/process/http.hpp +++ b/3rdparty/libprocess/include/process/http.hpp @@ -451,20 +451,38 @@ private: } // namespace header { -class Headers +class Headers : public hashmap< + std::string, + std::string, + CaseInsensitiveHash, + CaseInsensitiveEqual> { public: - typedef hashmap< - std::string, - std::string, - CaseInsensitiveHash, - CaseInsensitiveEqual> Type; - Headers() {} - Headers(const Type& _headers) : headers(_headers) {} + + Headers(const std::map<std::string, std::string>& map) + : hashmap< + std::string, + std::string, + CaseInsensitiveHash, + CaseInsensitiveEqual>(map) {} + + Headers(std::map<std::string, std::string>&& map) + : hashmap< + std::string, + std::string, + CaseInsensitiveHash, + CaseInsensitiveEqual>(map) {} + + Headers(std::initializer_list<std::pair<std::string, std::string>> list) + : hashmap< + std::string, + std::string, + CaseInsensitiveHash, + CaseInsensitiveEqual>(list) {} template <typename T> - Result<T> get() const + Result<T> header() const { Option<std::string> value = get(T::NAME); if (value.isNone()) { @@ -476,34 +494,6 @@ public: } return header.get(); } - - Headers& operator=(const Type& _headers); - - std::string& operator[](const std::string& key); - - void put(const std::string& key, const std::string& value); - - Option<std::string> get(const std::string& key) const; - - std::string& at(const std::string& key); - - const std::string& at(const std::string& key) const; - - bool contains(const std::string& key) const; - - size_t size() const; - - bool empty() const; - - void clear(); - - typename Type::iterator begin() { return headers.begin(); } - typename Type::iterator end() { return headers.end(); } - typename Type::const_iterator begin() const { return headers.cbegin(); } - typename Type::const_iterator end() const { return headers.cend(); } - -private: - Type headers; }; http://git-wip-us.apache.org/repos/asf/mesos/blob/75340d70/3rdparty/libprocess/src/http.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/http.cpp b/3rdparty/libprocess/src/http.cpp index 0e37936..e17ad22 100644 --- a/3rdparty/libprocess/src/http.cpp +++ b/3rdparty/libprocess/src/http.cpp @@ -649,71 +649,6 @@ hashmap<string, string> WWWAuthenticate::authParam() } // namespace header { -Headers& Headers::operator=(const Headers::Type& _headers) -{ - headers = _headers; - return *this; -} - - -string& Headers::operator[](const string& key) -{ - return headers[key]; -} - - -void Headers::put(const string& key, const string& value) -{ - headers.put(key, value); -} - - -Option<string> Headers::get(const string& key) const -{ - if (headers.contains(key)) { - return headers.at(key); - } - - return None(); -} - - -string& Headers::at(const string& key) -{ - return headers.at(key); -} - - -const string& Headers::at(const string& key) const -{ - return headers.at(key); -} - - -bool Headers::contains(const string& key) const -{ - return headers.contains(key); -} - - -size_t Headers::size() const -{ - return headers.size(); -} - - -bool Headers::empty() const -{ - return headers.empty(); -} - - -void Headers::clear() -{ - headers.clear(); -} - - OK::OK(const JSON::Value& value, const Option<string>& jsonp) : Response(Status::OK) { http://git-wip-us.apache.org/repos/asf/mesos/blob/75340d70/3rdparty/libprocess/src/tests/http_tests.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/tests/http_tests.cpp b/3rdparty/libprocess/src/tests/http_tests.cpp index fb4da9a..71e8ad6 100644 --- a/3rdparty/libprocess/src/tests/http_tests.cpp +++ b/3rdparty/libprocess/src/tests/http_tests.cpp @@ -1527,7 +1527,7 @@ TEST_P(HTTPTest, WWWAuthenticateHeader) headers["Www-Authenticate"] = "Basic realm=\"basic-realm\""; Result<http::header::WWWAuthenticate> header = - headers.get<http::header::WWWAuthenticate>(); + headers.header<http::header::WWWAuthenticate>(); ASSERT_SOME(header); @@ -1536,7 +1536,7 @@ TEST_P(HTTPTest, WWWAuthenticateHeader) EXPECT_EQ("basic-realm", header->authParam()["realm"]); headers.clear(); - header = headers.get<http::header::WWWAuthenticate>(); + header = headers.header<http::header::WWWAuthenticate>(); EXPECT_NONE(header); @@ -1545,7 +1545,7 @@ TEST_P(HTTPTest, WWWAuthenticateHeader) "service=\"registry.docker.io\"," "scope=\"repository:gilbertsong/inky:pull\""; - header = headers.get<http::header::WWWAuthenticate>(); + header = headers.header<http::header::WWWAuthenticate>(); ASSERT_SOME(header); @@ -1556,32 +1556,32 @@ TEST_P(HTTPTest, WWWAuthenticateHeader) EXPECT_EQ("repository:gilbertsong/inky:pull", header->authParam()["scope"]); headers["Www-Authenticate"] = ""; - header = headers.get<http::header::WWWAuthenticate>(); + header = headers.header<http::header::WWWAuthenticate>(); EXPECT_ERROR(header); headers["Www-Authenticate"] = " "; - header = headers.get<http::header::WWWAuthenticate>(); + header = headers.header<http::header::WWWAuthenticate>(); EXPECT_ERROR(header); headers["Www-Authenticate"] = "Digest"; - header = headers.get<http::header::WWWAuthenticate>(); + header = headers.header<http::header::WWWAuthenticate>(); EXPECT_ERROR(header); headers["Www-Authenticate"] = "Digest ="; - header = headers.get<http::header::WWWAuthenticate>(); + header = headers.header<http::header::WWWAuthenticate>(); EXPECT_ERROR(header); headers["Www-Authenticate"] = "Digest ,,"; - header = headers.get<http::header::WWWAuthenticate>(); + header = headers.header<http::header::WWWAuthenticate>(); EXPECT_ERROR(header); headers["Www-Authenticate"] = "Digest uri=\"/dir/index.html\",qop=auth"; - header = headers.get<http::header::WWWAuthenticate>(); + header = headers.header<http::header::WWWAuthenticate>(); EXPECT_ERROR(header); }
