From: Casey Bodley Date: Thu, 6 Jul 2017 20:31:23 +0000 (-0400) Subject: rgw: update beast frontend/submodule to v116 X-Git-Tag: v13.0.1~300^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=746c218c620d7681f6c9d769631ee1ac0d2b5987;p=ceph.git rgw: update beast frontend/submodule to v116 Signed-off-by: Casey Bodley --- diff --git a/src/Beast b/src/Beast index d8db5f1a0d6..dca65932a80 160000 --- a/src/Beast +++ b/src/Beast @@ -1 +1 @@ -Subproject commit d8db5f1a0d607aa78e6e857daa0410b0d5326978 +Subproject commit dca65932a8055dd3e240633c6a058db8aa7f7915 diff --git a/src/rgw/rgw_asio_client.cc b/src/rgw/rgw_asio_client.cc index 5fa40a9680b..b25e115e9f2 100644 --- a/src/rgw/rgw_asio_client.cc +++ b/src/rgw/rgw_asio_client.cc @@ -3,7 +3,6 @@ #include #include -#include #include "rgw_asio_client.h" @@ -17,7 +16,7 @@ using namespace rgw::asio; ClientIO::ClientIO(tcp::socket& socket, parser_type& parser, - beast::flat_streambuf& buffer) + beast::flat_buffer& buffer) : socket(socket), parser(parser), buffer(buffer), txbuf(*this) { } @@ -29,20 +28,21 @@ void ClientIO::init_env(CephContext *cct) env.init(cct); const auto& request = parser.get(); - const auto& headers = request.fields; + const auto& headers = request; for (auto header = headers.begin(); header != headers.end(); ++header) { - const auto& name = header->name(); + const auto& field = header->name(); // enum type for known headers + const auto& name = header->name_string(); const auto& value = header->value(); - if (boost::algorithm::iequals(name, "content-length")) { + if (field == beast::http::field::content_length) { env.set("CONTENT_LENGTH", value); continue; } - if (boost::algorithm::iequals(name, "content-type")) { + if (field == beast::http::field::content_type) { env.set("CONTENT_TYPE", value); continue; } - if (boost::algorithm::iequals(name, "connection")) { + if (field == beast::http::field::connection) { conn_keepalive = boost::algorithm::iequals(value, "keep-alive"); conn_close = boost::algorithm::iequals(value, "close"); } @@ -63,15 +63,15 @@ void ClientIO::init_env(CephContext *cct) env.set(buf, value); } - int major = request.version / 10; - int minor = request.version % 10; + int major = request.version() / 10; + int minor = request.version() % 10; std::string http_version = std::to_string(major) + '.' + std::to_string(minor); env.set("HTTP_VERSION", http_version); - env.set("REQUEST_METHOD", request.method); + env.set("REQUEST_METHOD", request.method_string()); // split uri from query - auto url = boost::string_ref{request.url}; + auto url = request.target(); auto pos = url.find('?'); auto query = url.substr(pos + 1); url = url.substr(0, pos); @@ -104,20 +104,20 @@ size_t ClientIO::write_data(const char* buf, size_t len) size_t ClientIO::read_data(char* buf, size_t max) { auto& message = parser.get(); - auto& body_remaining = message.body; - body_remaining = boost::asio::mutable_buffer{buf, max}; - - boost::system::error_code ec; + auto& body_remaining = message.body(); + body_remaining.data = buf; + body_remaining.size = max; dout(30) << this << " read_data for " << max << " with " << buffer.size() << " bytes buffered" << dendl; - while (boost::asio::buffer_size(body_remaining) && !parser.is_complete()) { - auto bytes = beast::http::read_some(socket, buffer, parser, ec); - buffer.consume(bytes); + while (body_remaining.size && !parser.is_done()) { + boost::system::error_code ec; + beast::http::read_some(socket, buffer, parser, ec); if (ec == boost::asio::error::connection_reset || ec == boost::asio::error::eof || - ec == beast::http::error::partial_message) { + ec == beast::http::error::partial_message || + ec == beast::http::error::need_buffer) { break; } if (ec) { @@ -125,7 +125,7 @@ size_t ClientIO::read_data(char* buf, size_t max) throw rgw::io::Exception(ec.value(), std::system_category()); } } - return max - boost::asio::buffer_size(body_remaining); + return max - body_remaining.size; } size_t ClientIO::complete_request() diff --git a/src/rgw/rgw_asio_client.h b/src/rgw/rgw_asio_client.h index 513a3ef0ca2..64a5bdcd1e8 100644 --- a/src/rgw/rgw_asio_client.h +++ b/src/rgw/rgw_asio_client.h @@ -4,9 +4,8 @@ #define RGW_ASIO_CLIENT_H #include -#include -#include -#include +#include +#include #include "include/assert.h" #include "rgw_client_io.h" @@ -14,40 +13,8 @@ namespace rgw { namespace asio { -/// streaming message body interface -struct streaming_body { - using value_type = boost::asio::mutable_buffer; - - class reader { - value_type& buffer; - public: - using mutable_buffers_type = boost::asio::mutable_buffers_1; - - static const bool is_direct{true}; // reads directly into user buffer - - template - explicit reader(beast::http::message& m) - : buffer(m.body) - {} - - void init() {} - void init(uint64_t content_length) {} - void finish() {} - - mutable_buffers_type prepare(size_t n) { - n = std::min(n, boost::asio::buffer_size(buffer)); - auto position = boost::asio::buffer_cast(buffer); - return {position, n}; - } - - void commit(size_t n) { - buffer = buffer + n; - } - }; -}; - -using header_type = beast::http::fields; -using parser_type = beast::http::message_parser; +namespace beast = boost::beast; +using parser_type = beast::http::request_parser; class ClientIO : public io::RestfulClient, public io::BuffererSink { @@ -55,7 +22,7 @@ class ClientIO : public io::RestfulClient, using tcp = boost::asio::ip::tcp; tcp::socket& socket; parser_type& parser; - beast::flat_streambuf& buffer; //< parse buffer + beast::flat_buffer& buffer; //< parse buffer bool conn_keepalive{false}; bool conn_close{false}; @@ -68,7 +35,7 @@ class ClientIO : public io::RestfulClient, public: ClientIO(tcp::socket& socket, parser_type& parser, - beast::flat_streambuf& buffer); + beast::flat_buffer& buffer); ~ClientIO() override; bool get_conn_close() const { return conn_close; } diff --git a/src/rgw/rgw_asio_frontend.cc b/src/rgw/rgw_asio_frontend.cc index 27a9329112c..f64f435920d 100644 --- a/src/rgw/rgw_asio_frontend.cc +++ b/src/rgw/rgw_asio_frontend.cc @@ -9,18 +9,13 @@ #include #include -#include -#include -#include -#include - -#include "rgw_asio_frontend.h" #include "rgw_asio_client.h" +#include "rgw_asio_frontend.h" #define dout_subsys ceph_subsys_rgw -#undef dout_prefix -#define dout_prefix (*_dout << "asio: ") +//#undef dout_prefix +//#define dout_prefix (*_dout << "asio: ") namespace { @@ -68,6 +63,7 @@ void Pauser::wait() } using tcp = boost::asio::ip::tcp; +namespace beast = boost::beast; // coroutine to handle a client connection to completion static void handle_connection(RGWProcessEnv& env, tcp::socket socket, @@ -76,16 +72,13 @@ static void handle_connection(RGWProcessEnv& env, tcp::socket socket, auto cct = env.store->ctx(); boost::system::error_code ec; - beast::flat_streambuf buffer{1024}; + beast::flat_buffer buffer{4096}; // read messages from the socket until eof for (;;) { // parse the header rgw::asio::parser_type parser; - do { - auto bytes = beast::http::async_read_some(socket, buffer, parser, yield[ec]); - buffer.consume(bytes); - } while (!ec && !parser.got_header()); + beast::http::async_read_header(socket, buffer, parser, yield[ec]); if (ec == boost::asio::error::connection_reset || ec == boost::asio::error::eof) { @@ -96,11 +89,11 @@ static void handle_connection(RGWProcessEnv& env, tcp::socket socket, ldout(cct, 1) << "read failed: " << ec.message() << dendl; ldout(cct, 1) << "====== req done http_status=400 ======" << dendl; beast::http::response response; - response.status = 400; - response.reason = "Bad Request"; - response.version = message.version == 10 ? 10 : 11; - beast::http::prepare(response); - beast::http::async_write(socket, std::move(response), yield[ec]); + response.result(beast::http::status::bad_request); + response.reason("Bad Request"); + response.version(message.version() == 10 ? 10 : 11); + response.prepare_payload(); + beast::http::async_write(socket, response, yield[ec]); // ignore ec return; } diff --git a/src/rgw/rgw_env.cc b/src/rgw/rgw_env.cc index 8be133d67f8..f17b7832ba9 100644 --- a/src/rgw/rgw_env.cc +++ b/src/rgw/rgw_env.cc @@ -19,7 +19,7 @@ void RGWEnv::init(CephContext *cct) void RGWEnv::set(const boost::string_ref& name, const boost::string_ref& val) { - env_map[std::string{name}] = std::string{val}; + env_map[name.to_string()] = val.to_string(); } void RGWEnv::init(CephContext *cct, char **envp)