From aa2c915c965437d51e4ed18ea696de726839749f Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sun, 4 Jun 2017 10:52:28 -0700 Subject: [PATCH] Canonicalize string_view parameter types --- CHANGELOG.md | 1 + include/beast/http/basic_parser.hpp | 4 +- .../beast/http/detail/basic_parsed_list.hpp | 2 +- include/beast/http/detail/basic_parser.hpp | 6 +- include/beast/http/detail/fields.hpp | 8 +-- include/beast/http/detail/rfc7230.hpp | 4 +- include/beast/http/fields.hpp | 16 +++--- include/beast/http/impl/basic_parser.ipp | 4 +- include/beast/http/impl/fields.ipp | 12 ++-- include/beast/http/impl/rfc7230.ipp | 4 +- include/beast/http/parser.hpp | 16 +++--- include/beast/http/rfc7230.hpp | 6 +- .../beast/websocket/detail/pmd_extension.hpp | 2 +- include/beast/websocket/impl/handshake.ipp | 52 ++++++++--------- include/beast/websocket/impl/stream.ipp | 8 +-- include/beast/websocket/stream.hpp | 56 +++++++++---------- test/http/basic_parser.cpp | 6 +- test/http/message_fuzz.hpp | 2 +- test/http/parser_bench.cpp | 14 ++--- test/http/rfc7230.cpp | 12 ++-- test/http/test_parser.hpp | 14 ++--- test/websocket/stream.cpp | 32 +++++------ 22 files changed, 141 insertions(+), 140 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd0f246a..bbfb7372 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Version 49 API Changes: * Refactor method and verb +* Canonicalize string_view parameter types -------------------------------------------------------------------------------- diff --git a/include/beast/http/basic_parser.hpp b/include/beast/http/basic_parser.hpp index 75a62535..0d9ebebd 100644 --- a/include/beast/http/basic_parser.hpp +++ b/include/beast/http/basic_parser.hpp @@ -463,8 +463,8 @@ private: char const* last, error_code& ec); void - do_field(string_view const& name, - string_view const& value, + do_field(string_view name, + string_view value, error_code& ec); }; diff --git a/include/beast/http/detail/basic_parsed_list.hpp b/include/beast/http/detail/basic_parsed_list.hpp index 5f75790b..4026e158 100644 --- a/include/beast/http/detail/basic_parsed_list.hpp +++ b/include/beast/http/detail/basic_parsed_list.hpp @@ -128,7 +128,7 @@ public: /// Construct a list from a string explicit - basic_parsed_list(string_view const& s) + basic_parsed_list(string_view s) : s_(s) { } diff --git a/include/beast/http/detail/basic_parser.hpp b/include/beast/http/detail/basic_parser.hpp index d51016f4..1a475868 100644 --- a/include/beast/http/detail/basic_parser.hpp +++ b/include/beast/http/detail/basic_parser.hpp @@ -211,8 +211,8 @@ protected: template static bool - strieq(string_view const& s1, - string_view const& s2) + strieq(string_view s1, + string_view s2) { if(s1.size() != s2.size()) return false; @@ -227,7 +227,7 @@ protected: template bool strieq(const char (&s1)[N], - string_view const& s2) + string_view s2) { return strieq({s1, N-1}, s2); } diff --git a/include/beast/http/detail/fields.hpp b/include/beast/http/detail/fields.hpp index 906f3cc3..a83e95a7 100644 --- a/include/beast/http/detail/fields.hpp +++ b/include/beast/http/detail/fields.hpp @@ -29,8 +29,8 @@ public: std::string first; std::string second; - value_type(string_view const& name_, - string_view const& value_) + value_type(string_view name_, + string_view value_) : first(name_) , second(value_) { @@ -63,8 +63,8 @@ protected: { value_type data; - element(string_view const& name, - string_view const& value) + element(string_view name, + string_view value) : data(name, value) { } diff --git a/include/beast/http/detail/rfc7230.hpp b/include/beast/http/detail/rfc7230.hpp index b00cc448..b4d536e2 100644 --- a/include/beast/http/detail/rfc7230.hpp +++ b/include/beast/http/detail/rfc7230.hpp @@ -329,7 +329,7 @@ skip_token(FwdIt& it, FwdIt const& last) inline string_view -trim(string_view const& s) +trim(string_view s) { auto first = s.begin(); auto last = s.end(); @@ -459,7 +459,7 @@ struct opt_token_list_policy bool operator()(value_type& v, - char const*& it, string_view const& s) const + char const*& it, string_view s) const { v = {}; auto need_comma = it != s.begin(); diff --git a/include/beast/http/fields.hpp b/include/beast/http/fields.hpp index 3784c9de..aa9869a9 100644 --- a/include/beast/http/fields.hpp +++ b/include/beast/http/fields.hpp @@ -177,14 +177,14 @@ public: /// Returns `true` if the specified field exists. bool - exists(string_view const& name) const + exists(string_view name) const { return set_.find(name, less{}) != set_.end(); } /// Returns the number of values for the specified field. std::size_t - count(string_view const& name) const; + count(string_view name) const; /** Returns an iterator to the case-insensitive matching field name. @@ -192,7 +192,7 @@ public: first field defined by insertion order is returned. */ iterator - find(string_view const& name) const; + find(string_view name) const; /** Returns the value for a case-insensitive matching header, or `""`. @@ -200,7 +200,7 @@ public: first field defined by insertion order is returned. */ string_view const - operator[](string_view const& name) const; + operator[](string_view name) const; /// Clear the contents of the basic_fields. void @@ -216,7 +216,7 @@ public: @return The number of fields removed. */ std::size_t - erase(string_view const& name); + erase(string_view name); /** Insert a field value. @@ -229,7 +229,7 @@ public: @param value A string holding the value of the field. */ void - insert(string_view const& name, string_view value); + insert(string_view name, string_view value); /** Insert a field value. @@ -260,7 +260,7 @@ public: @param value A string holding the value of the field. */ void - replace(string_view const& name, string_view value); + replace(string_view name, string_view value); /** Replace a field value. @@ -275,7 +275,7 @@ public: template typename std::enable_if< ! std::is_constructible::value>::type - replace(string_view const& name, T const& value) + replace(string_view name, T const& value) { replace(name, boost::lexical_cast(value)); diff --git a/include/beast/http/impl/basic_parser.ipp b/include/beast/http/impl/basic_parser.ipp index 1ee80a70..51a94866 100644 --- a/include/beast/http/impl/basic_parser.ipp +++ b/include/beast/http/impl/basic_parser.ipp @@ -739,8 +739,8 @@ template void basic_parser:: do_field( - string_view const& name, - string_view const& value, + string_view name, + string_view value, error_code& ec) { // Connection diff --git a/include/beast/http/impl/fields.ipp b/include/beast/http/impl/fields.ipp index ef78d693..9e23de45 100644 --- a/include/beast/http/impl/fields.ipp +++ b/include/beast/http/impl/fields.ipp @@ -161,7 +161,7 @@ operator=(basic_fields const& other) -> template std::size_t basic_fields:: -count(string_view const& name) const +count(string_view name) const { auto const it = set_.find(name, less{}); if(it == set_.end()) @@ -173,7 +173,7 @@ count(string_view const& name) const template auto basic_fields:: -find(string_view const& name) const -> +find(string_view name) const -> iterator { auto const it = set_.find(name, less{}); @@ -185,7 +185,7 @@ find(string_view const& name) const -> template string_view const basic_fields:: -operator[](string_view const& name) const +operator[](string_view name) const { auto const it = find(name); if(it == end()) @@ -206,7 +206,7 @@ clear() noexcept template std::size_t basic_fields:: -erase(string_view const& name) +erase(string_view name) { auto it = set_.find(name, less{}); if(it == set_.end()) @@ -230,7 +230,7 @@ erase(string_view const& name) template void basic_fields:: -insert(string_view const& name, +insert(string_view name, string_view value) { value = detail::trim(value); @@ -243,7 +243,7 @@ insert(string_view const& name, template void basic_fields:: -replace(string_view const& name, +replace(string_view name, string_view value) { value = detail::trim(value); diff --git a/include/beast/http/impl/rfc7230.ipp b/include/beast/http/impl/rfc7230.ipp index 151d2dda..758122a3 100644 --- a/include/beast/http/impl/rfc7230.ipp +++ b/include/beast/http/impl/rfc7230.ipp @@ -87,7 +87,7 @@ private: template static std::string - unquote(string_view const& sr); + unquote(string_view sr); template void @@ -133,7 +133,7 @@ cend() const -> template std::string param_list::const_iterator:: -unquote(string_view const& sr) +unquote(string_view sr) { std::string s; s.reserve(sr.size()); diff --git a/include/beast/http/parser.hpp b/include/beast/http/parser.hpp index 313a5b03..13edb2e1 100644 --- a/include/beast/http/parser.hpp +++ b/include/beast/http/parser.hpp @@ -187,7 +187,7 @@ private: void on_chunk(std::uint64_t, - string_view const&, error_code&) + string_view, error_code&) { body_ = {}; } @@ -331,8 +331,8 @@ private: void on_request( - string_view const& method, - string_view const& target, + string_view method, + string_view target, int version, error_code&) { m_.target(target); @@ -342,7 +342,7 @@ private: void on_response(int status, - string_view const& reason, + string_view reason, int version, error_code&) { m_.status = status; @@ -351,8 +351,8 @@ private: } void - on_field(string_view const& name, - string_view const& value, + on_field(string_view name, + string_view value, error_code&) { m_.fields.insert(name, value); @@ -373,7 +373,7 @@ private: } void - on_data(string_view const& s, + on_data(string_view s, error_code& ec) { wr_->put(boost::asio::buffer( @@ -382,7 +382,7 @@ private: void on_chunk( - std::uint64_t, string_view const&, + std::uint64_t, string_view, error_code&) { } diff --git a/include/beast/http/rfc7230.hpp b/include/beast/http/rfc7230.hpp index b16c6f0f..e2d3f3fb 100644 --- a/include/beast/http/rfc7230.hpp +++ b/include/beast/http/rfc7230.hpp @@ -77,7 +77,7 @@ public: must remain valid for the lifetime of the container. */ explicit - param_list(string_view const& s) + param_list(string_view s) : s_(s) { } @@ -163,7 +163,7 @@ public: must remain valid for the lifetime of the container. */ explicit - ext_list(string_view const& s) + ext_list(string_view s) : s_(s) { } @@ -251,7 +251,7 @@ public: must remain valid for the lifetime of the container. */ explicit - token_list(string_view const& s) + token_list(string_view s) : s_(s) { } diff --git a/include/beast/websocket/detail/pmd_extension.hpp b/include/beast/websocket/detail/pmd_extension.hpp index 56c5cb5b..489a7f38 100644 --- a/include/beast/websocket/detail/pmd_extension.hpp +++ b/include/beast/websocket/detail/pmd_extension.hpp @@ -47,7 +47,7 @@ struct pmd_offer template int -parse_bits(string_view const& s) +parse_bits(string_view s) { if(s.size() == 0) return -1; diff --git a/include/beast/websocket/impl/handshake.ipp b/include/beast/websocket/impl/handshake.ipp index bc17c906..cae20f99 100644 --- a/include/beast/websocket/impl/handshake.ipp +++ b/include/beast/websocket/impl/handshake.ipp @@ -47,8 +47,8 @@ class stream::handshake_op template data(Handler& handler, stream& ws_, response_type* res_p_, - string_view const& host, - string_view const& target, + string_view host, + string_view target, Decorator const& decorator) : ws(ws_) , res_p(res_p_) @@ -171,8 +171,8 @@ template async_return_type< HandshakeHandler, void(error_code)> stream:: -async_handshake(string_view const& host, - string_view const& target, +async_handshake(string_view host, + string_view target, HandshakeHandler&& handler) { static_assert(is_async_stream::value, @@ -192,8 +192,8 @@ async_return_type< HandshakeHandler, void(error_code)> stream:: async_handshake(response_type& res, - string_view const& host, - string_view const& target, + string_view host, + string_view target, HandshakeHandler&& handler) { static_assert(is_async_stream::value, @@ -212,8 +212,8 @@ template async_return_type< HandshakeHandler, void(error_code)> stream:: -async_handshake_ex(string_view const& host, - string_view const& target, +async_handshake_ex(string_view host, + string_view target, RequestDecorator const& decorator, HandshakeHandler&& handler) { @@ -237,8 +237,8 @@ async_return_type< HandshakeHandler, void(error_code)> stream:: async_handshake_ex(response_type& res, - string_view const& host, - string_view const& target, + string_view host, + string_view target, RequestDecorator const& decorator, HandshakeHandler&& handler) { @@ -259,8 +259,8 @@ async_handshake_ex(response_type& res, template void stream:: -handshake(string_view const& host, - string_view const& target) +handshake(string_view host, + string_view target) { static_assert(is_sync_stream::value, "SyncStream requirements not met"); @@ -275,8 +275,8 @@ template void stream:: handshake(response_type& res, - string_view const& host, - string_view const& target) + string_view host, + string_view target) { static_assert(is_sync_stream::value, "SyncStream requirements not met"); @@ -290,8 +290,8 @@ template template void stream:: -handshake_ex(string_view const& host, - string_view const& target, +handshake_ex(string_view host, + string_view target, RequestDecorator const& decorator) { static_assert(is_sync_stream::value, @@ -310,8 +310,8 @@ template void stream:: handshake_ex(response_type& res, - string_view const& host, - string_view const& target, + string_view host, + string_view target, RequestDecorator const& decorator) { static_assert(is_sync_stream::value, @@ -328,8 +328,8 @@ handshake_ex(response_type& res, template void stream:: -handshake(string_view const& host, - string_view const& target, error_code& ec) +handshake(string_view host, + string_view target, error_code& ec) { static_assert(is_sync_stream::value, "SyncStream requirements not met"); @@ -341,8 +341,8 @@ template void stream:: handshake(response_type& res, - string_view const& host, - string_view const& target, + string_view host, + string_view target, error_code& ec) { static_assert(is_sync_stream::value, @@ -355,8 +355,8 @@ template template void stream:: -handshake_ex(string_view const& host, - string_view const& target, +handshake_ex(string_view host, + string_view target, RequestDecorator const& decorator, error_code& ec) { @@ -374,8 +374,8 @@ template void stream:: handshake_ex(response_type& res, - string_view const& host, - string_view const& target, + string_view host, + string_view target, RequestDecorator const& decorator, error_code& ec) { diff --git a/include/beast/websocket/impl/stream.ipp b/include/beast/websocket/impl/stream.ipp index 8ce4422c..dc533ffa 100644 --- a/include/beast/websocket/impl/stream.ipp +++ b/include/beast/websocket/impl/stream.ipp @@ -128,8 +128,8 @@ template void stream:: do_handshake(response_type* res_p, - string_view const& host, - string_view const& target, + string_view host, + string_view target, RequestDecorator const& decorator, error_code& ec) { @@ -157,8 +157,8 @@ template request_type stream:: build_request(detail::sec_ws_key_type& key, - string_view const& host, - string_view const& target, + string_view host, + string_view target, Decorator const& decorator) { request_type req; diff --git a/include/beast/websocket/stream.hpp b/include/beast/websocket/stream.hpp index 773d5697..bf565d8e 100644 --- a/include/beast/websocket/stream.hpp +++ b/include/beast/websocket/stream.hpp @@ -1471,8 +1471,8 @@ public: @endcode */ void - handshake(string_view const& host, - string_view const& target); + handshake(string_view host, + string_view target); /** Send an HTTP WebSocket Upgrade request and receive the response. @@ -1519,8 +1519,8 @@ public: */ void handshake(response_type& res, - string_view const& host, - string_view const& target); + string_view host, + string_view target); /** Send an HTTP WebSocket Upgrade request and receive the response. @@ -1576,8 +1576,8 @@ public: */ template void - handshake_ex(string_view const& host, - string_view const& target, + handshake_ex(string_view host, + string_view target, RequestDecorator const& decorator); /** Send an HTTP WebSocket Upgrade request and receive the response. @@ -1639,8 +1639,8 @@ public: template void handshake_ex(response_type& res, - string_view const& host, - string_view const& target, + string_view host, + string_view target, RequestDecorator const& decorator); /** Send an HTTP WebSocket Upgrade request and receive the response. @@ -1681,8 +1681,8 @@ public: @endcode */ void - handshake(string_view const& host, - string_view const& target, error_code& ec); + handshake(string_view host, + string_view target, error_code& ec); /** Send an HTTP WebSocket Upgrade request and receive the response. @@ -1727,8 +1727,8 @@ public: */ void handshake(response_type& res, - string_view const& host, - string_view const& target, + string_view host, + string_view target, error_code& ec); /** Send an HTTP WebSocket Upgrade request and receive the response. @@ -1784,8 +1784,8 @@ public: */ template void - handshake_ex(string_view const& host, - string_view const& target, + handshake_ex(string_view host, + string_view target, RequestDecorator const& decorator, error_code& ec); @@ -1847,8 +1847,8 @@ public: template void handshake_ex(response_type& res, - string_view const& host, - string_view const& target, + string_view host, + string_view target, RequestDecorator const& decorator, error_code& ec); @@ -1899,8 +1899,8 @@ public: async_return_type< HandshakeHandler, void(error_code)> #endif - async_handshake(string_view const& host, - string_view const& target, + async_handshake(string_view host, + string_view target, HandshakeHandler&& handler); /** Start an asynchronous operation to send an upgrade request and receive the response. @@ -1955,8 +1955,8 @@ public: HandshakeHandler, void(error_code)> #endif async_handshake(response_type& res, - string_view const& host, - string_view const& target, + string_view host, + string_view target, HandshakeHandler&& handler); /** Start an asynchronous operation to send an upgrade request and receive the response. @@ -2015,8 +2015,8 @@ public: async_return_type< HandshakeHandler, void(error_code)> #endif - async_handshake_ex(string_view const& host, - string_view const& target, + async_handshake_ex(string_view host, + string_view target, RequestDecorator const& decorator, HandshakeHandler&& handler); @@ -2081,8 +2081,8 @@ public: HandshakeHandler, void(error_code)> #endif async_handshake_ex(response_type& res, - string_view const& host, - string_view const& target, + string_view host, + string_view target, RequestDecorator const& decorator, HandshakeHandler&& handler); @@ -2963,16 +2963,16 @@ private: template void do_handshake(response_type* res_p, - string_view const& host, - string_view const& target, + string_view host, + string_view target, RequestDecorator const& decorator, error_code& ec); template request_type build_request(detail::sec_ws_key_type& key, - string_view const& host, - string_view const& target, + string_view host, + string_view target, Decorator const& decorator); template diff --git a/test/http/basic_parser.cpp b/test/http/basic_parser.cpp index 9ab789af..1e6b7e98 100644 --- a/test/http/basic_parser.cpp +++ b/test/http/basic_parser.cpp @@ -217,7 +217,7 @@ public: template void - good(string_view const& s, + good(string_view s, Pred const& pred, bool skipBody = false) { using boost::asio::buffer; @@ -239,7 +239,7 @@ public: template void - good(string_view const& s) + good(string_view s) { good(s, [](test_parser const&) @@ -249,7 +249,7 @@ public: template void - bad(string_view const& s, + bad(string_view s, error_code const& ev, bool skipBody = false) { using boost::asio::buffer; diff --git a/test/http/message_fuzz.hpp b/test/http/message_fuzz.hpp index 3e6ff075..a2f10932 100644 --- a/test/http/message_fuzz.hpp +++ b/test/http/message_fuzz.hpp @@ -19,7 +19,7 @@ namespace http { template std::string -escaped_string(string_view const& s) +escaped_string(string_view s) { std::string out; out.reserve(s.size()); diff --git a/test/http/parser_bench.cpp b/test/http/parser_bench.cpp index 77062982..dd4daa31 100644 --- a/test/http/parser_bench.cpp +++ b/test/http/parser_bench.cpp @@ -165,22 +165,22 @@ public: boost::asio::mutable_buffers_1; void - on_request(string_view const&, - string_view const&, + on_request(string_view, + string_view, int, error_code&) { } void on_response(int, - string_view const&, + string_view, int, error_code&) { } void - on_field(string_view const&, - string_view const&, + on_field(string_view, + string_view, error_code&) { } @@ -197,14 +197,14 @@ public: } void - on_data(string_view const&, + on_data(string_view, error_code& ec) { } void on_chunk(std::uint64_t, - string_view const&, + string_view, error_code&) { } diff --git a/test/http/rfc7230.cpp b/test/http/rfc7230.cpp index 546398ce..07b285c1 100644 --- a/test/http/rfc7230.cpp +++ b/test/http/rfc7230.cpp @@ -30,7 +30,7 @@ public: static std::string - str(string_view const& s) + str(string_view s) { return std::string(s.data(), s.size()); } @@ -241,7 +241,7 @@ public: template static std::vector - to_vector(string_view const& in) + to_vector(string_view in) { std::vector v; detail::basic_parsed_list list{in}; @@ -253,7 +253,7 @@ public: template void - validate(string_view const& in, + validate(string_view in, std::vector const& v) { BEAST_EXPECT(to_vector(in) == v); @@ -261,7 +261,7 @@ public: template void - good(string_view const& in) + good(string_view in) { BEAST_EXPECT(validate_list( detail::basic_parsed_list{in})); @@ -269,7 +269,7 @@ public: template void - good(string_view const& in, + good(string_view in, std::vector const& v) { BEAST_EXPECT(validate_list( @@ -279,7 +279,7 @@ public: template void - bad(string_view const& in) + bad(string_view in) { BEAST_EXPECT(! validate_list( detail::basic_parsed_list{in})); diff --git a/test/http/test_parser.hpp b/test/http/test_parser.hpp index 148509a8..0f88ba06 100644 --- a/test/http/test_parser.hpp +++ b/test/http/test_parser.hpp @@ -47,8 +47,8 @@ public: } void - on_request(string_view const& method_, - string_view const& path_, + on_request(string_view method_, + string_view path_, int version_, error_code& ec) { method = std::string( @@ -63,7 +63,7 @@ public: void on_response(int status_, - string_view const& reason_, + string_view reason_, int version_, error_code& ec) { status = status_; @@ -76,8 +76,8 @@ public: } void - on_field(string_view const&, - string_view const&, + on_field(string_view, + string_view, error_code& ec) { got_on_field = true; @@ -106,7 +106,7 @@ public: } void - on_data(string_view const& s, + on_data(string_view s, error_code& ec) { body.append(s.data(), s.size()); @@ -116,7 +116,7 @@ public: void on_chunk(std::uint64_t, - string_view const&, error_code& ec) + string_view, error_code& ec) { got_on_chunk = true; if(fc_) diff --git a/test/websocket/stream.cpp b/test/websocket/stream.cpp index b5dc6ea5..50d23be6 100644 --- a/test/websocket/stream.cpp +++ b/test/websocket/stream.cpp @@ -200,8 +200,8 @@ public: template void handshake(stream& ws, - string_view const& uri, - string_view const& path) const + string_view uri, + string_view path) const { ws.handshake(uri, path); } @@ -210,8 +210,8 @@ public: void handshake(stream& ws, response_type& res, - string_view const& uri, - string_view const& path) const + string_view uri, + string_view path) const { ws.handshake(res, uri, path); } @@ -219,8 +219,8 @@ public: template void handshake_ex(stream& ws, - string_view const& uri, - string_view const& path, + string_view uri, + string_view path, Decorator const& d) const { ws.handshake_ex(uri, path, d); @@ -230,8 +230,8 @@ public: void handshake_ex(stream& ws, response_type& res, - string_view const& uri, - string_view const& path, + string_view uri, + string_view path, Decorator const& d) const { ws.handshake_ex(res, uri, path, d); @@ -413,8 +413,8 @@ public: template void handshake(stream& ws, - string_view const& uri, - string_view const& path) const + string_view uri, + string_view path) const { error_code ec; ws.async_handshake( @@ -427,8 +427,8 @@ public: void handshake(stream& ws, response_type& res, - string_view const& uri, - string_view const& path) const + string_view uri, + string_view path) const { error_code ec; ws.async_handshake( @@ -440,8 +440,8 @@ public: template void handshake_ex(stream& ws, - string_view const& uri, - string_view const& path, + string_view uri, + string_view path, Decorator const &d) const { error_code ec; @@ -455,8 +455,8 @@ public: void handshake_ex(stream& ws, response_type& res, - string_view const& uri, - string_view const& path, + string_view uri, + string_view path, Decorator const &d) const { error_code ec;