---
title: Response
summary: An HTTP response, including body, headers, and status code.
url: https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/struct.Response/
---

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

```rust
pub struct Response { /* private fields */ }
```

An HTTP response, including body, headers, and status code.

## Sending to the client

Each execution of a Compute program may send a single response back to the client:

- [`Response::send_to_client()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-send_to_client)
- [`Response::stream_to_client()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-stream_to_client)

If no response is explicitly sent by the program, a default `200 OK` response is sent.

## Creation and conversion

Responses can be created programmatically:

- [`Response::new()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-new)
- [`Response::from_body()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-from_body)
- [`Response::from_status()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-from_status)

Responses are also returned from backend requests:

- [`Request::send()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/request/struct.Request/#method-send)
- [`Request::send_async()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/request/struct.Request/#method-send_async)
- [`Request::send_async_streaming()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/request/struct.Request/#method-send_async_streaming)

For interoperability with other Rust libraries, [`Response`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/) can be converted to and from the
[`http`](https://docs.rs/http/latest/http/index.html) crate's [`http::Response`](https://docs.rs/http/latest/http/response/struct.Response.html) type using the [`From`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#impl-From-Response-Body) and
[`Into`](https://doc.rust-lang.org/stable/core/convert/Into/fn.into.html) traits.

## Builder-style methods

[`Response`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/) can be used as a
[builder](https://doc.rust-lang.org/1.0.0/style/ownership/builders.html), allowing responses to
be constructed and used through method chaining. Methods with the `with_` name prefix, such as
[`with_header()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-with_header), return `Self` to allow chaining. The builder style is
typically most useful when constructing and using a response in a single expression. For
example:

```rust
Response::new()
    .with_header("my-header", "hello!")
    .with_header("my-other-header", "Здравствуйте!")
    .send_to_client();
```

## Setter methods

Setter methods, such as [`set_header()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-set_header), are prefixed by `set_`, and can
be used interchangeably with the builder-style methods, allowing you to mix and match styles
based on what is most convenient for your program. Setter methods tend to work better than
builder-style methods when constructing a value involves conditional branches or loops. For
example:

```rust
let mut resp = Response::new().with_header("my-header", "hello!");
if needs_translation {
    resp.set_header("my-other-header", "Здравствуйте!");
}
resp.send_to_client();
```

## Methods

### append_body

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#477

```rust
fn append_body(&mut self, other: Body)
```

Append another [`Body`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.Body/) to the body of this response without reading or writing any body
contents.

If this response does not have a body, the appended body is set as the response's body.

This operation is performed in amortized constant time, and so should always be preferred to reading
an entire body and then writing the same contents to another body.

This method should be used when combining bodies that have not necessarily been read yet,
such as a body returned from a backend response. To append contents that are already in
memory as strings or bytes, use [`get_body_mut()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-get_body_mut) to write the
contents to the end of the body.

#### Examples

```rust
let mut resp = Response::from_body("hello! backend says: ");
let backend_resp = Request::get("https://example.com/").send("example_backend")?;
resp.append_body(backend_resp.into_body());
resp.send_to_client();
```

**Parameters**

- `self`: `&mut Self`
- `other`: `Body`

### append_header

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1348

```rust
fn append_header(&mut self, name: impl ToHeaderName, value: impl ToHeaderValue)
```

Add a response header with given value.

Unlike [`set_header()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-set_header), this does not discard existing values for the
same header name.

#### Argument type conversion

The header name and value arguments can be any types that implement [`ToHeaderName`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/convert/trait.ToHeaderName/) and
[`ToHeaderValue`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/convert/trait.ToHeaderValue/), respectively. See those traits for details on which types can be used and when
panics may arise during conversion.

#### Examples

```rust
let mut resp = Response::new();

resp.set_header("hello", "world!");
assert_eq!(resp.get_header_str("hello"), Some("world!"));

resp.append_header("hello", "universe!");

let values = resp.get_header_all_str("hello");
assert_eq!(values.len(), 2);
assert!(values.contains(&"world!"));
assert!(values.contains(&"universe!"));
```

**Parameters**

- `self`: `&mut Self`
- `name`: `impl ToHeaderName`
- `value`: `impl ToHeaderValue`

### clone_with_body

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#223

```rust
fn clone_with_body(&mut self) -> Response
```

Clone this response by reading in its body, and then writing the same body to the original
and the cloned response.

This method requires mutable access to this response because reading from and writing to the
body can involve an HTTP connection.

This operation is potentially expensive if the body is large. Take care when using this
method on bodies with unknown sizes. Consider using methods like [`BufRead::lines()`](https://doc.rust-lang.org/stable/alloc/io/buf_read/BufRead/fn.lines.html) or
[`Body::read_chunks()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.Body/#method-read_chunks) to incrementally process a body while limiting the maximum size.

#### Examples

```rust
let mut original = Response::from_body("hello")
    .with_header("hello", "world!")
    .with_status(418);
let mut new = original.clone_with_body();
assert_eq!(original.get_header("hello"), new.get_header("hello"));
assert_eq!(original.get_status(), new.get_status());
assert_eq!(original.get_version(), new.get_version());
assert_eq!(original.take_body_bytes(), new.take_body_bytes());
```

**Parameters**

- `self`: `&mut Self`

**Returns**

`Response`

### clone_without_body

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#191

```rust
fn clone_without_body(&self) -> Response
```

Make a new response with the same headers, status, and version of this response, but no
body.

If you also need to clone the response body, use
[`clone_with_body()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-clone_with_body)

#### Examples

```rust
let original = Response::from_body("hello")
    .with_header("hello", "world!")
    .with_status(418);
let new = original.clone_without_body();
assert_eq!(original.get_header("hello"), new.get_header("hello"));
assert_eq!(original.get_status(), new.get_status());
assert_eq!(original.get_version(), new.get_version());
assert!(original.has_body());
assert!(!new.has_body());
```

**Parameters**

- `self`: `&Self`

**Returns**

`Response`

### contains_header

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1004

```rust
fn contains_header(&self, name: impl ToHeaderName) -> bool
```

Returns whether the given header name is present in the response.

#### Argument type conversion

The header name argument can be any type that implements [`ToHeaderName`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/convert/trait.ToHeaderName/); see that trait for
details on which types can be used and when panics may arise during conversion.

#### Examples

```rust
let resp = Response::new().with_header("hello", "world!");
assert!(resp.contains_header("hello"));
assert!(!resp.contains_header("not-present"));
```

**Parameters**

- `self`: `&Self`
- `name`: `impl ToHeaderName`

**Returns**

`bool`

### from_body

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#267

```rust
fn from_body(body: impl Into<Body>) -> Self
```

Create a new [`Response`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/) with the given value as the body.

#### Argument type conversion

See the `From` impls for [`Body`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.Body/) to see which types can be used as a body.

#### Examples

```rust
let resp = Response::from_body("hello");
assert_eq!(&resp.into_body_str(), "hello");
```

```rust
let body_bytes: &[u8] = &[1, 2, 3];
let resp = Response::from_body(body_bytes);
assert_eq!(resp.into_body_bytes().as_slice(), body_bytes);
```

**Parameters**

- `body`: `impl Into<Body>`

**Returns**

`Self`

### from_handles

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1833

```rust
fn from_handles(resp_handle: ResponseHandle, body_handle: BodyHandle) -> Self
```

Create a [`Response`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/) from the a [`ResponseHandle`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/handle/struct.ResponseHandle/) and a [`BodyHandle`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/handle/struct.BodyHandle/).

The extra metadata associated with a backend response is not tracked by the low-level handle
APIs. As a result, methods like [`get_backend()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-get_backend) and
[`get_backend_request()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-get_backend_request) will always return `None` for a
request created from handles.

**Parameters**

- `resp_handle`: `ResponseHandle`
- `body_handle`: `BodyHandle`

**Returns**

`Self`

### from_status

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#290

```rust
fn from_status(status: impl ToStatusCode) -> Self
```

Create a new response with the given status code.

#### Argument type conversion

See the `From` impls for [`Body`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.Body/) to see which types can be used as a body.

#### Examples

```rust
use fastly::http::StatusCode;
let resp = Response::from_status(StatusCode::NOT_FOUND);
assert_eq!(resp.get_status().as_u16(), 404);
```

```rust
use fastly::http::StatusCode;
let resp = Response::from_status(404);
assert_eq!(resp.get_status(), StatusCode::NOT_FOUND);
```

**Parameters**

- `status`: `impl ToStatusCode`

**Returns**

`Self`

### get_age

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1946

```rust
fn get_age(&self) -> Option<Duration>
```

The current age of the response, if it is cached.

Returns `None` if the response is not cached.

**Parameters**

- `self`: `&Self`

**Returns**

`Option<Duration>`

### get_backend

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1572

```rust
fn get_backend(&self) -> Option<&Backend>
```

Get the backend this response came from, or `None` if the response is synthetic.

#### Examples

From a backend response:

```rust
let backend_resp = Request::get("https://example.com/").send("example_backend")?;
assert_eq!(backend_resp.get_backend().map(|b| b.name()), Some("example_backend"));
```

From a synthetic response:

```rust
let synthetic_resp = Response::new();
assert!(synthetic_resp.get_backend().is_none());
```

**Parameters**

- `self`: `&Self`

**Returns**

`Option<&Backend>`

### get_backend_addr

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1601

```rust
fn get_backend_addr(&self) -> Option<&SocketAddr>
```

Get the address of the backend this response came from, or `None` when the response is
synthetic or cached.

#### Examples

From a backend response:

```rust
let backend_resp = Request::get("https://example.com/")
    .with_pass(true)
    .send("example_backend")?;
assert_eq!(backend_resp.get_backend_addr(), Some(&"127.0.0.1:443".parse::<SocketAddr>().unwrap()));
```

From a synthetic response:

```rust
let synthetic_resp = Response::new();
assert!(synthetic_resp.get_backend_addr().is_none());
```

**Parameters**

- `self`: `&Self`

**Returns**

`Option<&SocketAddr>`

### get_backend_name

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1547

```rust
fn get_backend_name(&self) -> Option<&str>
```

Get the name of the [`Backend`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/) this response came from, or `None` if the response is
synthetic.

#### Examples

From a backend response:

```rust
let backend_resp = Request::get("https://example.com/").send("example_backend")?;
assert_eq!(backend_resp.get_backend_name(), Some("example_backend"));
Ok(()) }
```

From a synthetic response:

```rust
let synthetic_resp = Response::new();
assert!(synthetic_resp.get_backend_name().is_none());
```

**Parameters**

- `self`: `&Self`

**Returns**

`Option<&str>`

### get_backend_request

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1637

```rust
fn get_backend_request(&self) -> Option<&Request>
```

Get the request this response came from, or `None` if the response is synthetic.

Note that the returned request will only have the headers and metadata of the original
request, as the body is consumed when sending the request.

This method only returns a reference to the backend request. To instead take and return the
owned request (for example, to subsequently send the request again), use
[`take_backend_request()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-take_backend_request).

#### Examples

From a backend response:

```rust
let backend_resp = Request::post("https://example.com/")
    .with_body("hello")
    .send("example_backend")?;
let backend_req = backend_resp.get_backend_request().expect("response is not synthetic");
assert_eq!(backend_req.get_url_str(), "https://example.com/");
assert!(!backend_req.has_body());
```

From a synthetic response:

```rust
let synthetic_resp = Response::new();
assert!(synthetic_resp.get_backend_request().is_none());
```

**Parameters**

- `self`: `&Self`

**Returns**

`Option<&Request>`

### get_body_mut

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#372

```rust
fn get_body_mut(&mut self) -> &mut Body
```

Get a mutable reference to the body of this response.

An empty body is returned if no body has been set, or if it has previously been returned by a method
like [`take_body()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-take_body).

#### Examples

```rust
use std::io::Write;

let mut resp = Response::from_body("hello,");
write!(resp.get_body_mut(), " world!")?;
assert_eq!(&resp.into_body_str(), "hello, world!");
```

**Parameters**

- `self`: `&mut Self`

**Returns**

`&mut Body`

### get_body_prefix_mut

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#400

```rust
fn get_body_prefix_mut(&mut self, length: usize) -> Prefix<'_>
```

Get a prefix of this response's body containing up to the given number of bytes.

See [`Body::get_prefix_mut()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.Body/#method-get_prefix_mut) for details.

**Parameters**

- `self`: `&mut Self`
- `length`: `usize`

**Returns**

`body::Prefix`

### get_body_prefix_str_mut

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#417

```rust
fn get_body_prefix_str_mut(&mut self, length: usize) -> PrefixString<'_>
```

Get a prefix of this response's body as a string containing up to the given number of bytes.

See [`Body::get_prefix_str_mut()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.Body/#method-get_prefix_str_mut) for details.

#### Panics

If the prefix contains invalid UTF-8 bytes, this function will panic. The exception to this
is if the bytes are invalid because a multi-byte codepoint is cut off by the requested
prefix length. In this case, the invalid bytes are left off the end of the prefix.

To explicitly handle the possibility of invalid UTF-8 bytes, use
[`try_get_body_prefix_str_mut()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-try_get_body_prefix_str_mut), which returns an
error on failure rather than panicking.

**Parameters**

- `self`: `&mut Self`
- `length`: `usize`

**Returns**

`body::PrefixString`

### get_content_length

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#986

```rust
fn get_content_length(&self) -> Option<usize>
```

Get the value of the response's
[`Content-Length`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Length)
header, if it exists.

**Parameters**

- `self`: `&Self`

**Returns**

`Option<usize>`

### get_content_type

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#955

```rust
fn get_content_type(&self) -> Option<Mime>
```

Get the MIME type described by the response's
[`Content-Type`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type)
header, or `None` if that header is absent or contains an invalid MIME type.

#### Examples

```rust
let resp = Response::new().with_body_text_plain("hello, world!");
assert_eq!(resp.get_content_type(), Some(fastly::mime::TEXT_PLAIN_UTF_8));
```

**Parameters**

- `self`: `&Self`

**Returns**

`Option<Mime>`

### get_header

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1105

```rust
fn get_header(&self, name: impl ToHeaderName) -> Option<&HeaderValue>
```

Get the value of a header, or `None` if the header is not present.

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

#### Argument type conversion

The header name argument can be any type that implements [`ToHeaderName`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/convert/trait.ToHeaderName/); see that trait for
details on which types can be used and when panics may arise during conversion.

#### Examples

Handling UTF-8 values explicitly:

```rust
let resp = Response::new().with_header("hello", "world!");
assert_eq!(resp.get_header("hello"), Some(&HeaderValue::from_static("world")));
```

Safely handling invalid UTF-8 values:

```rust
let invalid_utf8 = &"🐈".as_bytes()[0..3];
let resp = Response::new().with_header("hello", invalid_utf8);
assert_eq!(resp.get_header("hello").unwrap().as_bytes(), invalid_utf8);
```

**Parameters**

- `self`: `&Self`
- `name`: `impl ToHeaderName`

**Returns**

`Option<&HeaderValue>`

### get_header_all

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1241

```rust
fn get_header_all(&self, name: impl ToHeaderName) -> impl Iterator<Item = &HeaderValue>
```

Get an iterator of all the values of a header.

#### Argument type conversion

The header name argument can be any type that implements [`ToHeaderName`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/convert/trait.ToHeaderName/); see that trait for
details on which types can be used and when panics may arise during conversion.

#### Examples

You can turn the iterator into collection, like [`Vec`](https://doc.rust-lang.org/stable/alloc/vec/struct.Vec.html):

```rust
let invalid_utf8 = &"🐈".as_bytes()[0..3];
let resp = Response::new()
    .with_header("hello", "world!")
    .with_header("hello", invalid_utf8);

let values: Vec<&HeaderValue> = resp.get_header_all("hello").collect();
assert_eq!(values.len(), 2);
assert!(values.contains(&&HeaderValue::from_static("world!")));
assert!(values.contains(&&HeaderValue::from_bytes(invalid_utf8).unwrap()));
```

You can use the iterator in a loop:

```rust
let invalid_utf8 = &"🐈".as_bytes()[0..3];
let resp = Response::new()
    .with_header("hello", "world!")
    .with_header("hello", invalid_utf8);

for value in resp.get_header_all("hello") {
    if let Ok(s) = std::str::from_utf8(value.as_bytes()) {
        println!("hello, {}", s);
    } else {
        println!("hello, invalid UTF-8!");
    }
}
```

**Parameters**

- `self`: `&Self`
- `name`: `impl ToHeaderName`

**Returns**

`impl Iterator<Item = &HeaderValue>`

### get_header_all_str

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1129

```rust
fn get_header_all_str(&self, name: impl ToHeaderName) -> Vec<&str>
```

Get all values of a header as strings, or an empty vector if the header is not present.

#### Argument type conversion

The header name argument can be any type that implements [`ToHeaderName`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/convert/trait.ToHeaderName/); see that trait for
details on which types can be used and when panics may arise during conversion.

#### Panics

This method panics if any of the header values are not valid UTF-8 strings. To handle the
possibility of non-UTF-8 data, use
[`get_header_all_str_lossy()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-get_header_all_str_lossy) for lossy conversion, or use
[`get_header_all()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-get_header_all) and then convert the bytes with
[`std::str::from_utf8()`](https://doc.rust-lang.org/stable/core/str/converts/fn.from_utf8.html).

#### Examples

```rust
let resp = Response::new()
    .with_header("hello", "world!")
    .with_header("hello", "universe!");
let values = resp.get_header_all_str("hello");
assert_eq!(values.len(), 2);
assert!(values.contains(&"world!"));
assert!(values.contains(&"universe!"));
```

**Parameters**

- `self`: `&Self`
- `name`: `impl ToHeaderName`

**Returns**

`Vec<&str>`

### get_header_all_str_lossy

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1196

```rust
fn get_header_all_str_lossy(&self, name: impl ToHeaderName) -> Vec<Cow<'_, str>>
```

Get all values of a header as strings, including invalid characters, or an empty vector if the header is not present.

Only the valid UTF-8 characters present are returned.
Invalid UTF-8 characters are replaced with `U+FFFD REPLACEMENT CHARACTER`.

#### Argument type conversion

The header name argument can be any type that implements [`ToHeaderName`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/convert/trait.ToHeaderName/); see that trait for
details on which types can be used and when panics may arise during conversion.

#### Examples

```rust
let world_value = HeaderValue::from_bytes(b"\xF0\x90\x80 world!").unwrap();
let universe_value = HeaderValue::from_bytes(b"\xF0\x90\x80 universe!").unwrap();
let resp = Response::new()
    .with_header("hello", world_value)
    .with_header("hello", universe_value);
let values = resp.get_header_all_str_lossy("hello");
assert_eq!(values.len(), 2);
assert!(values.contains(&Cow::from("� world!")));
assert!(values.contains(&Cow::from("� universe!")));
```

**Parameters**

- `self`: `&Self`
- `name`: `impl ToHeaderName`

**Returns**

`Vec<Cow<str>>`

### get_header_names

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1295

```rust
fn get_header_names(&self) -> impl Iterator<Item = &HeaderName>
```

Get an iterator of all the response's header names.

#### Examples

You can turn the iterator into a collection, like [`Vec`](https://doc.rust-lang.org/stable/alloc/vec/struct.Vec.html):

```rust
let resp = Response::new()
    .with_header("hello", "world!")
    .with_header("goodbye", "latency!");

let values: Vec<&HeaderName> = resp.get_header_names().collect();
assert_eq!(values.len(), 2);
assert!(values.contains(&&HeaderName::from_static("hello")));
assert!(values.contains(&&HeaderName::from_static("goodbye")));
```

You can use the iterator in a loop:

```rust
let resp = Response::new()
    .with_header("hello", "world!")
    .with_header("goodbye", "latency!");

for name in resp.get_header_names() {
    println!("saw header: {:?}", name);
}
```

**Parameters**

- `self`: `&Self`

**Returns**

`impl Iterator<Item = &HeaderName>`

### get_header_names_str

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1260

```rust
fn get_header_names_str(&self) -> Vec<&str>
```

Get all of the response's header names as strings, or an empty vector if no headers are
present.

#### Examples

```rust
let resp = Response::new()
    .with_header("hello", "world!")
    .with_header("goodbye", "latency!");
let names = resp.get_header_names_str();
assert_eq!(names.len(), 2);
assert!(names.contains(&"hello"));
assert!(names.contains(&"goodbye"));
```

**Parameters**

- `self`: `&Self`

**Returns**

`Vec<&str>`

### get_header_str

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1039

```rust
fn get_header_str(&self, name: impl ToHeaderName) -> Option<&str>
```

Get the value of a header as a string, or `None` if the header is not present.

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

#### Argument type conversion

The header name argument can be any type that implements [`ToHeaderName`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/convert/trait.ToHeaderName/); see that trait for
details on which types can be used and when panics may arise during conversion.

#### Panics

This method panics if the value of the header is not a valid UTF-8 string. To handle the possibility
of invalid UTF-8 data, use [`get_header_str_lossy()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-get_header_str_lossy) for lossy
conversion, or use [`get_header()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-get_header) and then convert the bytes with
[`std::str::from_utf8()`](https://doc.rust-lang.org/stable/core/str/converts/fn.from_utf8.html).

#### Examples

```rust
let resp = Response::new().with_header("hello", "world!");
assert_eq!(resp.get_header_str("hello"), Some("world"));
```

**Parameters**

- `self`: `&Self`
- `name`: `impl ToHeaderName`

**Returns**

`Option<&str>`

### get_header_str_lossy

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1073

```rust
fn get_header_str_lossy(&self, name: impl ToHeaderName) -> Option<Cow<'_, str>>
```

Get the value of a header as a string, including invalid characters, or `None` if the header
is not present.

Only the valid UTF-8 characters present are returned.
Invalid UTF-8 characters are replaced with `U+FFFD REPLACEMENT CHARACTER`.

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

#### Argument type conversion

The header name argument can be any type that implements [`ToHeaderName`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/convert/trait.ToHeaderName/); see that trait for
details on which types can be used and when panics may arise during conversion.

#### Examples

```rust
let header_value = HeaderValue::from_bytes(b"\xF0\x90\x80 world!").unwrap();
let resp = Response::new().with_header("hello", header_value);
assert_eq!(resp.get_header_str_lossy("hello"), Some(Cow::from("� world")));
```

**Parameters**

- `self`: `&Self`
- `name`: `impl ToHeaderName`

**Returns**

`Option<Cow<str>>`

### get_headers

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1170

```rust
fn get_headers(&self) -> impl Iterator<Item = (&HeaderName, &HeaderValue)>
```

Get an iterator of all the response's header names and values.

#### Examples

You can turn the iterator into a collection, like [`Vec`](https://doc.rust-lang.org/stable/alloc/vec/struct.Vec.html):

```rust
let resp = Response::new()
    .with_header("hello", "world!")
    .with_header("hello", "universe!");

let headers: Vec<(&HeaderName, &HeaderValue)> = resp.get_headers().collect();
assert_eq!(headers.len(), 2);
assert!(headers.contains(&(&HeaderName::from_static("hello"), &HeaderValue::from_static("world!"))));
assert!(headers.contains(&(&HeaderName::from_static("hello"), &HeaderValue::from_static("universe!"))));
```

You can use the iterator in a loop:

```rust
let resp = Response::new()
    .with_header("hello", "world!")
    .with_header("hello", "universe!");

for (n, v) in resp.get_headers() {
    println!("Header -  {}: {:?}", n, v);
}
```

**Parameters**

- `self`: `&Self`

**Returns**

`impl Iterator<Item = (&HeaderName, &HeaderValue)>`

### get_masked_error

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1991

```rust
fn get_masked_error(&self) -> Option<&SendErrorCause>
```

If this Response represents a stale-if-error response, returns the SendErrorCause that
this response replaced. If this Response is not a stale-if-error response from cache,
returns None.

**Parameters**

- `self`: `&Self`

**Returns**

`Option<&SendErrorCause>`

### get_stale_if_error

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1981

```rust
fn get_stale_if_error(&self) -> Option<Duration>
```

Gets the time for which the response can safely be used if (synchronous) revalidation
produces an error.

This time is relative to the start of the "stale" period; that is, it matches the meaning
of the `Cache-Control: stale-if-error=` directive in [RFC 5861](https://datatracker.ietf.org/doc/html/rfc5861).
See [Fastly's documentation on HTTP caching](https://www.fastly.com/documentation/guides/concepts/cache/stale/) for more details.

Returns `None` if the response is not cached.

**Parameters**

- `self`: `&Self`

**Returns**

`Option<Duration>`

### get_stale_while_revalidate

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1963

```rust
fn get_stale_while_revalidate(&self) -> Option<Duration>
```

The time for which the response can safely be used despite being considered stale, if it is cached.

This time is relative to the start of the "stale" period; that is, it matches the meaning
of the `Cache-Control: stale-while-revalidate=` directive in [RFC 5861](https://datatracker.ietf.org/doc/html/rfc5861).
See [Fastly's documentation on HTTP caching](https://www.fastly.com/documentation/guides/concepts/cache/stale/) for more details.

Returns `None` if the response is not cached.

**Parameters**

- `self`: `&Self`

**Returns**

`Option<Duration>`

### get_status

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1439

```rust
fn get_status(&self) -> StatusCode
```

Get the HTTP status code of the response.

**Parameters**

- `self`: `&Self`

**Returns**

`StatusCode`

### get_ttl

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1935

```rust
fn get_ttl(&self) -> Option<Duration>
```

Get the Time to Live (TTL) in the cache for this response, if it is cached.

The TTL provides the duration of "freshness" for the cached response
after it is inserted into the cache. If the response is stale,
the TTL is 0 (i.e. this returns `Some(0)`.

Returns `None` if the response is not cached.

**Parameters**

- `self`: `&Self`

**Returns**

`Option<Duration>`

### get_version

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1480

```rust
fn get_version(&self) -> Version
```

Get the HTTP version of this response.

**Parameters**

- `self`: `&Self`

**Returns**

`Version`

### has_body

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#352

```rust
fn has_body(&self) -> bool
```

Returns `true` if this response has a body.

**Parameters**

- `self`: `&Self`

**Returns**

`bool`

### into_body

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#541

```rust
fn into_body(self) -> Body
```

Consume the response and return its body.

An empty body is returned if no body has been set, or if it has previously been returned by a method
like [`take_body()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-take_body).

**Parameters**

- `self`: `Self`

**Returns**

`Body`

### into_body_bytes

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#495

```rust
fn into_body_bytes(self) -> Vec<u8>
```

Consume the response and return its body as a byte vector.

#### Memory usage

This method will cause the entire body to be buffering in WebAssembly memory. You should take care
not to exceed the WebAssembly memory limits, and consider using methods like
[`read_body_lines()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-read_body_lines) or
[`read_body_chunks()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-read_body_chunks) to control how much of the body you process at
once.
#### Examples

```rust
let resp = Response::from_body("hello, world!");
let bytes = resp.into_body_bytes();
assert_eq!(&bytes, b"hello, world!");

**Parameters**

- `self`: `Self`

**Returns**

`Vec<u8>`

### into_body_str

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#515

```rust
fn into_body_str(self) -> String
```

Consume the response and return its body as a string.

#### Memory usage

This method will cause the entire body to be buffering in WebAssembly memory. You should take care
not to exceed the WebAssembly memory limits, and consider using methods like
[`read_body_lines()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-read_body_lines) or
[`read_body_chunks()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-read_body_chunks) to control how much of the body you process at
once.

#### Panics

If the body does not contain a valid UTF-8 string, this function will panic. To explicitly handle
the possibility of invalid UTF-8 data, use [`into_body_str_lossy()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-into_body_str_lossy)
for lossy conversion, or use [`into_body_bytes()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-into_body_bytes) and then convert the
bytes explicitly with a function like [`String::from_utf8`](https://doc.rust-lang.org/stable/alloc/string/String/fn.from_utf8.html).

#### Examples

```rust
let resp = Response::from_body("hello, world!");
let string = resp.into_body_str();
assert_eq!(&string, "hello, world!");
```

**Parameters**

- `self`: `Self`

**Returns**

`String`

### into_body_str_lossy

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#534

```rust
fn into_body_str_lossy(self) -> String
```

Consume the response and return its body as a string, including invalid characters.

Only the valid UTF-8 characters present are returned.
Invalid UTF-8 characters are replaced with `U+FFFD REPLACEMENT CHARACTER`.

#### Memory usage

This method will cause the entire body to be buffering in WebAssembly memory. You should take care
not to exceed the WebAssembly memory limits, and consider using methods like
[`read_body_lines()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-read_body_lines) or
[`read_body_chunks()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-read_body_chunks) to control how much of the body you process at
once.

#### Examples

```rust
let mut resp = Response::new();
resp.set_body_octet_stream(b"\xF0\x90\x80 hello, world!");
let string = resp.into_body_str_lossy();
assert_eq!(&string, "� hello, world!");
```

**Parameters**

- `self`: `Self`

**Returns**

`String`

### into_handles

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1870

```rust
fn into_handles(self) -> (ResponseHandle, BodyHandle)
```

Create a [`ResponseHandle`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/handle/struct.ResponseHandle/)/[`BodyHandle`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/handle/struct.BodyHandle/) pair from a [`Response`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/).

The extra metadata associated with a backend response is not tracked by the low-level handle
APIs. As a result, converting to handles will cause the backend and request associated with
a backend response to be lost.

**Parameters**

- `self`: `Self`

**Returns**

`(ResponseHandle, BodyHandle)`

### is_from_backend

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#167

```rust
fn is_from_backend(&self) -> bool
```

Return whether the response is from a backend request.

**Parameters**

- `self`: `&Self`

**Returns**

`bool`

### new

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#152

```rust
fn new() -> Self
```

Create a new [`Response`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/).

The new response is created with status code `200 OK`, no headers, and an empty body.

**Returns**

`Self`

### read_body_chunks

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#744

```rust
fn read_body_chunks(&mut self, chunk_size: usize) -> impl Iterator<Item = Result<Vec<u8>, Error>> + '_
```

Return an iterator that reads the response body in chunks of at most the given number of
bytes.

If `chunk_size` does not evenly divide the length of the body, then the last chunk will not
have length `chunk_size`.

#### Examples

```rust
use std::io::Write;
fn remove_0s(resp: &mut Response) -> Result<(), Box<dyn std::error::Error>>  {
    let mut no_0s = Body::new();
    for chunk in resp.read_body_chunks(4096) {
        let mut chunk = chunk?;
        chunk.retain(|b| *b != 0);
        no_0s.write_all(&chunk)?;
    }
    resp.set_body(no_0s);
    Ok(())
}
```

**Parameters**

- `self`: `&mut Self`
- `chunk_size`: `usize`

**Returns**

`impl Iterator<Item = Result<Vec<u8>, Error>> + '_`

### read_body_lines

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#670

```rust
fn read_body_lines(&mut self) -> Lines<&mut Body>
```

Return a [`Lines`](https://doc.rust-lang.org/stable/alloc/io/util/struct.Lines.html) iterator that reads the response body a line at a time.

#### Examples

```rust
use std::io::Write;

fn remove_es(resp: &mut Response) -> Result<(), Box<dyn std::error::Error>>  {
    let mut no_es = Body::new();
    for line in resp.read_body_lines() {
        writeln!(no_es, "{}", line?.replace("e", ""))?;
    }
    resp.set_body(no_es);
    Ok(())
}
```

**Parameters**

- `self`: `&mut Self`

**Returns**

`std::io::Lines<&mut Body>`

### redirect

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#322

```rust
fn redirect(destination: impl ToHeaderValue) -> Self
```

Create a 308 Permanent Redirect response with the given value as the `Location` header.

#### Examples

```rust
let resp = Response::redirect("https://www.fastly.com");
assert_eq!(resp.get_status(), StatusCode::PERMANENT_REDIRECT);
assert_eq!(resp.get_header_str(header::LOCATION).unwrap(), "https://www.fastly.com");
```

**Parameters**

- `destination`: `impl ToHeaderValue`

**Returns**

`Self`

### remove_header

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1372

```rust
fn remove_header(&mut self, name: impl ToHeaderName) -> Option<HeaderValue>
```

Remove all response headers of the given name, and return one of the removed header values
if any were present.

If the header has multiple values, one is returned arbitrarily. To get all of the removed
header values, or to get a specific value, use
[`get_header_all()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-get_header_all).

#### Argument type conversion

The header name argument can be any type that implements [`ToHeaderName`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/convert/trait.ToHeaderName/); see that trait for
details on which types can be used and when panics may arise during conversion.

#### Examples

```rust
let mut resp = Response::new().with_header("hello", "world!");
assert_eq!(resp.get_header_str("hello"), Some("world!"));
assert_eq!(resp.remove_header("hello"), Some(HeaderValue::from_static("world!")));
assert!(resp.remove_header("not-present").is_none());
```

**Parameters**

- `self`: `&mut Self`
- `name`: `impl ToHeaderName`

**Returns**

`Option<HeaderValue>`

### remove_header_str

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1397

```rust
fn remove_header_str(&mut self, name: impl ToHeaderName) -> Option<String>
```

Remove all response headers of the given name, and return one of the removed header values
as a string if any were present.

If the header has multiple values, one is returned arbitrarily. To get all of the removed header
values, use [`get_header_all()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-get_header_all) before removing.

#### Argument type conversion

The header name argument can be any type that implements [`ToHeaderName`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/convert/trait.ToHeaderName/); see that trait for
details on which types can be used and when panics may arise during conversion.

#### Panics

This method panics if the value of the header is not a valid UTF-8 string. To handle the possibility
of invalid UTF-8 data, use [`remove_header_str_lossy()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-remove_header_str_lossy) for lossy
conversion, or use [`remove_header()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-remove_header) and then convert the bytes with
[`std::str::from_utf8()`](https://doc.rust-lang.org/stable/core/str/converts/fn.from_utf8.html).

#### Examples

```rust
let mut resp = Response::new().with_header("hello", "world!");
assert_eq!(resp.get_header_str("hello"), Some("world!"));
assert_eq!(resp.remove_header_str("hello"), Some("world!".to_string()));
assert!(resp.remove_header_str("not-present").is_none());
```

**Parameters**

- `self`: `&mut Self`
- `name`: `impl ToHeaderName`

**Returns**

`Option<String>`

### remove_header_str_lossy

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1427

```rust
fn remove_header_str_lossy(&mut self, name: impl ToHeaderName) -> Option<String>
```

Remove all response headers of the given name, and return one of the removed header values
as a string, including invalid characters, if any were present.

Only the valid UTF-8 characters present are returned.
Invalid UTF-8 characters are replaced with `U+FFFD REPLACEMENT CHARACTER`.

If the header has multiple values, one is returned arbitrarily. To get all of the removed header
values, use [`get_header_all()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-get_header_all) before removing.

#### Argument type conversion

The header name argument can be any type that implements [`ToHeaderName`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/convert/trait.ToHeaderName/); see that trait for
details on which types can be used and when panics may arise during conversion.

#### Examples

```rust
let header_value = HeaderValue::from_bytes(b"\xF0\x90\x80 world!").unwrap();
let mut resp = Response::new().with_header("hello", header_value);
assert_eq!(resp.get_header_str_lossy("hello"), Some(Cow::from("� world")));
assert_eq!(resp.remove_header_str_lossy("hello"), Some(String::from("� world")));
assert!(resp.remove_header_str_lossy("not-present").is_none());
```

**Parameters**

- `self`: `&mut Self`
- `name`: `impl ToHeaderName`

**Returns**

`Option<String>`

### see_other

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#305

```rust
fn see_other(destination: impl ToHeaderValue) -> Self
```

Create a 303 See Other response with the given value as the `Location` header.

#### Examples

```rust
let resp = Response::see_other("https://www.fastly.com");
assert_eq!(resp.get_status(), StatusCode::SEE_OTHER);
assert_eq!(resp.get_header_str(header::LOCATION).unwrap(), "https://www.fastly.com");
```

**Parameters**

- `destination`: `impl ToHeaderValue`

**Returns**

`Self`

### send_to_client

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1735

```rust
fn send_to_client(self)
```

Begin sending a response to the client.

This method returns as soon as the response header begins sending to the client, and
transmission of the response will continue in the background.

This method may be used to send `103 Early Hints` responses to the client. Any number of
`103 Early Hints` responses may be sent before sending the final response. Any response
with status code other than `103` will be treated as the final response.

Once this method is called with a final response, nothing else may be added to the response
body. To stream additional data to a response body after it begins to send, use
[`stream_to_client`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-stream_to_client).

#### Panics

This method panics if any response with status code other than `103` has already been sent
to the client by this method, by [`stream_to_client()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-stream_to_client), or
by the equivalent methods of [`ResponseHandle`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/handle/struct.ResponseHandle/).

#### Compatibility with [`fastly::main`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/attr.main/)

This method cannot be used to send final responses with
[`fastly::main`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/attr.main/), as that attribute implicitly calls
[`Response::send_to_client()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-send_to_client) on the returned response. Use an
undecorated `main()` function instead, along with
[`Request::from_client()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/request/struct.Request/#method-from_client) if the client request is needed.

#### Examples

Sending a backend response without modification:

```rust
Request::get("https://example.com/").send("example_backend")?.send_to_client();
```

Removing a header from a backend response before sending to the client:

```rust
let mut backend_resp = Request::get("https://example.com/").send("example_backend")?;
backend_resp.remove_header("bad-header");
backend_resp.send_to_client();
```

Sending a synthetic response:

```rust
Response::from_body("hello, world!").send_to_client();
```

Sending `103 Early Hints` responses followed by forwarding a final response from a backend:
```rust
use fastly::{Error, Request, Response};
#[fastly::main]
fn main(ds_req: Request) -> Result<Response, Error> {
    let early_hint = Response::from_status(103)
       .with_header("Link", "</script.js>; rel=preload; as=scrypt");
    early_hint.send_to_client();
    Ok(ds_req.send("example_backend")?)
}
```

**Parameters**

- `self`: `Self`

### set_body

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#434

```rust
fn set_body(&mut self, body: impl Into<Body>)
```

Set the given value as the response's body.
#### Argument type conversion

See the `From` impls for [`Body`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.Body/) to see which types can be used as a body.
Any previous body that may have been set on the response is discarded. To add to an existing body,
use [`get_body_mut()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-get_body_mut) and write to the returned [`Body`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.Body/).

**Parameters**

- `self`: `&mut Self`
- `body`: `impl Into<Body>`

### set_body_form

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#898

```rust
fn set_body_form(&mut self, value: &impl Serialize) -> Result<(), Error>
```

Convert the given value to `application/x-www-form-urlencoded` format and set that data as
the response's body.

The given value must implement [`serde::Serialize`](https://docs.rs/serde_core/1.0.228/serde_core/ser/trait.Serialize.html); see the trait documentation for
details.

Any previous body that may have been set on the response is discarded. To add to an existing body,
use [`get_body_mut()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-get_body_mut) and write to the returned [`Body`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.Body/).

#### Content type

This method sets the content type to `application/x-www-form-urlencoded`.

#### Errors

This method returns [`serde_urlencoded::ser::Error`](https://docs.rs/serde_urlencoded/latest/serde_urlencoded/ser/enum.Error.html) if serialization fails.

#### Examples

```rust
#[derive(serde::Serialize)]
struct MyData {
    name: String,
    count: u64,
}
let my_data = MyData { name: "Computers".to_string(), count: 1024 };
let mut resp = Response::new();
resp.set_body_form(&my_data).unwrap();
assert_eq!(resp.get_content_type(), Some(fastly::mime::APPLICATION_WWW_FORM_URLENCODED));
assert_eq!(&resp.into_body_str(), "name=Computers&count=1024");
```

**Parameters**

- `self`: `&mut Self`
- `value`: `&impl Serialize`

**Returns**

`Result<(), serde_urlencoded::ser::Error>`

### set_body_json

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#801

```rust
fn set_body_json(&mut self, value: &impl Serialize) -> Result<(), Error>
```

Convert the given value to JSON and set that JSON as the response's body.

The given value must implement [`serde::Serialize`](https://docs.rs/serde_core/1.0.228/serde_core/ser/trait.Serialize.html). You can either implement that trait for
your own custom type, or use [`serde_json::Value`](https://docs.rs/serde_json/1.0.145/serde_json/value/enum.Value.html) to create untyped JSON values. See
[`serde_json`](https://docs.rs/serde_json/1.0.145/serde_json/index.html) for details.

Any previous body that may have been set on the response is discarded. To add to an existing body,
use [`get_body_mut()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-get_body_mut) and write to the returned [`Body`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.Body/).
#### Content type

This method sets the content type to `application/json`.

#### Errors

This method returns [`serde_json::Error`](https://docs.rs/serde_json/1.0.145/serde_json/error/struct.Error.html) if serialization fails.

#### Examples

Using a type that derives [`serde::Serialize`](https://docs.rs/serde_core/1.0.228/serde_core/ser/trait.Serialize.html):

```rust
#[derive(serde::Serialize)]
struct MyData {
    name: String,
    count: u64,
}
let my_data = MyData { name: "Computers".to_string(), count: 1024 };
let mut resp = Response::new();
resp.set_body_json(&my_data).unwrap();
assert_eq!(resp.get_content_type(), Some(fastly::mime::APPLICATION_JSON));
assert_eq!(&resp.into_body_str(), r#"{"name":"Computers","count":1024}"#);
```

Using untyped JSON and the [`serde_json::json`](https://docs.rs/serde_json/1.0.145/serde_json/macro.json.html) macro:

```rust
let my_data = serde_json::json!({
    "name": "Computers",
    "count": 1024,
});
let mut resp = Response::new();
resp.set_body_json(&my_data).unwrap();
assert_eq!(resp.get_content_type(), Some(fastly::mime::APPLICATION_JSON));
assert_eq!(&resp.into_body_str(), r#"{"count":1024,"name":"Computers"}"#);
```

**Parameters**

- `self`: `&mut Self`
- `value`: `&impl Serialize`

**Returns**

`Result<(), serde_json::Error>`

### set_body_octet_stream

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#694

```rust
fn set_body_octet_stream(&mut self, body: &[u8])
```

Set the given bytes as the response's body.

Any previous body that may have been set on the response is discarded. To add to an existing body,
use [`get_body_mut()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-get_body_mut) and write to the returned [`Body`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.Body/).
#### Content type

This method sets the content type to `application/octet-stream`.

#### Examples

```rust
let mut resp = Response::new();
resp.set_body_octet_stream(b"hello, world!");
assert_eq!(resp.get_content_type(), Some(fastly::mime::APPLICATION_OCTET_STREAM));
assert_eq!(&resp.into_body_bytes(), b"hello, world!");
```

**Parameters**

- `self`: `&mut Self`
- `body`: `&[u8]`

### set_body_text_html

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#595

```rust
fn set_body_text_html(&mut self, body: &str)
```

Set the given string as the response's body with content type `text/html; charset=UTF-8`.

Any previous body that may have been set on the response is discarded. To add to an existing body,
use [`get_body_mut()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-get_body_mut) and write to the returned [`Body`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.Body/).
#### Content type

This method sets the content type to `text/html; charset=utf-8`.

#### Examples

```rust
let mut resp = Response::new();
resp.set_body_text_html("<p>hello, world!</p>");
assert_eq!(resp.get_content_type(), Some(fastly::mime::TEXT_HTML_UTF_8));
assert_eq!(&resp.into_body_str(), "<p>hello, world!</p>");
```

**Parameters**

- `self`: `&mut Self`
- `body`: `&str`

### set_body_text_plain

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#570

```rust
fn set_body_text_plain(&mut self, body: &str)
```

Set the given string as the response's body with content type `text/plain; charset=UTF-8`.

Any previous body that may have been set on the response is discarded. To add to an existing body,
use [`get_body_mut()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-get_body_mut) and write to the returned [`Body`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.Body/).
#### Content type

This method sets the content type to `text/plain; charset=utf-8`.

#### Examples

```rust
let mut resp = Response::new();
resp.set_body_text_plain("hello, world!");
assert_eq!(resp.get_content_type(), Some(fastly::mime::TEXT_PLAIN_UTF_8));
assert_eq!(&resp.into_body_str(), "hello, world!");
```

**Parameters**

- `self`: `&mut Self`
- `body`: `&str`

### set_content_type

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#979

```rust
fn set_content_type(&mut self, mime: Mime)
```

Set the MIME type described by the response's
[`Content-Type`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type)
header.

Any existing `Content-Type` header values will be overwritten.

#### Examples

```rust
let mut resp = Response::new().with_body("hello,world!");
resp.set_content_type(fastly::mime::TEXT_CSV_UTF_8);
```

**Parameters**

- `self`: `&mut Self`
- `mime`: `Mime`

### set_framing_headers_mode

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1493

```rust
fn set_framing_headers_mode(&mut self, mode: FramingHeadersMode)
```

Sets how `Content-Length` and `Transfer-Encoding` will be determined when sending this
response.

See [`FramingHeadersMode`](https://docs.rs/fastly_shared/latest/fastly_shared/enum.FramingHeadersMode.html) for details on the options.

**Parameters**

- `self`: `&mut Self`
- `mode`: `FramingHeadersMode`

### set_header

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1320

```rust
fn set_header(&mut self, name: impl ToHeaderName, value: impl ToHeaderValue)
```

Set a response header to the given value, discarding any previous values for the given
header name.

#### Argument type conversion

The header name and value arguments can be any types that implement [`ToHeaderName`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/convert/trait.ToHeaderName/) and
[`ToHeaderValue`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/convert/trait.ToHeaderValue/), respectively. See those traits for details on which types can be used and when
panics may arise during conversion.

#### Examples

```rust
let mut resp = Response::new();

resp.set_header("hello", "world!");
assert_eq!(resp.get_header_str("hello"), Some("world!"));

resp.set_header("hello", "universe!");

let values = resp.get_header_all_str("hello");
assert_eq!(values.len(), 1);
assert!(!values.contains(&"world!"));
assert!(values.contains(&"universe!"));
```

**Parameters**

- `self`: `&mut Self`
- `name`: `impl ToHeaderName`
- `value`: `impl ToHeaderValue`

### set_status

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1468

```rust
fn set_status(&mut self, status: impl ToStatusCode)
```

Set the HTTP status code of the response.

#### Argument type conversion

The status code argument can be any type that implements [`ToStatusCode`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/convert/trait.ToStatusCode/); see that trait for
details on which types can be used and when panics may arise during conversion.

#### Examples

Using the constants from [`StatusCode`](https://docs.rs/http/latest/http/status/struct.StatusCode.html):

```rust
use fastly::http::StatusCode;

let mut resp = Response::from_body("not found!");
resp.set_status(StatusCode::NOT_FOUND);
resp.send_to_client();
```

Using a `u16`:

```rust
let mut resp = Response::from_body("not found!");
resp.set_status(404);
resp.send_to_client();
```

**Parameters**

- `self`: `&mut Self`
- `status`: `impl ToStatusCode`

### set_version

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1485

```rust
fn set_version(&mut self, version: Version)
```

Set the HTTP version of this response.

**Parameters**

- `self`: `&mut Self`
- `version`: `Version`

### stream_to_client

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1789

```rust
fn stream_to_client(self) -> StreamingBody
```

Begin sending the response to the client, and return a [`StreamingBody`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.StreamingBody/) that can accept
further data to send.

The client connection must be closed when finished writing the response by calling
[`StreamingBody::finish()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.StreamingBody/#method-finish).

This method is most useful for programs that do some sort of processing or inspection of a
potentially-large backend response body. Streaming allows the program to operate on small
parts of the body rather than having to read it all into memory at once.

This method returns as soon as the response header begins sending to the client, and
transmission of the response will continue in the background.

#### Panics

This method panics if another response has already been sent to the client by this method,
by [`send_to_client()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-send_to_client), or by the equivalent methods of
[`ResponseHandle`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/handle/struct.ResponseHandle/).

#### Compatibility with [`fastly::main`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/attr.main/)

This method cannot be used to send final responses with
[`fastly::main`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/attr.main/), as that attribute implicitly calls
[`Response::send_to_client()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-send_to_client) on the returned response. Use an
undecorated `main()` function instead, along with
[`Request::from_client()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/request/struct.Request/#method-from_client) if the client request is needed.

#### Examples

Count the number of lines in a UTF-8 backend response body while sending it to the client:

```rust
use std::io::{BufRead, Write};

let mut backend_resp = Request::get("https://example.com/").send("example_backend")?;
// Take the body so we can iterate through its lines later
let backend_resp_body = backend_resp.take_body();
// Start sending the backend response to the client with a now-empty body
let mut client_body = backend_resp.stream_to_client();

let mut num_lines = 0;
for line in backend_resp_body.lines() {
    let line = line?;
    num_lines += 1;
    // Write the line to the streaming client body
    client_body.write_all(line.as_bytes())?;
}
// Finish the streaming body to close the client connection
client_body.finish()?;

println!("backend response body contained {} lines", num_lines);
```

**Parameters**

- `self`: `Self`

**Returns**

`StreamingBody`

### take_backend_request

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1670

```rust
fn take_backend_request(&mut self) -> Option<Request>
```

Take and return the request this response came from, or `None` if the response is synthetic.

Note that the returned request will only have the headers and metadata of the original
request, as the body is consumed when sending the request.

#### Examples

From a backend response:

```rust
let mut backend_resp = Request::post("https://example.com/")
    .with_body("hello")
    .send("example_backend")?;
let backend_req = backend_resp.take_backend_request().expect("response is not synthetic");
assert_eq!(backend_req.get_url_str(), "https://example.com/");
assert!(!backend_req.has_body());
backend_req.with_body("goodbye").send("example_backend")?;
```

From a synthetic response:

```rust
let mut synthetic_resp = Response::new();
assert!(synthetic_resp.take_backend_request().is_none());
```

**Parameters**

- `self`: `&mut Self`

**Returns**

`Option<Request>`

### take_body

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#443

```rust
fn take_body(&mut self) -> Body
```

Take and return the body from this response.

After calling this method, this response will no longer have a body.

An empty body is returned if no body has been set, or if it has previously been returned by a method
like [`take_body()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-take_body).

**Parameters**

- `self`: `&mut Self`

**Returns**

`Body`

### take_body_bytes

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#714

```rust
fn take_body_bytes(&mut self) -> Vec<u8>
```

Take and return the body from this response as a string.

After calling this method, this response will no longer have a body.

#### Memory usage

This method will cause the entire body to be buffering in WebAssembly memory. You should take care
not to exceed the WebAssembly memory limits, and consider using methods like
[`read_body_lines()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-read_body_lines) or
[`read_body_chunks()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-read_body_chunks) to control how much of the body you process at
once.

#### Examples

```rust
let mut resp = Response::from_body("hello, world!");
let bytes = resp.take_body_bytes();
assert!(resp.try_take_body().is_none());
assert_eq!(&bytes, b"hello, world!");
```

**Parameters**

- `self`: `&mut Self`

**Returns**

`Vec<u8>`

### take_body_form

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#934

```rust
fn take_body_form<T: DeserializeOwned>(&mut self) -> Result<T, Error>
```

Take the response body and attempt to parse it as a `application/x-www-form-urlencoded`
formatted string.

The return type chosen for this function must implement [`serde::de::Deserialize`](https://docs.rs/serde_core/1.0.228/serde_core/de/trait.Deserialize.html) without any
non-static lifetimes; see the trait documentation for details.

After calling this method, this response will no longer have a body.

#### Errors

This method returns [`serde_urlencoded::de::Error`](https://docs.rs/serde_core/1.0.228/serde_core/de/value/struct.Error.html) if deserialization fails.

#### Examples

```rust
#[derive(serde::Deserialize)]
struct MyData {
    name: String,
    count: u64,
}
let mut resp = Response::from_body("name=Computers&count=1024");
let my_data = resp.take_body_form::<MyData>().unwrap();
assert_eq!(&my_data.name, "Computers");
assert_eq!(my_data.count, 1024);
```

**Parameters**

- `self`: `&mut Self`

**Returns**

`Result<T, serde_urlencoded::de::Error>`

### take_body_json

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#850

```rust
fn take_body_json<T: DeserializeOwned>(&mut self) -> Result<T, Error>
```

Take the response body and attempt to parse it as a JSON value.

The return type must implement [`serde::Deserialize`](https://docs.rs/serde_core/1.0.228/serde_core/de/trait.Deserialize.html) without any non-static lifetimes. You
can either implement that trait for your own custom type, or use [`serde_json::Value`](https://docs.rs/serde_json/1.0.145/serde_json/value/enum.Value.html) to
deserialize untyped JSON values. See [`serde_json`](https://docs.rs/serde_json/1.0.145/serde_json/index.html) for details.

After calling this method, this response will no longer have a body.

#### Errors

This method returns [`serde_json::Error`](https://docs.rs/serde_json/1.0.145/serde_json/error/struct.Error.html) if deserialization fails.

#### Examples

Using a type that derives [`serde::de::DeserializeOwned`](https://docs.rs/serde_core/1.0.228/serde_core/de/trait.DeserializeOwned.html):

```rust
#[derive(serde::Deserialize)]
struct MyData {
    name: String,
    count: u64,
}
let mut resp = Response::from_body(r#"{"name":"Computers","count":1024}"#);
let my_data = resp.take_body_json::<MyData>().unwrap();
assert_eq!(&my_data.name, "Computers");
assert_eq!(my_data.count, 1024);
```

Using untyped JSON with [`serde_json::Value`](https://docs.rs/serde_json/1.0.145/serde_json/value/enum.Value.html):

```rust
let my_data = serde_json::json!({
    "name": "Computers",
    "count": 1024,
});
let mut resp = Response::from_body(r#"{"name":"Computers","count":1024}"#);
let my_data = resp.take_body_json::<serde_json::Value>().unwrap();
assert_eq!(my_data["name"].as_str(), Some("Computers"));
assert_eq!(my_data["count"].as_u64(), Some(1024));
```

**Parameters**

- `self`: `&mut Self`

**Returns**

`Result<T, serde_json::Error>`

### take_body_str

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#619

```rust
fn take_body_str(&mut self) -> String
```

Take and return the body from this response as a string.

After calling this method, this response will no longer have a body.

#### Memory usage

This method will cause the entire body to be buffering in WebAssembly memory. You should take care
not to exceed the WebAssembly memory limits, and consider using methods like
[`read_body_lines()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-read_body_lines) or
[`read_body_chunks()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-read_body_chunks) to control how much of the body you process at
once.

#### Panics

If the body does not contain a valid UTF-8 string, this function will panic. To handle the
possibility of invalid UTF-8 data, use [`take_body_str_lossy()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-take_body_str_lossy) for
lossy conversion, or use [`take_body_bytes()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-take_body_bytes) and then convert the bytes
with a function like [`String::from_utf8`](https://doc.rust-lang.org/stable/alloc/string/String/fn.from_utf8.html).

#### Examples

```rust
let mut resp = Response::from_body("hello, world!");
let string = resp.take_body_str();
assert!(resp.try_take_body().is_none());
assert_eq!(&string, "hello, world!");
```

**Parameters**

- `self`: `&mut Self`

**Returns**

`String`

### take_body_str_lossy

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#645

```rust
fn take_body_str_lossy(&mut self) -> String
```

Take and return the body from this response as a string, including invalid characters.

Only the valid UTF-8 characters present are returned.
Invalid UTF-8 characters are replaced with `U+FFFD REPLACEMENT CHARACTER`.

After calling this method, this response will no longer have a body.

#### Memory usage

This method will cause the entire body to be buffering in WebAssembly memory. You should take care
not to exceed the WebAssembly memory limits, and consider using methods like
[`read_body_lines()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-read_body_lines) or
[`read_body_chunks()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-read_body_chunks) to control how much of the body you process at
once.

#### Examples

```rust
let mut resp = Response::new();
resp.set_body_octet_stream(b"\xF0\x90\x80 hello, world!");
let string = resp.take_body_str_lossy();
assert!(resp.try_take_body().is_none());
assert_eq!(&string, "� hello, world!");
```

**Parameters**

- `self`: `&mut Self`

**Returns**

`String`

### take_masked_error

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#2001

```rust
fn take_masked_error(&mut self) -> Option<SendError>
```

If this Response represents a stale-if-error response, returns the SendError that
this response replaced. If this Response is not a stale-if-error response from cache,
returns None.

This also returns None if [Response::take_backend_request](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-take_backend_request) was called previously.
(The `SendError` includes the backend request.)

**Parameters**

- `self`: `&mut Self`

**Returns**

`Option<SendError>`

### temporary_redirect

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#339

```rust
fn temporary_redirect(destination: impl ToHeaderValue) -> Self
```

Create a 307 Temporary Redirect response with the given value as the `Location` header.

#### Examples

```rust
let resp = Response::temporary_redirect("https://www.fastly.com");
assert_eq!(resp.get_status(), StatusCode::TEMPORARY_REDIRECT);
assert_eq!(resp.get_header_str(header::LOCATION).unwrap(), "https://www.fastly.com");
```

**Parameters**

- `destination`: `impl ToHeaderValue`

**Returns**

`Self`

### try_get_body_mut

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#393

```rust
fn try_get_body_mut(&mut self) -> Option<&mut Body>
```

Get a shared reference to the body of this response if it has one, otherwise return `None`.

#### Examples

```rust
use std::io::Write;

let mut resp = Response::new();
assert!(resp.try_get_body_mut().is_none());

resp.set_body("hello,");
write!(resp.try_get_body_mut().expect("body now exists"), " world!")?;
assert_eq!(&resp.into_body_str(), "hello, world!");
```

**Parameters**

- `self`: `&mut Self`

**Returns**

`Option<&mut Body>`

### try_get_body_prefix_str_mut

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#424

```rust
fn try_get_body_prefix_str_mut(&mut self, length: usize) -> Result<PrefixString<'_>, Utf8Error>
```

Try to get a prefix of the body as a string containing up to the given number of bytes.

See [`Body::try_get_prefix_str_mut()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.Body/#method-try_get_prefix_str_mut) for details.

**Parameters**

- `self`: `&mut Self`
- `length`: `usize`

**Returns**

`Result<body::PrefixString, std::str::Utf8Error>`

### try_into_body

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#546

```rust
fn try_into_body(self) -> Option<Body>
```

Consume the response and return its body if it has one, otherwise return `None`.

**Parameters**

- `self`: `Self`

**Returns**

`Option<Body>`

### try_take_body

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#450

```rust
fn try_take_body(&mut self) -> Option<Body>
```

Take and return the body from this response if it has one, otherwise return `None`.

After calling this method, this response will no longer have a body.

**Parameters**

- `self`: `&mut Self`

**Returns**

`Option<Body>`

### with_body

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#346

```rust
fn with_body(self, body: impl Into<Body>) -> Self
```

Builder-style equivalent of [`set_body()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-set_body).

**Parameters**

- `self`: `Self`
- `body`: `impl Into<Body>`

**Returns**

`Self`

### with_body_form

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#859

```rust
fn with_body_form(self, value: &impl Serialize) -> Result<Self, Error>
```

Builder-style equivalent of [`set_body_form()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-set_body_form).

**Parameters**

- `self`: `Self`
- `value`: `&impl Serialize`

**Returns**

`Result<Self, serde_urlencoded::ser::Error>`

### with_body_json

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#752

```rust
fn with_body_json(self, value: &impl Serialize) -> Result<Self, Error>
```

Builder-style equivalent of [`set_body_json()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-set_body_json).

**Parameters**

- `self`: `Self`
- `value`: `&impl Serialize`

**Returns**

`Result<Self, serde_json::Error>`

### with_body_octet_stream

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#675

```rust
fn with_body_octet_stream(self, body: &[u8]) -> Self
```

Builder-style equivalent of [`set_body_octet_stream()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-set_body_octet_stream).

**Parameters**

- `self`: `Self`
- `body`: `&[u8]`

**Returns**

`Self`

### with_body_text_html

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#576

```rust
fn with_body_text_html(self, body: &str) -> Self
```

Builder-style equivalent of [`set_body_text_html()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-set_body_text_html).

**Parameters**

- `self`: `Self`
- `body`: `&str`

**Returns**

`Self`

### with_body_text_plain

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#551

```rust
fn with_body_text_plain(self, body: &str) -> Self
```

Builder-style equivalent of [`set_body_text_plain()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-set_body_text_plain).

**Parameters**

- `self`: `Self`
- `body`: `&str`

**Returns**

`Self`

### with_content_type

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#961

```rust
fn with_content_type(self, mime: Mime) -> Self
```

Builder-style equivalent of [`set_content_type()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-set_content_type).

**Parameters**

- `self`: `Self`
- `mime`: `Mime`

**Returns**

`Self`

### with_framing_headers_mode

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1499

```rust
fn with_framing_headers_mode(self, mode: FramingHeadersMode) -> Self
```

Builder-style equivalent of
[`set_framing_headers_mode()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-set_framing_headers_mode).

**Parameters**

- `self`: `Self`
- `mode`: `FramingHeadersMode`

**Returns**

`Self`

### with_header

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1009

```rust
fn with_header(self, name: impl ToHeaderName, value: impl ToHeaderValue) -> Self
```

Builder-style equivalent of [`append_header()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-append_header).

**Parameters**

- `self`: `Self`
- `name`: `impl ToHeaderName`
- `value`: `impl ToHeaderValue`

**Returns**

`Self`

### with_set_header

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1015

```rust
fn with_set_header(self, name: impl ToHeaderName, value: impl ToHeaderValue) -> Self
```

Builder-style equivalent of [`set_header()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-set_header).

**Parameters**

- `self`: `Self`
- `name`: `impl ToHeaderName`
- `value`: `impl ToHeaderValue`

**Returns**

`Self`

### with_status

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1433

```rust
fn with_status(self, status: impl ToStatusCode) -> Self
```

Builder-style equivalent of [`set_status()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-set_status).

**Parameters**

- `self`: `Self`
- `status`: `impl ToStatusCode`

**Returns**

`Self`

### with_version

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#1474

```rust
fn with_version(self, version: Version) -> Self
```

Builder-style equivalent of [`set_version()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-set_version).

**Parameters**

- `self`: `Self`
- `version`: `Version`

**Returns**

`Self`

## Trait implementations

### impl Debug for Response

#### fmt

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#97

```rust
fn fmt(&self, f: &mut Formatter<'_>) -> Result
```

**Parameters**

- `self`: `&Self`
- `f`: `&mut $crate::fmt::Formatter`

**Returns**

`$crate::fmt::Result`

### impl Default for Response

#### default

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#143

```rust
fn default() -> Self
```

**Returns**

`Self`

### impl From<Response<Body>> for Response

#### from

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#2021

```rust
fn from(from: Response<Body>) -> Self
```

**Parameters**

- `from`: `http::Response<Body>`

**Returns**

`Self`

### impl From<(ResponseHandle, BodyHandle)> for Response

#### from

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#2043

```rust
fn from(pair: (ResponseHandle, BodyHandle)) -> Self
```

**Parameters**

- `pair`: `(ResponseHandle, BodyHandle)`

**Returns**

`Self`

### impl HandlerResult for Response

#### send

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/serve.rs#94

```rust
fn send(self) -> Result<(), Self::Error>
```

**Parameters**

- `self`: `Self`

**Returns**

`Result<(), Self::Error>`

## Auto trait implementations

- `Freeze`
- `RefUnwindSafe`
- `Send`
- `Sync`
- `Unpin`
- `UnsafeUnpin`
- `UnwindSafe`

## Blanket implementations

- `Any`
- `Borrow<T>`
- `BorrowMut<T>`
- `Downcast`
- `ErasedDestructor`
- `From<T>`
- `Into<U>`
- `IntoEither`
- `Same`
- `TryFrom<U>`
- `TryInto<U>`
