beast icon indicating copy to clipboard operation
beast copied to clipboard

Is `keep_alive` intentionally not implemented for `header`?

Open inetic opened this issue 3 months ago • 4 comments

The keep_alive function is implemented for message but it only requires information from the header. Due to this, any function that composes a response header needs to take the whole message unnecessarily.

Our work around is to just re-implement the keep_alive function and use that, but I'm wondering if there is a reason I'm missing for the exclusion or whether is just hasn't been a priority to have it in header.

inetic avatar Oct 09 '25 08:10 inetic

The implementation is actually in header. I don't know why it is in message. Try patching Beast and see if it works? Maybe we could merge it.

vinniefalco avatar Oct 09 '25 14:10 vinniefalco

I think the reason might be that request_header and response_header are two separate classes, and keep_alive is common to both request and response messages. Moving it to the header would lead to code duplication. As for why it is not in basic_fields, it might be to keep basic_fields limited to functioning as a container.

ashtum avatar Oct 09 '25 17:10 ashtum

the implementation of keep_alive() depends on knowing if the message is a request or a response, which is not possible in basic_fields.

vinniefalco avatar Oct 09 '25 21:10 vinniefalco

the implementation of keep_alive() depends on knowing if the message is a request or a response, which is not possible in basic_fields.

I think keep_alive is a common field in both request and response and the implementation doesn't check for that either. However, it requires the message version, which is only available in request_header and response_header:
https://github.com/boostorg/beast/blob/9b24b28d502946583300d3e58767cb30a8ec8486/include/boost/beast/http/impl/fields.hpp#L817

ashtum avatar Oct 10 '25 05:10 ashtum