> ## Documentation Index
> Fetch the complete documentation index at: https://bunny.net/docs/llms.txt
> Use this file to discover all available pages before exploring further.
# Modify response body (Middleware)
> Use a middleware script to change the response body coming back from the origin before it is cached.
This middleware reads the HTML response from the origin and appends
`- bunny.net` to the contents of the `
` tag, so every page carries it.
```ts theme={null}
import * as BunnySDK from "@bunny.net/edgescript-sdk";
/**
* When a response is not served from the cache, you can use this event handler
* to modify the response coming from the origin. This runs before the response
* is cached.
*
* Returns an HTTP response.
* @param {Context} context - The context of the middleware.
* @param {Request} request - The current request done to the origin.
* @param {Response} response - The HTTP response or string.
*/
async function onOriginResponse(context: {
request: Request;
response: Response;
}): Promise | Response | void {
let body = await context.response.text();
body = body.replace("", "- bunny.net");
// Remove the original Content headers so the response is returned correctly
const headers = new Headers(context.response.headers);
headers.delete("Content-Length");
headers.delete("Content-Encoding");
return new Response(body, {
status: context.response.status, // Preserve the original status code
headers, // Preserve the original headers
});
}
BunnySDK.net.http.servePullZone().onOriginResponse(onOriginResponse);
```
This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.