diff --git a/CHANGELOG.md b/CHANGELOG.md index 73126935..b95daf6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Version 61: * Flush the output stream in the example * Clean close in Secure WebSocket client * Add server-framework SSL HTTP and WebSocket ports +* Fix shadowing warnings API Changes: diff --git a/example/doc/http_examples.hpp b/example/doc/http_examples.hpp index d1aefdfd..977aade6 100644 --- a/example/doc/http_examples.hpp +++ b/example/doc/http_examples.hpp @@ -137,7 +137,7 @@ receive_expect_100_continue( response res; res.version = 11; res.result(status::continue_); - res.insert(field::server, "test"); + res.set(field::server, "test"); write(stream, res, ec); if(ec) return; @@ -199,8 +199,8 @@ send_cgi_response( res.result(status::ok); res.version = 11; - res.insert(field::server, "Beast"); - res.insert(field::transfer_encoding, "chunked"); + res.set(field::server, "Beast"); + res.set(field::transfer_encoding, "chunked"); // No data yet, but we set more = true to indicate // that it might be coming later. Otherwise the @@ -308,7 +308,7 @@ void do_server_head( // Set up the response, starting with the common fields response res; res.version = 11; - res.insert(field::server, "test"); + res.set(field::server, "test"); // Now handle request-specific fields switch(req.method()) @@ -338,7 +338,7 @@ void do_server_head( // We return responses indicating an error if // we do not recognize the request method. res.result(status::bad_request); - res.insert(field::content_type, "text/plain"); + res.set(field::content_type, "text/plain"); res.body = "Invalid request-method '" + req.method_string().to_string() + "'"; break; } @@ -398,11 +398,11 @@ do_head_request( req.version = 11; req.method(verb::head); req.target(target); - req.insert(field::user_agent, "test"); + req.set(field::user_agent, "test"); // A client MUST send a Host header field in all HTTP/1.1 request messages. // https://tools.ietf.org/html/rfc7230#section-5.4 - req.insert(field::host, "localhost"); + req.set(field::host, "localhost"); // Now send it write(stream, req, ec); diff --git a/include/beast/core/string.hpp b/include/beast/core/string.hpp index dc8915b5..862b24d0 100644 --- a/include/beast/core/string.hpp +++ b/include/beast/core/string.hpp @@ -83,9 +83,9 @@ struct iless using std::end; return std::lexicographical_compare( begin(lhs), end(lhs), begin(rhs), end(rhs), - [](char lhs, char rhs) + [](char c1, char c2) { - return detail::ascii_tolower(lhs) < detail::ascii_tolower(rhs); + return detail::ascii_tolower(c1) < detail::ascii_tolower(c2); } ); } diff --git a/include/beast/http/impl/parser.ipp b/include/beast/http/impl/parser.ipp index ca14e493..97d3a0f7 100644 --- a/include/beast/http/impl/parser.ipp +++ b/include/beast/http/impl/parser.ipp @@ -26,12 +26,12 @@ parser(Arg1&& arg1, ArgN&&... argn) template template parser:: -parser(parser&& parser, +parser(parser&& p, Args&&... args) - : base_type(std::move(parser)) - , m_(parser.release(), std::forward(args)...) + : base_type(std::move(p)) + , m_(p.release(), std::forward(args)...) { - if(parser.wr_) + if(p.wr_) BOOST_THROW_EXCEPTION(std::invalid_argument{ "moved-from parser has a body"}); } diff --git a/include/beast/http/message.hpp b/include/beast/http/message.hpp index 1a39c757..f30416d2 100644 --- a/include/beast/http/message.hpp +++ b/include/beast/http/message.hpp @@ -538,7 +538,7 @@ struct message : header req.version = 11; req.method(verb::upgrade); req.target("/"); - req.insert(field::user_agent, "Beast"); + req.set(field::user_agent, "Beast"); req.body = "Hello, world!"; req.prepare(); @endcode diff --git a/include/beast/websocket/detail/stream_base.hpp b/include/beast/websocket/detail/stream_base.hpp index e8334148..9e5c18d1 100644 --- a/include/beast/websocket/detail/stream_base.hpp +++ b/include/beast/websocket/detail/stream_base.hpp @@ -532,10 +532,10 @@ template void stream_base:: write_ping(DynamicBuffer& db, - detail::opcode op, ping_data const& data) + detail::opcode code, ping_data const& data) { frame_header fh; - fh.op = op; + fh.op = code; fh.fin = true; fh.rsv1 = false; fh.rsv2 = false; diff --git a/include/beast/websocket/detail/utf8_checker.hpp b/include/beast/websocket/detail/utf8_checker.hpp index 6800923a..9feb9c66 100644 --- a/include/beast/websocket/detail/utf8_checker.hpp +++ b/include/beast/websocket/detail/utf8_checker.hpp @@ -145,40 +145,40 @@ utf8_checker_t<_>:: write(std::uint8_t const* in, std::size_t size) { auto const valid = - [](std::uint8_t const*& in) + [](std::uint8_t const*& p) { - if (in[0] < 128) + if (p[0] < 128) { - ++in; + ++p; return true; } - if ((in[0] & 0x60) == 0x40) + if ((p[0] & 0x60) == 0x40) { - if ((in[1] & 0xc0) != 0x80) + if ((p[1] & 0xc0) != 0x80) return false; - in += 2; + p += 2; return true; } - if ((in[0] & 0xf0) == 0xe0) + if ((p[0] & 0xf0) == 0xe0) { - if ((in[1] & 0xc0) != 0x80 || - (in[2] & 0xc0) != 0x80 || - (in[0] == 224 && in[1] < 160) || - (in[0] == 237 && in[1] > 159)) + if ((p[1] & 0xc0) != 0x80 || + (p[2] & 0xc0) != 0x80 || + (p[0] == 224 && p[1] < 160) || + (p[0] == 237 && p[1] > 159)) return false; - in += 3; + p += 3; return true; } - if ((in[0] & 0xf8) == 0xf0) + if ((p[0] & 0xf8) == 0xf0) { - if (in[0] > 244 || - (in[1] & 0xc0) != 0x80 || - (in[2] & 0xc0) != 0x80 || - (in[3] & 0xc0) != 0x80 || - (in[0] == 240 && in[1] < 144) || - (in[0] == 244 && in[1] > 143)) + if (p[0] > 244 || + (p[1] & 0xc0) != 0x80 || + (p[2] & 0xc0) != 0x80 || + (p[3] & 0xc0) != 0x80 || + (p[0] == 240 && p[1] < 144) || + (p[0] == 244 && p[1] > 143)) return false; - in += 4; + p += 4; return true; } return false; @@ -199,10 +199,10 @@ write(std::uint8_t const* in, std::size_t size) } if ((have_[0] & 0xf8) == 0xf0) { - auto const size = p_ - have_; - if (size > 2 && (have_[2] & 0xc0) != 0x80) + auto const n = p_ - have_; + if (n > 2 && (have_[2] & 0xc0) != 0x80) return false; - if (size > 1 && + if (n > 1 && ((have_[1] & 0xc0) != 0x80 || (have_[0] == 240 && have_[1] < 144) || (have_[0] == 244 && have_[1] > 143))) @@ -211,17 +211,17 @@ write(std::uint8_t const* in, std::size_t size) return true; }; auto const needed = - [](std::uint8_t const in) + [](std::uint8_t const v) { - if (in < 128) + if (v < 128) return 1; - if (in < 194) + if (v < 194) return 0; - if (in < 224) + if (v < 224) return 2; - if (in < 240) + if (v < 240) return 3; - if (in < 245) + if (v < 245) return 4; return 0; }; diff --git a/include/beast/websocket/impl/stream.ipp b/include/beast/websocket/impl/stream.ipp index b6101b95..ce791296 100644 --- a/include/beast/websocket/impl/stream.ipp +++ b/include/beast/websocket/impl/stream.ipp @@ -164,12 +164,12 @@ build_request(detail::sec_ws_key_type& key, req.target(target); req.version = 11; req.method(http::verb::get); - req.insert(http::field::host, host); - req.insert(http::field::upgrade, "websocket"); - req.insert(http::field::connection, "upgrade"); + req.set(http::field::host, host); + req.set(http::field::upgrade, "websocket"); + req.set(http::field::connection, "upgrade"); detail::make_sec_ws_key(key, maskgen_); - req.insert(http::field::sec_websocket_key, key); - req.insert(http::field::sec_websocket_version, "13"); + req.set(http::field::sec_websocket_key, key); + req.set(http::field::sec_websocket_version, "13"); if(pmd_opts_.client_enable) { detail::pmd_offer config; @@ -186,7 +186,7 @@ build_request(detail::sec_ws_key_type& key, } decorator(req); if(! req.count(http::field::user_agent)) - req.insert(http::field::user_agent, + req.set(http::field::user_agent, BEAST_VERSION_STRING); return req; } @@ -206,7 +206,7 @@ build_response(http::header const& req, { BOOST_STATIC_ASSERT(sizeof(BEAST_VERSION_STRING) < 20); static_string<20> s(BEAST_VERSION_STRING); - res.insert(http::field::server, s); + res.set(http::field::server, s); } }; auto err = @@ -245,7 +245,7 @@ build_response(http::header const& req, response_type res; res.result(http::status::upgrade_required); res.version = req.version; - res.insert(http::field::sec_websocket_version, "13"); + res.set(http::field::sec_websocket_version, "13"); res.prepare(); decorate(res); return res; @@ -261,12 +261,12 @@ build_response(http::header const& req, } res.result(http::status::switching_protocols); res.version = req.version; - res.insert(http::field::upgrade, "websocket"); - res.insert(http::field::connection, "upgrade"); + res.set(http::field::upgrade, "websocket"); + res.set(http::field::connection, "upgrade"); { - detail::sec_ws_accept_type accept; - detail::make_sec_ws_accept(accept, key); - res.insert(http::field::sec_websocket_accept, accept); + detail::sec_ws_accept_type acc; + detail::make_sec_ws_accept(acc, key); + res.set(http::field::sec_websocket_accept, acc); } decorate(res); return res; @@ -290,9 +290,9 @@ do_response(http::header const& res, return false; if(res.count(http::field::sec_websocket_accept) != 1) return false; - detail::sec_ws_accept_type accept; - detail::make_sec_ws_accept(accept, key); - if(accept.compare( + detail::sec_ws_accept_type acc; + detail::make_sec_ws_accept(acc, key); + if(acc.compare( res[http::field::sec_websocket_accept]) != 0) return false; return true; diff --git a/include/beast/websocket/stream.hpp b/include/beast/websocket/stream.hpp index 72541820..befc7a8e 100644 --- a/include/beast/websocket/stream.hpp +++ b/include/beast/websocket/stream.hpp @@ -1759,7 +1759,7 @@ public: ws.handshake("localhost", "/", [](request_type& req) { - req.insert(field::user_agent, "Beast"); + req.set(field::user_agent, "Beast"); }); } catch(...) @@ -1820,7 +1820,7 @@ public: ws.handshake(res, "localhost", "/", [](request_type& req) { - req.insert(field::user_agent, "Beast"); + req.set(field::user_agent, "Beast"); }); } catch(...) @@ -1963,7 +1963,7 @@ public: ws.handshake("localhost", "/", [](request_type& req) { - req.insert(field::user_agent, "Beast"); + req.set(field::user_agent, "Beast"); }, ec); if(ec) @@ -2024,7 +2024,7 @@ public: ws.handshake(res, "localhost", "/", [](request_type& req) { - req.insert(field::user_agent, "Beast"); + req.set(field::user_agent, "Beast"); }, ec); if(ec) diff --git a/include/beast/zlib/detail/deflate_stream.hpp b/include/beast/zlib/detail/deflate_stream.hpp index 1e29298d..5af73a7d 100644 --- a/include/beast/zlib/detail/deflate_stream.hpp +++ b/include/beast/zlib/detail/deflate_stream.hpp @@ -2282,18 +2282,18 @@ fill_window(z_params& zs) if(high_water_ < window_size_) { std::uint32_t curr = strstart_ + (std::uint32_t)(lookahead_); - std::uint32_t init; + std::uint32_t winit; if(high_water_ < curr) { /* Previous high water mark below current data -- zero kWinInit bytes or up to end of window, whichever is less. */ - init = window_size_ - curr; - if(init > kWinInit) - init = kWinInit; - std::memset(window_ + curr, 0, (unsigned)init); - high_water_ = curr + init; + winit = window_size_ - curr; + if(winit > kWinInit) + winit = kWinInit; + std::memset(window_ + curr, 0, (unsigned)winit); + high_water_ = curr + winit; } else if(high_water_ < (std::uint32_t)curr + kWinInit) { @@ -2301,11 +2301,11 @@ fill_window(z_params& zs) plus kWinInit -- zero out to current data plus kWinInit, or up to end of window, whichever is less. */ - init = (std::uint32_t)curr + kWinInit - high_water_; - if(init > window_size_ - high_water_) - init = window_size_ - high_water_; - std::memset(window_ + high_water_, 0, (unsigned)init); - high_water_ += init; + winit = (std::uint32_t)curr + kWinInit - high_water_; + if(winit > window_size_ - high_water_) + winit = window_size_ - high_water_; + std::memset(window_ + high_water_, 0, (unsigned)winit); + high_water_ += winit; } } } diff --git a/test/core/static_buffer.cpp b/test/core/static_buffer.cpp index b2ef000d..fb0f4f62 100644 --- a/test/core/static_buffer.cpp +++ b/test/core/static_buffer.cpp @@ -207,15 +207,15 @@ public: // base { static_buffer_n<10> b; - [&](static_buffer& b) + [&](static_buffer& base) { - BEAST_EXPECT(b.max_size() == b.capacity()); + BEAST_EXPECT(base.max_size() == b.capacity()); } (b.base()); - [&](static_buffer const&) + [&](static_buffer const& base) { - BEAST_EXPECT(b.max_size() == b.capacity()); + BEAST_EXPECT(base.max_size() == b.capacity()); } (b.base()); } diff --git a/test/http/doc_examples.cpp b/test/http/doc_examples.cpp index 064d73ad..d0f0406d 100644 --- a/test/http/doc_examples.cpp +++ b/test/http/doc_examples.cpp @@ -120,9 +120,9 @@ public: flat_buffer buffer; relay(upstream.client, downstream.server, buffer, ec, - [&](header& h, error_code& ec) + [&](header& h, error_code& ev) { - ec = {}; + ev = {}; h.erase("Content-Length"); h.set("Transfer-Encoding", "chunked"); }); diff --git a/test/http/doc_snippets.cpp b/test/http/doc_snippets.cpp index 67b15125..6605fbca 100644 --- a/test/http/doc_snippets.cpp +++ b/test/http/doc_snippets.cpp @@ -26,7 +26,6 @@ void fxx() { boost::asio::io_service ios; boost::asio::io_service::work work{ios}; std::thread t{[&](){ ios.run(); }}; - error_code ec; boost::asio::ip::tcp::socket sock{ios}; { @@ -36,8 +35,8 @@ void fxx() { req.version = 11; // HTTP/1.1 req.method(verb::get); req.target("/index.htm"); - req.insert(field::accept, "text/html"); - req.insert(field::user_agent, "Beast"); + req.set(field::accept, "text/html"); + req.set(field::user_agent, "Beast"); //] } @@ -48,7 +47,7 @@ void fxx() { response res; res.version = 11; // HTTP/1.1 res.result(status::ok); - res.insert(field::server, "Beast"); + res.set(field::server, "Beast"); res.body = "Hello, world!"; res.prepare(); @@ -86,6 +85,7 @@ void fxx() { flat_buffer buffer{10}; // Try to read a request + error_code ec; request req; read(sock, buffer, req, ec); if(ec == error::buffer_overflow) @@ -100,9 +100,10 @@ void fxx() { response res; res.version = 11; res.result(status::ok); - res.insert(field::server, "Beast"); + res.set(field::server, "Beast"); res.body = "Hello, world!"; + error_code ec; write(sock, res, ec); if(ec == error::end_of_stream) sock.close(); diff --git a/test/http/rfc7230.cpp b/test/http/rfc7230.cpp index 07b285c1..dfa5b068 100644 --- a/test/http/rfc7230.cpp +++ b/test/http/rfc7230.cpp @@ -63,18 +63,18 @@ public: BEAST_EXPECTS(got == s, fmt(got)); }; auto const cs = - [&](std::string const& s, std::string const& good) + [&](std::string const& s, std::string const& answer) { - ce(good); + ce(answer); auto const got = str(param_list{s}); ce(got); - BEAST_EXPECTS(got == good, fmt(got)); + BEAST_EXPECTS(got == answer, fmt(got)); }; auto const cq = - [&](std::string const& s, std::string const& good) + [&](std::string const& s, std::string const& answer) { auto const got = str(param_list{s}); - BEAST_EXPECTS(got == good, fmt(got)); + BEAST_EXPECTS(got == answer, fmt(got)); }; ce(""); diff --git a/test/websocket/doc_snippets.cpp b/test/websocket/doc_snippets.cpp index c9cde577..bf54708c 100644 --- a/test/websocket/doc_snippets.cpp +++ b/test/websocket/doc_snippets.cpp @@ -79,9 +79,9 @@ boost::asio::ip::tcp::socket sock{ios}; //[ws_snippet_9 ws.handshake_ex("localhost", "/", - [](request_type& req) + [](request_type& m) { - req.insert(http::field::sec_websocket_protocol, "xmpp;ws-chat"); + m.insert(http::field::sec_websocket_protocol, "xmpp;ws-chat"); }); //] @@ -98,9 +98,9 @@ boost::asio::ip::tcp::socket sock{ios}; //[ws_snippet_12 ws.accept_ex( - [](response_type& res) + [](response_type& m) { - res.insert(http::field::server, "MyServer"); + m.insert(http::field::server, "MyServer"); }); //] } @@ -207,7 +207,7 @@ boost::asio::ip::tcp::socket sock{ios}; //[ws_snippet_20 multi_buffer buffer; ws.async_read(buffer, - [](error_code ec) + [](error_code) { // Do something with the buffer });