---
title: BodyHandleExt
summary: Extensions to the crate::handle::BodyHandle type to support trailers.
url: https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/experimental/trait.BodyHandleExt/
---

**Kind:** Trait  
**Module:** [experimental](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/experimental/)  
**Package:** fastly 0.13.1  
**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/experimental.rs#431

```rust
pub trait BodyHandleExt {
    // Required methods
    fn get_trailer_names<'a>(
        &'a self,
        buf_size: usize,
    ) -> Result<Box<(dyn Iterator<Item = Result<HeaderName, BufferSizeError>> + 'a)>, BodyHandleError>;
    fn get_trailer_value(
        &self,
        name: &HeaderName,
        max_len: usize,
    ) -> Result<Result<Option<HeaderValue>, BufferSizeError>, BodyHandleError>;
    fn get_trailer_values<'a>(
        &'a self,
        name: &'a HeaderName,
        max_len: usize,
    ) -> Result<Box<(dyn Iterator<Item = Result<HeaderValue, BufferSizeError>> + 'a)>, BodyHandleError>;
}
```

Extensions to the [`crate::handle::BodyHandle`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/handle/struct.BodyHandle/) type to support trailers.

## Methods

### get_trailer_names

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/experimental.rs#440

```rust
fn get_trailer_names<'a>(&'a self, buf_size: usize) -> Result<Box<(dyn Iterator<Item = Result<HeaderName, BufferSizeError>> + 'a)>, BodyHandleError>
```

Get the names of the trailers associated with this body.

The resulting iterator will produce either the header names or an indication
that the provided buffer size was too small. In that case, calling with a
larger buffer size (information about how large a buffer is recommended is
provided in [`BufferSizeError`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/error/struct.BufferSizeError/)) should resolve the situation.
#### Trailers

Trailers can be tricky to access. You must completely read all bytes from the body
before calling this function. The outermost `Result` reflects this requirement; if you
receive [`BodyHandleError::TrailersNotReady`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/experimental/enum.BodyHandleError/), there are potentially more bytes available
in the body that you must read.
#### Stability

This is part of an experimental API that is subject to change or removal even in minor versions of
this crate.

**Parameters**

- `self`: `&Self`
- `buf_size`: `usize`

**Returns**

`Result<Box<(dyn Iterator<Item = Result<HeaderName, BufferSizeError>> + 'a)>, BodyHandleError>`

### get_trailer_value

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/experimental.rs#462

```rust
fn get_trailer_value(&self, name: &HeaderName, max_len: usize) -> Result<Result<Option<HeaderValue>, BufferSizeError>, BodyHandleError>
```

Get the value for the trailer with the given name.

If there are multiple values for this header, only one is returned, which may be
any of the values. See [`BodyHandleExt::get_trailer_values`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/experimental/trait.BodyHandleExt/#method-get_trailer_values) if you need to get
all of the values.

There are several options in the return value, ignoring the common trailer case
in which you must read more data from the body:
   * Ok(Some(value)): The trailer existed, and had the given value
   * Ok(None): A trailer with that name does not exist
   * Err(BufferSizeError): The trailer existed, but the provided max length was
     too small.

In the last case, [`BufferSizeError`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/error/struct.BufferSizeError/) should provide information about what
size buffer will be required to hold the requested data.
#### Trailers

Trailers can be tricky to access. You must completely read all bytes from the body
before calling this function. The outermost `Result` reflects this requirement; if you
receive [`BodyHandleError::TrailersNotReady`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/experimental/enum.BodyHandleError/), there are potentially more bytes available
in the body that you must read.
#### Stability

This is part of an experimental API that is subject to change or removal even in minor versions of
this crate.

**Parameters**

- `self`: `&Self`
- `name`: `&HeaderName`
- `max_len`: `usize`

**Returns**

`Result<Result<Option<HeaderValue>, BufferSizeError>, BodyHandleError>`

### get_trailer_values

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/experimental.rs#474

```rust
fn get_trailer_values<'a>(&'a self, name: &'a HeaderName, max_len: usize) -> Result<Box<(dyn Iterator<Item = Result<HeaderValue, BufferSizeError>> + 'a)>, BodyHandleError>
```

Get all the values associated with the trailer with the given name.

As opposed to [`BodyHandleExt::get_trailer_value`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/experimental/trait.BodyHandleExt/#method-get_trailer_value), this function returns all
of the values for this trailer.
#### Trailers

Trailers can be tricky to access. You must completely read all bytes from the body
before calling this function. The outermost `Result` reflects this requirement; if you
receive [`BodyHandleError::TrailersNotReady`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/experimental/enum.BodyHandleError/), there are potentially more bytes available
in the body that you must read.
#### Stability

This is part of an experimental API that is subject to change or removal even in minor versions of
this crate.

**Parameters**

- `self`: `&Self`
- `name`: `&HeaderName`
- `max_len`: `usize`

**Returns**

`Result<Box<(dyn Iterator<Item = Result<HeaderValue, BufferSizeError>> + 'a)>, BodyHandleError>`
