# setNextProxyHeaders

Canonical: <https://test-proxy-recorder.dev/docs/reference/api/functions/setnextproxyheaders/>
Docs index: <https://test-proxy-recorder.dev/docs/> · All docs as one file: <https://test-proxy-recorder.dev/llms-full.txt>

---

> **setNextProxyHeaders**(`request`, `response`): `void`

Defined in: [nextjs/middleware.ts:41](https://github.com/asmyshlyaev177/test-proxy-recorder/blob/d1bacb3b39a3cf6f7f5a5391a8201868e4629861/packages/test-proxy-recorder/src/nextjs/middleware.ts#L41)

Next.js middleware helper for forwarding test proxy recording headers
Automatically forwards the recording ID header from incoming requests to the proxy
Only runs in non-production environments or when TEST_PROXY_RECORDER_ENABLED is set

## Parameters

### request

`NextJSRequest`

Next.js request object (NextRequest from next/server)

### response

`NextJSResponse`

Next.js response object (NextResponse from next/server)

## Returns

`void`

## Example

```ts
// middleware.ts
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { setNextProxyHeaders } from 'test-proxy-recorder/nextjs';

export function middleware(request: NextRequest) {
  const response = NextResponse.next();
  // Only forwards headers in test/dev environments
  setNextProxyHeaders(request, response);
  return response;
}
```
