Body

Classin httpcompute-sdk-cpp 0.7.0View source

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()
View source

Get a new, empty HTTP body.

Overload 2 of 6

fastly::http::Body::Body(Body &&old)
View source

Parameters

old: Body &&

Overload 3 of 6

fastly::http::Body::Body(std::vector<uint8_t> body_vec)
View source

Parameters

body_vec: std::vector<uint8_t>

Overload 4 of 6

fastly::http::Body::Body(std::string body_str)
View source

Parameters

body_str: std::string

Overload 5 of 6

fastly::http::Body::Body(const char *body_str)
View source

Parameters

body_str: const char *

Overload 6 of 6

fastly::http::Body::Body(std::string_view body_str)
View source

Parameters

body_str: std::string_view

Methods

void fastly::http::Body::append(Body other)

Append another body onto the end of this body.

Parameters

other: Body

Returns

void

append_trailer

View source
fastly::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

fastly::expected<void>
fastly::expected<size_t> fastly::http::Body::read(uint8_t *buf, size_t bufsize)

Read 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

fastly::expected<size_t>

take_body_string

View source
std::string fastly::http::Body::take_body_string()

Take the entire body as a string.

Returns

std::string
fastly::expected<size_t> fastly::http::Body::write(uint8_t *buf, size_t bufsize)

Write 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

fastly::expected<size_t>