diff --git a/CHANGELOG.md b/CHANGELOG.md index 4db8d055..eb6362c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ API Changes: * Add verb to on_request for parsers * Refactor prepare * Protect basic_fields special members +* Remove message connection settings -------------------------------------------------------------------------------- diff --git a/doc/4_02_message.qbk b/doc/4_02_message.qbk index 5105e82e..11ee8707 100644 --- a/doc/4_02_message.qbk +++ b/doc/4_02_message.qbk @@ -118,10 +118,7 @@ the __Body__ requirements: The code examples below show how to create and fill in request and response objects: Here is simple example of building an [@https://tools.ietf.org/html/rfc7231#section-4.3.1 HTTP GET] -request. The function -[link beast.ref.http__message.prepare prepare] -allows for various connection options. The use of prepare is optional, -the Connection field may be set manually if desired. +request. [table Create Request [[Statements] [Serialized Result]] @@ -132,7 +129,6 @@ the Connection field may be set manually if desired. GET /index.htm HTTP/1.1\r\n Accept: text/html\r\n User-Agent: Beast\r\n - Connection: close\r\n \r\n ``` ]] @@ -143,7 +139,7 @@ message has a body. The function [link beast.ref.http__message.prepare prepare] automatically sets the Content-Length or Transfer-Encoding field depending on the body type. The use of prepare is optional, the -Content-Length and other fields may be set manually if desired. +fields may be set manually if desired. [table Create Response [[Statements] [Serialized Result]] diff --git a/include/beast/http.hpp b/include/beast/http.hpp index 6f6063c5..fbdc3034 100644 --- a/include/beast/http.hpp +++ b/include/beast/http.hpp @@ -12,7 +12,6 @@ #include #include -#include #include #include #include diff --git a/include/beast/http/connection.hpp b/include/beast/http/connection.hpp deleted file mode 100644 index f0bc58ad..00000000 --- a/include/beast/http/connection.hpp +++ /dev/null @@ -1,88 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// - -#ifndef BEAST_HTTP_CONNECTION_HPP -#define BEAST_HTTP_CONNECTION_HPP - -#include - -namespace beast { -namespace http { - -/// The type of @ref connection::close -struct close_t {}; - -/// The type of @ref connection::upgrade -struct upgrade_t {}; - -/// The type of @ref connection::keep_alive -struct keep_alive_t {}; - -namespace detail { - -template -struct connection_impl -{ - static close_t constexpr close{}; - static keep_alive_t constexpr keep_alive{}; - static upgrade_t constexpr upgrade{}; -}; - -template -constexpr -close_t -connection_impl<_>::close; - -template -constexpr -keep_alive_t -connection_impl<_>::keep_alive; - -template -constexpr -upgrade_t -connection_impl<_>::upgrade; - -} // detail - -/** HTTP/1 Connection prepare options. - - Each value is an individual settings, they can be combined. - - @par Example - @code - request req; - req.version = 11; - req.method(verb::upgrade); - req.target("/"); - req.insert(field::user_agent, "Beast"); - req.prepare(connection::close, connection::upgrade); - @endcode - - @note These values are used with @ref message::prepare. -*/ -struct connection -#if ! BEAST_DOXYGEN - : detail::connection_impl<> -#endif -{ -#if BEAST_DOXYGEN - /// Specify connection close semantics. - static close_t constexpr close; - - /// Specify connection keep-alive semantics. - static keep_alive_t constexpr keep_alive; - - /// Specify Connection: upgrade. - static upgrade_t constexpr upgrade; -#endif -}; - -} // http -} // beast - -#endif diff --git a/include/beast/http/fields.hpp b/include/beast/http/fields.hpp index a22e4fb0..6512d021 100644 --- a/include/beast/http/fields.hpp +++ b/include/beast/http/fields.hpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -396,24 +395,6 @@ protected: */ void content_length_impl(std::uint64_t n); - /** Add close to the Connection field. - - @note This is called by the @ref header implementation. - */ - void connection_impl(close_t); - - /** Add keep-alive to the Connection field. - - @note This is called by the @ref header implementation. - */ - void connection_impl(keep_alive_t); - - /** Add upgrade to the Connection field. - - @note This is called by the @ref header implementation. - */ - void connection_impl(upgrade_t); - /** Add chunked to the Transfer-Encoding field. @note This is called by the @ref header implementation. diff --git a/include/beast/http/impl/fields.ipp b/include/beast/http/impl/fields.ipp index 48077d1a..a2fffa24 100644 --- a/include/beast/http/impl/fields.ipp +++ b/include/beast/http/impl/fields.ipp @@ -662,48 +662,6 @@ content_length_impl(std::uint64_t n) to_static_string(n)); } -template -inline -void -basic_fields:: -connection_impl(close_t) -{ - auto it = find("Connection"); - if(it == end()) - this->insert("Connection", "close"); - else - this->replace("Connection", - it->value().to_string() + ", close"); -} - -template -inline -void -basic_fields:: -connection_impl(keep_alive_t) -{ - auto it = find("Connection"); - if(it == end()) - this->insert("Connection", "keep-alive"); - else - this->replace("Connection", - it->value().to_string() + ", keep-alive"); -} - -template -inline -void -basic_fields:: -connection_impl(upgrade_t) -{ - auto it = find("Connection"); - if(it == end()) - this->insert("Connection", "upgrade"); - else - this->replace("Connection", - it->value().to_string() + ", upgrade"); -} - template inline void diff --git a/include/beast/http/impl/message.ipp b/include/beast/http/impl/message.ipp index eff0b46a..6b28a746 100644 --- a/include/beast/http/impl/message.ipp +++ b/include/beast/http/impl/message.ipp @@ -292,85 +292,19 @@ content_length(std::uint64_t n) } template -template void message:: -prepare(Args const&... args) +prepare() { - static_assert(is_body_reader::value, - "BodyReader requirements not met"); - - unsigned f = 0; - prepare_opt(f, args...); - - if(f & 1) - { - if(this->version > 10) - this->connection_impl(connection::close); - } - - if(f & 2) - { - if(this->version < 11) - this->connection_impl(connection::keep_alive); - } - - if(f & 4) - { - if(this->version < 11) - BOOST_THROW_EXCEPTION(std::invalid_argument{ - "invalid connection upgrade"}); - this->connection_impl(connection::upgrade); - } - - prepare_payload(typename header< + prepare(typename header< isRequest, Fields>::is_request{}); } template -template inline void message:: -prepare_opt(unsigned& f, - Arg const& arg, Args const&... args) -{ - prepare_opt(f, arg); - prepare_opt(f, args...); -} - -template -inline -void -message:: -prepare_opt(unsigned& f, close_t) -{ - f |= 1; -} - -template -inline -void -message:: -prepare_opt(unsigned& f, keep_alive_t) -{ - f |= 2; -} - -template -inline -void -message:: -prepare_opt(unsigned& f, upgrade_t) -{ - f |= 4; -} - -template -inline -void -message:: -prepare_payload(std::true_type) +prepare(std::true_type) { auto const n = size(); if(this->method_ == verb::trace && @@ -398,7 +332,7 @@ template inline void message:: -prepare_payload(std::false_type) +prepare(std::false_type) { auto const n = size(); if((status_class(this->result_) == diff --git a/include/beast/http/message.hpp b/include/beast/http/message.hpp index cef3d990..1942b5c0 100644 --- a/include/beast/http/message.hpp +++ b/include/beast/http/message.hpp @@ -9,7 +9,6 @@ #define BEAST_HTTP_MESSAGE_HPP #include -#include #include #include #include @@ -500,34 +499,25 @@ struct message : header void content_length(std::uint64_t n); - /** Prepare some fields automatically. + /** Prepare the message payload fields for the body. - This function will adjust the Connection, Content-Length - and Transfer-Encoding, fields of the message based on the - properties of the body and the options passed in. + This function will adjust the Content-Length and + Transfer-Encoding field values based on the properties + of the body. @par Example @code - request req; + request req; req.version = 11; req.method(verb::upgrade); req.target("/"); req.insert(field::user_agent, "Beast"); - req.prepare(connection::close, connection::upgrade); + req.body = "Hello, world!"; + req.prepare(); @endcode - - @param args An list of zero or more options to use. - - @throw std::invalid_argument if the values of certain - fields detectably violate the semantic requirements of HTTP. - - @note Undefined behavior if called more than once. - - @see @ref connection */ - template void - prepare(Args const&... args); + prepare(); private: static_assert(is_body::value, @@ -564,29 +554,11 @@ private: return boost::none; } - template void - prepare_opt(unsigned&, Arg const&, Args const&...); + prepare(std::true_type); void - prepare_opt(unsigned&) - { - } - - void - prepare_opt(unsigned&, close_t); - - void - prepare_opt(unsigned&, keep_alive_t); - - void - prepare_opt(unsigned&, upgrade_t); - - void - prepare_payload(std::true_type); - - void - prepare_payload(std::false_type); + prepare(std::false_type); }; /// A typical HTTP request diff --git a/test/http/doc_snippets.cpp b/test/http/doc_snippets.cpp index 32e16b97..8d357bdb 100644 --- a/test/http/doc_snippets.cpp +++ b/test/http/doc_snippets.cpp @@ -38,7 +38,6 @@ void fxx() { req.target("/index.htm"); req.insert(field::accept, "text/html"); req.insert(field::user_agent, "Beast"); - req.prepare(connection::close); //] } diff --git a/test/http/message.cpp b/test/http/message.cpp index c619f5a3..19355d06 100644 --- a/test/http/message.cpp +++ b/test/http/message.cpp @@ -205,9 +205,8 @@ public: m.insert("Upgrade", "test"); BEAST_EXPECT(! is_upgrade(m)); - m.prepare(connection::upgrade); + m.insert(field::connection, "upgrade"); BEAST_EXPECT(is_upgrade(m)); - BEAST_EXPECT(m["Connection"] == "upgrade"); m.version = 10; BEAST_EXPECT(! is_upgrade(m)); diff --git a/test/http/write.cpp b/test/http/write.cpp index bb461f3f..d2b11948 100644 --- a/test/http/write.cpp +++ b/test/http/write.cpp @@ -510,42 +510,6 @@ public: "*" ); } - // keep-alive HTTP/1.0 - { - message m; - m.method(verb::get); - m.target("/"); - m.version = 10; - m.insert(field::user_agent, "test"); - m.body = "*"; - m.prepare(connection::keep_alive); - BEAST_EXPECT(str(m) == - "GET / HTTP/1.0\r\n" - "User-Agent: test\r\n" - "Connection: keep-alive\r\n" - "Content-Length: 1\r\n" - "\r\n" - "*" - ); - } - // upgrade HTTP/1.0 - { - message m; - m.method(verb::get); - m.target("/"); - m.version = 10; - m.insert(field::user_agent, "test"); - m.body = "*"; - try - { - m.prepare( connection::upgrade); - fail(); - } - catch(std::exception const&) - { - pass(); - } - } // no content-length HTTP/1.0 { message m; @@ -583,43 +547,6 @@ public: "*" ); } - // close HTTP/1.1 - { - message m; - m.method(verb::get); - m.target("/"); - m.version = 11; - m.insert(field::user_agent, "test"); - m.body = "*"; - m.prepare(connection::close); - test::string_ostream ss(ios_); - error_code ec; - write(ss, m, ec); - BEAST_EXPECT(ec == error::end_of_stream); - BEAST_EXPECT(ss.str == - "GET / HTTP/1.1\r\n" - "User-Agent: test\r\n" - "Connection: close\r\n" - "Content-Length: 1\r\n" - "\r\n" - "*" - ); - } - // upgrade HTTP/1.1 - { - message m; - m.method(verb::get); - m.target("/"); - m.version = 11; - m.insert(field::user_agent, "test"); - m.prepare(connection::upgrade); - BEAST_EXPECT(str(m) == - "GET / HTTP/1.1\r\n" - "User-Agent: test\r\n" - "Connection: upgrade\r\n" - "\r\n" - ); - } // no content-length HTTP/1.1 { message m;