# Delete response body content

**URL:** <https://discourse.slimframework.com/t/delete-response-body-content/590>\
**Category:** Questions\
**Created:** [August 7, 2016, 5:14am UTC](https://discourse.slimframework.com/t/delete-response-body-content/590 "2016-08-07T05:14:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hans](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@hans](https://discourse.slimframework.com/u/hans)\
**Post date:** [August 7, 2016, 5:14am UTC](https://discourse.slimframework.com/t/delete-response-body-content/590/1 "2016-08-07T05:14:32Z")

</div>

Is there a way to delete the entire response body content, after it has been written to it?  
Like this.

Stream.php

```
public function truncate() {
    ftruncate($this->stream, 0);
}
```

---

<div class="post-metadata">

**Author:** ![zooboole](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/zooboole/32/134_2.png) [@zooboole](https://discourse.slimframework.com/u/zooboole)\
**Post date:** [August 7, 2016, 9:20am UTC](https://discourse.slimframework.com/t/delete-response-body-content/590/2 "2016-08-07T09:20:10Z")

</div>

probably by replacing with an empty PSR-7 valid object. Check out this from the docs:

> You can also replace the PSR 7 Response object’s body with an entirely new StreamInterface instance.

An example:

```
$newStream = new \GuzzleHttp\Psr7\LazyOpenStream('/path/to/file', 'r');
$newResponse = $oldResponse->withBody($newStream);

```

[Source](http://www.slimframework.com/docs/objects/response.html#the-response-body)

---

<div class="post-metadata">

**Author:** ![hans](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@hans](https://discourse.slimframework.com/u/hans)\
**Post date:** [August 7, 2016, 3:30pm UTC](https://discourse.slimframework.com/t/delete-response-body-content/590/3 "2016-08-07T15:30:44Z")

</div>

Look promising.  
But in case I would prefer to create an empty file stream from memory and an build in solution would be nice, too?

Anyway my slim skeleton implementation does not seem to come with Guzzle, do I have to download it from github separately?

---

<div class="post-metadata">

**Author:** ![mdonk](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/mdonk/32/342_2.png) [@mdonk](https://discourse.slimframework.com/u/mdonk)\
**Post date:** [March 4, 2017, 1:36am UTC](https://discourse.slimframework.com/t/delete-response-body-content/590/4 "2017-03-04T01:36:26Z")

</div>

Easy way in Slim Framework 3. This works fine for me.

```
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $args = null)
{
    // Get response set by middleware.
    $mw_response = $response->getBody()->__toString();

    // Now reset the response.
    $response = new \Slim\Http\Response();

    .....
}
```
