Repository: mesos Updated Branches: refs/heads/master d261076ed -> cb12060a4
Added an overload for `acceptsMediaType()`. This overload allows us to see if a header name with similar semantics as the "Accept" header is acceptable in the response. This would be used for the "Message-Accept" header later. Review: https://reviews.apache.org/r/55936/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/05fbacd3 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/05fbacd3 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/05fbacd3 Branch: refs/heads/master Commit: 05fbacd370848c138eab758cfd8adab87a33ff2e Parents: d261076 Author: Anand Mazumdar <an...@apache.org> Authored: Sun Jan 29 12:49:03 2017 -0800 Committer: Anand Mazumdar <an...@apache.org> Committed: Sun Jan 29 12:49:03 2017 -0800 ---------------------------------------------------------------------- 3rdparty/libprocess/include/process/http.hpp | 19 ++++++++++++-- 3rdparty/libprocess/src/http.cpp | 30 +++++++++++++++++------ 2 files changed, 39 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/05fbacd3/3rdparty/libprocess/include/process/http.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/http.hpp b/3rdparty/libprocess/include/process/http.hpp index e8f53bf..4b11e08 100644 --- a/3rdparty/libprocess/include/process/http.hpp +++ b/3rdparty/libprocess/include/process/http.hpp @@ -477,10 +477,25 @@ struct Request bool acceptsEncoding(const std::string& encoding) const; /** - * Returns whether the media type is considered acceptable in the - * response. See RFC 2616, section 14.1 for the details. + * Returns whether the media type in the "Accept" header is considered + * acceptable in the response. See RFC 2616, section 14.1 for the details. */ bool acceptsMediaType(const std::string& mediaType) const; + + /** + * Returns whether the media type in the `name` header is considered + * acceptable in the response. The media type should have similar + * semantics as the "Accept" header. See RFC 2616, section 14.1 for + * the details. + */ + bool acceptsMediaType( + const std::string& name, + const std::string& mediaType) const; + +private: + bool _acceptsMediaType( + Option<std::string> name, + const std::string& mediaType) const; }; http://git-wip-us.apache.org/repos/asf/mesos/blob/05fbacd3/3rdparty/libprocess/src/http.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/http.cpp b/3rdparty/libprocess/src/http.cpp index f4ae30b..4fd62c8 100644 --- a/3rdparty/libprocess/src/http.cpp +++ b/3rdparty/libprocess/src/http.cpp @@ -333,24 +333,38 @@ bool Request::acceptsEncoding(const string& encoding) const bool Request::acceptsMediaType(const string& mediaType) const { + return _acceptsMediaType(headers.get("Accept"), mediaType); +} + + +bool Request::acceptsMediaType( + const string& name, + const string& mediaType) const +{ + return _acceptsMediaType(headers.get(name), mediaType); +} + + +bool Request::_acceptsMediaType( + Option<string> name, + const string& mediaType) const +{ vector<string> mediaTypes = strings::tokenize(mediaType, "/"); if (mediaTypes.size() != 2) { return false; } - Option<string> accept = headers.get("Accept"); - - // If no Accept header field is present, then it is assumed + // If no header field is present, then it is assumed // that the client accepts all media types. - if (accept.isNone()) { + if (name.isNone()) { return true; } // Remove spaces and tabs for easier parsing. - accept = strings::remove(accept.get(), " "); - accept = strings::remove(accept.get(), "\t"); - accept = strings::remove(accept.get(), "\n"); + name = strings::remove(name.get(), " "); + name = strings::remove(name.get(), "\t"); + name = strings::remove(name.get(), "\n"); // First match 'type/subtype', then 'type/*', then '*/*'. vector<string> candidates; @@ -359,7 +373,7 @@ bool Request::acceptsMediaType(const string& mediaType) const candidates.push_back("*/*"); foreach (const string& candidate, candidates) { - foreach (const string& type, strings::tokenize(accept.get(), ",")) { + foreach (const string& type, strings::tokenize(name.get(), ",")) { vector<string> tokens = strings::tokenize(type, ";"); if (tokens.empty()) {