Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of sum/product Body types is impossible #884

Closed
djarek opened this issue Nov 11, 2017 · 2 comments
Closed

Implementation of sum/product Body types is impossible #884

djarek opened this issue Nov 11, 2017 · 2 comments
Labels
API Change A breaking change Design Open design questions still present

Comments

@djarek
Copy link
Contributor

djarek commented Nov 11, 2017

It is impossible to compose Bodies into sum types, e.g.:

template <typename... Ts>
struct variant_body
{
    using value_type = std::variant<typename Ts::value_type...>;
    struct reader;
    struct writer;
};

using my_body = variant_body<beast::http::empty_body, json_body, beast::http::string_body>;

due to the requirement of Body::reader and Body::writer that the message's body type is exactly the same type as Body. The same restriction applies to product types(not as useful as a variant_body). Not sure how to make this use-case possible without complicating other use-cases.

@vinniefalco
Copy link
Member

How about if we change the constructor of reader and writer to something like this:

template<bool isRequest, class Fields>
void writer(header<isRequest, Fields> const&, value_type const& body);

@djarek
Copy link
Contributor Author

djarek commented Nov 11, 2017

I believe that would solve this issue.

@vinniefalco vinniefalco added API Change A breaking change Design Open design questions still present labels Nov 11, 2017
djarek added a commit to djarek/beast that referenced this issue Dec 10, 2017
This change enables composing bodies into multiple layers e.g.
compressed_body<json_body<T>>. Resolves boostorg#884.

Actions required:
- change body writer constructor signature to
	writer(header<isRequest, Fields> const&, value_type const&)
- change body reader constructor signature to
	reader(header<isRequest, Fields>&, value_type&)

Signed-off-by: Damian Jarek <damian.jarek93@gmail.com>
djarek added a commit to djarek/beast that referenced this issue Dec 12, 2017
This change enables composing bodies into multiple layers e.g.
compressed_body<json_body<T>>. Resolves boostorg#884.
The old concepts signatures are supported if BOOST_BEAST_ALLOW_DEPRECATED
is defined as 1.

Actions required:
- change BodyWriter constructor signature to
	writer(header<isRequest, Fields> const&, value_type const&)
- change BodyReader constructor signature to
	reader(header<isRequest, Fields>&, value_type&)

Signed-off-by: Damian Jarek <damian.jarek93@gmail.com>
djarek added a commit to djarek/beast that referenced this issue Dec 14, 2017
fix boostorg#884

* BodyReader and BodyWriter constructors now require the header and
  body elements to be passed as distinct header and value_type objects.

This enables the composition of body types, for example:

    http::response<compressed_body<http::string_body>> res;

* The previous single-argument constructors are deprecated and will be
  removed in a subsequent version.

Actions Required:

* Change user-defined instances of BodyReader or BodyWriter constructor
  signatures to the two-argument form.

OR

* Define the macro BOOST_BEAST_ALLOW_DEPRECATED in the project (which
  will accept both the new and the deprecated signatures).
vinniefalco pushed a commit to vinniefalco/beast that referenced this issue Dec 14, 2017
fix boostorg#884

* BodyReader and BodyWriter constructors now require the header and
  body elements to be passed as distinct header and value_type objects.

This enables the composition of body types, for example:

    http::response<compressed_body<http::string_body>> res;

* The previous single-argument constructors are deprecated and will be
  removed in a subsequent version.

Actions Required:

* Change user-defined instances of BodyReader or BodyWriter constructor
  signatures to the two-argument form.

OR

* Define the macro BOOST_BEAST_ALLOW_DEPRECATED in the project (which
  will accept both the new and the deprecated signatures).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Change A breaking change Design Open design questions still present
Projects
None yet
Development

No branches or pull requests

2 participants