Body
Include fastly/http/body.h to use this class.
Extends std::iostream, std::streambuf.
An HTTP body that can be read from, written to, or appended to another body.
The most efficient ways to read from and write to the body are through the iostreams implementations. If you want a non-panicking interface, you can use Body::read and Body::write directly, instead.
Read and write operations to a Body are automatically buffered.
Constructor
Overload 1 of 6
fastly::http::Body::Body()Get a new, empty HTTP body.
Overload 2 of 6
fastly::http::Body::Body(Body &&old)Parameters
- old: Body &&
Overload 3 of 6
Parameters
- body_vec: std::vector<uint8_t>
Overload 4 of 6
fastly::http::Body::Body(std::string body_str)Parameters
- body_str: std::string
Overload 5 of 6
fastly::http::Body::Body(const char *body_str)Parameters
- body_str: const char *
Overload 6 of 6
fastly::http::Body::Body(std::string_view body_str)Parameters
- body_str: std::string_view
Methods
append
View sourcevoid fastly::http::Body::append(Body other)Append another body onto the end of this body.
Parameters
- other: Body
Returns
append_trailer
View sourcefastly::expected<void> fastly::http::Body::append_trailer(std::string_view header_name, std::string_view header_value)Appends request or response trailers to the body.
Parameters
- header_name: std::string_view
- header_value: std::string_view
Returns
read
View sourceRead bytes from the body, and return the number of bytes read. Bytes read will be 0 when the Body is or has become empty.
Unlike operator<<, this operation will return a fastly::unexpected<FastlyError> that can then be handled if the read itself fails, instead of aborting the entire process.
Parameters
- buf: uint8_t *
- bufsize: size_t
Returns
take_body_string
View sourcestd::string fastly::http::Body::take_body_string()Take the entire body as a string.
Returns
write
View sourceWrite bytes to the end of this body, and return the number of bytes written. Bytes written will be 0 on EOF.
Unlike operator<<, this operation will return a fastly::unexpected<FastlyError> that can then be handled if the write itself fails, instead of aborting the entire process.
Parameters
- buf: uint8_t *
- bufsize: size_t
Returns