beast icon indicating copy to clipboard operation
beast copied to clipboard

P0083r3 for basic_fields

Open arun11299 opened this issue 8 years ago • 6 comments

Version: 90

Just wanted to know if a "merge" API for header would make a sense or not. I have a situation where I need to have some sort of default set of headers which can either be customised by a client code by providing another header. So, instead of doing the regular (and inefficient) way of iterating and performing a "set", using the "merge" operation of intrusive list would be better.

WDYT ?

arun11299 avatar Jul 30 '17 08:07 arun11299

I don't understand what you're trying to do. Could you please provide a very simple piece of example code?

vinniefalco avatar Jul 30 '17 12:07 vinniefalco

Yeah, I think a pseudo code would be good.

// Client side code

Request r;
beast::http::request_header<> h;
//...fill headers here
r.send(h);
OR
r.send({ {"e", "f"}, {"a", "z"} });

// Library code

class Request
{
public:
    Request() {
        fill_in_defaults();
    }

    void send(const std::initializer_list<std::pair<beast::string_view, beast::string_view>>&);
    void send(const beast::http::request_header<>&);

private:
    void fill_in_defaults() {
        headers_.set("a", "b");
        headers_.set("c", "d");
     }

private:
    beast::http::request_header<> headers_;
};

Assume that the send operation creates the complete request and dispatches it and it has 2 overloads, one taking an initializer-list and the other taking a beast header itself.

So, in the overload taking the beast::http::request_header, what would be the most efficient way to merge it with the headers_ member ? I would think the intrusive_list merge operation would be good to have in such cases.

Please let me know if there is anything I can add to make it more clear.

arun11299 avatar Jul 31 '17 07:07 arun11299

How would you feel about something like this: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0083r3.pdf

Example of use: http://en.cppreference.com/w/cpp/container/map/merge

vinniefalco avatar Jul 31 '17 14:07 vinniefalco

Hmm..yes. That is a cool feature. But since beast is making use of boost::intrusive_list, the functionality is already there. Or are you planning to move to std::containers ?

arun11299 avatar Aug 01 '17 07:08 arun11299

I'm saying that http::basic_fields could offer the same feature as described in P0083r3. So you would have basic_fields::node_handle, basic_fields::extract(), and basic_fields::merge().

vinniefalco avatar Aug 01 '17 13:08 vinniefalco

Oh..ok. That would be nice.

arun11299 avatar Aug 01 '17 13:08 arun11299