]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: update beast frontend/submodule to v116
authorCasey Bodley <cbodley@redhat.com>
Thu, 6 Jul 2017 20:31:23 +0000 (16:31 -0400)
committerCasey Bodley <cbodley@redhat.com>
Fri, 27 Oct 2017 15:28:40 +0000 (11:28 -0400)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/Beast
src/rgw/rgw_asio_client.cc
src/rgw/rgw_asio_client.h
src/rgw/rgw_asio_frontend.cc
src/rgw/rgw_env.cc

index d8db5f1a0d607aa78e6e857daa0410b0d5326978..dca65932a8055dd3e240633c6a058db8aa7f7915 160000 (submodule)
--- a/src/Beast
+++ b/src/Beast
@@ -1 +1 @@
-Subproject commit d8db5f1a0d607aa78e6e857daa0410b0d5326978
+Subproject commit dca65932a8055dd3e240633c6a058db8aa7f7915
index 5fa40a9680bc9c7a894c81371a95409f7de5d914..b25e115e9f2c6d585c040bc0353786561995a9d1 100644 (file)
@@ -3,7 +3,6 @@
 
 #include <boost/algorithm/string/predicate.hpp>
 #include <boost/asio/write.hpp>
-#include <beast/http/read.hpp>
 
 #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()
index 513a3ef0ca20bc9e667ace39a015b871145e8123..64a5bdcd1e81e6b4340642c5360daed126a51403 100644 (file)
@@ -4,9 +4,8 @@
 #define RGW_ASIO_CLIENT_H
 
 #include <boost/asio/ip/tcp.hpp>
-#include <beast/http/message.hpp>
-#include <beast/http/message_parser.hpp>
-#include <beast/core/flat_streambuf.hpp>
+#include <boost/beast/core.hpp>
+#include <boost/beast/http.hpp>
 #include "include/assert.h"
 
 #include "rgw_client_io.h"
 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<bool isRequest, class Fields>
-    explicit reader(beast::http::message<isRequest, streaming_body, Fields>& 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<char*>(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<true, streaming_body, header_type>;
+namespace beast = boost::beast;
+using parser_type = beast::http::request_parser<beast::http::buffer_body>;
 
 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; }
index 27a9329112c031d5881665dd693730e98d7e6eca..f64f435920d2eef4b78563a3122d51327a779585 100644 (file)
@@ -9,18 +9,13 @@
 #include <boost/asio.hpp>
 #include <boost/asio/spawn.hpp>
 
-#include <beast/core/placeholders.hpp>
-#include <beast/http/read.hpp>
-#include <beast/http/string_body.hpp>
-#include <beast/http/write.hpp>
-
-#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<beast::http::string_body> 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;
     }
index 8be133d67f8064344b733882652b64b41269fe38..f17b7832ba9480a14f96d4926eebe4d8a110006e 100644 (file)
@@ -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)