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

**Kind:** Class  
**Module:** [http](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/http/)  
**Package:** compute-sdk-cpp 0.7.0  
**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L94

Include `fastly/http/response.h` to use this class.

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/cpp/fastly/http/class.Response/#method-send_to_client)
- [`Response::stream_to_client()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/http/class.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()`
- [`Response::from_body()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/http/class.Response/#method-from_body)
- [`Response::from_status()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/http/class.Response/#method-from_status)

Responses are also returned from backend requests:

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

#### Builder-style methods

[`Response`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/http/class.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 [`Response::with_header()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/http/class.Response/#method-with_header), return `std::move(*this)` to allow chaining. The builder style is typically most useful when constructing and using a response in a single expression. For example:

#### Setter methods

Setter methods, such as [`Response::set_header()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/http/class.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:

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

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

## Constructor

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L107

```cpp
fastly::http::Response::Response()
```

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

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

## Methods

### append_body

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L201

```cpp
void fastly::http::Response::append_body(Body body)
```

Append another [`Body`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/http/class.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 method should be used when combining bodies that have not necessarily been read yet, such as a body returned from a backend response.

###### Examples

**Parameters**

- `body`: `Body`

**Returns**

`void`

```cpp
auto resp{Response::from_body("hello! backend says: ")};
auto backend_resp{
  Request::get("https://example.com/").send("example_backend")
};
resp.append_body(backend_resp.into_body());
resp.send_to_client();
```

### append_header

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L303

```cpp
fastly::expected<void> fastly::http::Response::append_header(std::string_view name, std::string_view value)
```

Add a request header with given value.

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

**Parameters**

- `name`: `std::string_view`
- `value`: `std::string_view`

**Returns**

`fastly::expected<void>`

### clone_with_body

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L124

```cpp
Response fastly::http::Response::clone_with_body()
```

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.

**Returns**

`Response`

### clone_without_body

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L117

```cpp
Response fastly::http::Response::clone_without_body()
```

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 [`Response::clone_with_body()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/http/class.Response/#method-clone_with_body).

**Returns**

`Response`

### contains_header

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L269

```cpp
fastly::expected<bool> fastly::http::Response::contains_header(std::string_view name)
```

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

**Parameters**

- `name`: `std::string_view`

**Returns**

`fastly::expected<bool>`

### from_body

**Flags:** static  
**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L127

```cpp
static Response fastly::http::Response::from_body(Body body)
```

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

**Parameters**

- `body`: `Body`

**Returns**

`Response`

### from_status

**Flags:** static  
**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L130

```cpp
static Response fastly::http::Response::from_status(StatusCode status)
```

Create a new response with the given status code.

**Parameters**

- `status`: `StatusCode`

**Returns**

`Response`

### get_age

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L550

```cpp
std::optional<std::chrono::milliseconds> fastly::http::Response::get_age()
```

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

Returns `std::nullopt` if the response is not cached.

**Returns**

`std::optional<std::chrono::milliseconds>`

### get_backend

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L393

```cpp
std::optional<fastly::backend::Backend> fastly::http::Response::get_backend()
```

Get the backend this response came from, or `std::nullopt` if the response is synthetic.

###### Examples

From a backend response:

From a synthetic response:

**Returns**

`std::optional<fastly::backend::Backend>`

```cpp
auto backend_resp{
  Request::get("https://example.com/").send("example_backend")
};
assert(
  backend_resp.get_backend() ==
  std::optional(Backend::from_name("example_backend"))
);
```

```cpp
Response synthetic_resp;
assert(synthetic_resp.get_backend() == std::nullopt);
```

### get_backend_addr

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L417

```cpp
std::optional<std::string> fastly::http::Response::get_backend_addr()
```

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

###### Examples

From a backend response:

From a synthetic response:

**Returns**

`std::optional<std::string>`

```cpp
auto backend_resp{Request::get("https://example.com/")
    .with_pass(true)
    .send("example_backend")};
assert(
   backend_resp.get_backend_addr() ==
   std::optional("127.0.0.1:443"));
```

```cpp
Response synthetic_resp;
assert(synthetic_resp.get_backend_addr() == std::nullopt);
```

### get_backend_name

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L368

```cpp
std::optional<std::string> fastly::http::Response::get_backend_name()
```

Get the name of the `Backend` this response came from, or `std::nullopt` if the response is synthetic.

###### Examples

From a backend response:

From a synthetic response:

**Returns**

`std::optional<std::string>`

```cpp
auto
backend_resp{Request::get("https://example.com/").send("example_backend")};
assert(backend_resp.get_backend_name(),
std::optional("example_backend"));
```

```cpp
Response synthetic_resp;
assert(synthetic_resp.get_backend_name() == std::nullopt);
```

### get_content_length

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L266

```cpp
std::optional<size_t> fastly::http::Response::get_content_length()
```

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.

**Returns**

`std::optional<size_t>`

### get_content_type

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L250

```cpp
std::optional<std::string> fastly::http::Response::get_content_type()
```

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 `std::nullopt` if that header is absent or contains an invalid MIME type.

**Returns**

`std::optional<std::string>`

### get_header

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L287

```cpp
fastly::expected<std::optional<HeaderValue>> fastly::http::Response::get_header(std::string_view name)
```

Get the value of a header, or `std::nullopt` 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 [`Response::get_header_all()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/http/class.Response/#method-get_header_all) all of the values.

**Parameters**

- `name`: `std::string_view`

**Returns**

`fastly::expected<std::optional<HeaderValue>>`

### get_header_all

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L290

```cpp
fastly::expected<HeaderValuesRange> fastly::http::Response::get_header_all(std::string_view name)
```

Get an iterator of all the values of a header.

**Parameters**

- `name`: `std::string_view`

**Returns**

`fastly::expected<HeaderValuesRange>`

### get_header_names

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L292

```cpp
fastly::expected<HeaderNamesRange> fastly::http::Response::get_header_names()
```

**Returns**

`fastly::expected<HeaderNamesRange>`

### get_headers

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L291

```cpp
fastly::expected<HeadersRange> fastly::http::Response::get_headers()
```

**Returns**

`fastly::expected<HeadersRange>`

### get_stale_while_revalidate

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L556

```cpp
std::optional<std::chrono::milliseconds> fastly::http::Response::get_stale_while_revalidate()
```

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

Returns `std::nullopt` if the response is not cached.

**Returns**

`std::optional<std::chrono::milliseconds>`

### get_ttl

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L545

```cpp
std::optional<std::chrono::milliseconds> fastly::http::Response::get_ttl()
```

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 `std::optional(0)`.

Returns `std::nullopt` if the response is not cached.

**Returns**

`std::optional<std::chrono::milliseconds>`

### get_version

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L339

```cpp
Version fastly::http::Response::get_version()
```

Get the HTTP version of this response.

**Returns**

`Version`

### has_body

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L172

```cpp
bool fastly::http::Response::has_body()
```

Returns `true` if this response has a body.

**Returns**

`bool`

### into_body

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L210

```cpp
Body fastly::http::Response::into_body()
```

Consume the response and return its body.

**Returns**

`Body`

### into_body_bytes

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L204

```cpp
std::vector<uint8_t> fastly::http::Response::into_body_bytes()
```

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

**Returns**

`std::vector<uint8_t>`

### into_body_string

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L207

```cpp
std::string fastly::http::Response::into_body_string()
```

Consume the response and return its body as a string.

**Returns**

`std::string`

### is_from_backend

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L110

```cpp
bool fastly::http::Response::is_from_backend()
```

Return whether the response is from a backend request.

**Returns**

`bool`

### redirect

**Flags:** static  
**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L154

```cpp
static Response fastly::http::Response::redirect(std::string_view destination)
```

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

###### Examples

**Parameters**

- `destination`: `std::string_view`

**Returns**

`Response`

```cpp
auto resp{Response::redirect("https://www.fastly.com")};
assert(resp.get_status() == StatusCode::PERMANENT_REDIRECT);
assert(resp.get_header("Location").value(), "https://www.fastly.com");
```

### remove_header

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L309

```cpp
fastly::expected<std::optional<std::string>> fastly::http::Response::remove_header(std::string_view name)
```

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

**Parameters**

- `name`: `std::string_view`

**Returns**

`fastly::expected<std::optional<std::string>>`

### see_other

**Flags:** static  
**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L142

```cpp
static Response fastly::http::Response::see_other(std::string_view destination)
```

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

###### Examples

**Parameters**

- `destination`: `std::string_view`

**Returns**

`Response`

```cpp
auto resp{Response::see_other("https://www.fastly.com")};
assert(resp.get_status() == StatusCode::SEE_OTHER);
assert(resp.get_header("Location").value(), "https://www.fastly.com");
```

### send_to_client

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L483

```cpp
void fastly::http::Response::send_to_client()
```

Begin sending the 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.

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

###### Panics

This method panics if another response has already been sent to the client by this method, by [`Response::stream_to_client()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/http/class.Response/#method-stream_to_client).

###### Examples

Sending a backend response without modification:

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

Sending a synthetic response:

**Returns**

`void`

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

```cpp
auto
backend_resp{Request::get("https://example.com/").send("example_backend")};
backend_resp.remove_header("bad-header");
backend_resp.send_to_client();
```

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

### set_body

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L175

```cpp
void fastly::http::Response::set_body(Body body)
```

Set the given value as the response's body.

**Parameters**

- `body`: `Body`

**Returns**

`void`

### set_body_octet_stream

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L239

```cpp
void fastly::http::Response::set_body_octet_stream(std::vector<uint8_t> body)
```

Set the given bytes as the response's body with content type `application/octet-stream`.

**Parameters**

- `body`: `std::vector<uint8_t>`

**Returns**

`void`

### set_body_text_html

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L226

```cpp
fastly::expected<void> fastly::http::Response::set_body_text_html(std::string_view body)
```

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

**Parameters**

- `body`: `std::string_view`

**Returns**

`fastly::expected<void>`

### set_body_text_plain

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L218

```cpp
fastly::expected<void> fastly::http::Response::set_body_text_plain(std::string_view body)
```

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

**Parameters**

- `body`: `std::string_view`

**Returns**

`fastly::expected<void>`

### set_content_type

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L261

```cpp
void fastly::http::Response::set_content_type(std::string_view 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.

**Parameters**

- `mime`: `std::string_view`

**Returns**

`void`

### set_header

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L296

```cpp
fastly::expected<void> fastly::http::Response::set_header(std::string_view name, std::string_view value)
```

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

**Parameters**

- `name`: `std::string_view`
- `value`: `std::string_view`

**Returns**

`fastly::expected<void>`

### set_status

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L333

```cpp
void fastly::http::Response::set_status(StatusCode status)
```

Set the HTTP status code of the response.

###### Examples

Using the constants from [`StatusCode`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/http/class.StatusCode/):

Using a `uint16_t`:

**Parameters**

- `status`: `StatusCode`

**Returns**

`void`

```cpp
auto resp{fastly::Response::from_body("not found!")};
resp.set_status(fastly::http::StatusCode::NOT_FOUND);
resp.send_to_client();
```

```cpp
auto resp{fastly::Response::from_body("not found!")};
resp.set_status(404);
resp.send_to_client();
```

### set_version

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L342

```cpp
void fastly::http::Response::set_version(Version version)
```

Set the HTTP version of this response.

**Parameters**

- `version`: `Version`

**Returns**

`void`

### stream_to_client

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L535

```cpp
StreamingBody fastly::http::Response::stream_to_client()
```

Begin sending the response to the client, and return a [`StreamingBody`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/http/class.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/cpp/fastly/http/class.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 [`Response::send_to_client()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/http/class.Response/#method-send_to_client).

###### Examples

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

**Returns**

`StreamingBody`

```cpp
auto backend_resp{
   Request::get("https://example.com/").send("example_backend")
};

// Take the body so we can iterate through its lines later
auto backend_resp_body{backend_resp.take_body()};

// Start sending the backend response to the client with a now-empty body
auto client_body{backend_resp.stream_to_client()};

size_t num_lines{0};
std::string line;
while (getline(backend_resp_body, line)) {
  num_lines++;
  client_body << line;
}
// Finish the streaming body to close the client connection.
client_body.finish();

std::cout
  << "backend response body contained "
  << num_lines
  << " lines"
  << std::endl;
```

### take_backend_request

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L445

```cpp
std::optional<Request> fastly::http::Response::take_backend_request()
```

Take and return the request this response came from, or `std::nullopt` 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:

From a synthetic response:

**Returns**

`std::optional<Request>`

```cpp
auto backend_resp{Request::post("https://example.com/")
    .with_body("hello")
    .send("example_backend")};
auto backend_req{backend_resp.take_backend_request().value()};
assert(backend_req.get_url() == "https://example.com/");
assert(!backend_req.has_body());
backend_req.with_body("goodbye").send("example_backend");
```

```cpp
Response synthetic_resp;
assert(synthetic_resp.take_backend_request() == std::nullopt);
```

### take_body

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L180

```cpp
Body fastly::http::Response::take_body()
```

Take and return the body from this response.

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

**Returns**

`Body`

### take_body_bytes

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L244

```cpp
std::vector<uint8_t> fastly::http::Response::take_body_bytes()
```

Take and return the body from this response as a vector of bytes.

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

**Returns**

`std::vector<uint8_t>`

### take_body_string

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L231

```cpp
std::string fastly::http::Response::take_body_string()
```

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

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

**Returns**

`std::string`

### temporary_redirect

**Flags:** static  
**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L166

```cpp
static Response fastly::http::Response::temporary_redirect(std::string_view destination)
```

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

###### Examples

**Parameters**

- `destination`: `std::string_view`

**Returns**

`Response`

```cpp
auto resp{Response::temporary_redirect("https://www.fastly.com")};
assert(resp.get_status() == StatusCode::TEMPORARY_REDIRECT);
assert(resp.get_header("Location").value(), "https://www.fastly.com");
```

### with_body

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L169

```cpp
Response fastly::http::Response::with_body(Body body) &&
```

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

**Parameters**

- `body`: `Body`

**Returns**

`Response`

### with_body_octet_stream

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L235

```cpp
Response fastly::http::Response::with_body_octet_stream(std::vector<uint8_t> body) &&
```

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

**Parameters**

- `body`: `std::vector<uint8_t>`

**Returns**

`Response`

### with_body_text_html

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L222

```cpp
fastly::expected<Response> fastly::http::Response::with_body_text_html(std::string_view body) &&
```

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

**Parameters**

- `body`: `std::string_view`

**Returns**

`fastly::expected<Response>`

### with_body_text_plain

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L214

```cpp
fastly::expected<Response> fastly::http::Response::with_body_text_plain(std::string_view body) &&
```

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

**Parameters**

- `body`: `std::string_view`

**Returns**

`fastly::expected<Response>`

### with_content_type

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L254

```cpp
Response fastly::http::Response::with_content_type(std::string_view mime) &&
```

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

**Parameters**

- `mime`: `std::string_view`

**Returns**

`Response`

### with_header

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L272

```cpp
fastly::expected<Response> fastly::http::Response::with_header(std::string_view name, std::string_view value) &&
```

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

**Parameters**

- `name`: `std::string_view`
- `value`: `std::string_view`

**Returns**

`fastly::expected<Response>`

### with_set_header

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L276

```cpp
fastly::expected<Response> fastly::http::Response::with_set_header(std::string_view name, std::string_view value) &&
```

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

**Parameters**

- `name`: `std::string_view`
- `value`: `std::string_view`

**Returns**

`fastly::expected<Response>`

### with_status

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L312

```cpp
Response fastly::http::Response::with_status(StatusCode status) &&
```

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

**Parameters**

- `status`: `StatusCode`

**Returns**

`Response`

### with_version

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/http/response.h#L336

```cpp
Response fastly::http::Response::with_version(Version version) &&
```

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

**Parameters**

- `version`: `Version`

**Returns**

`Response`
