Adding a response header

Learn how to add a response header in your Middleware.

DX Team
2 min read
Last updated November 21, 2025

The following example shows how to add a response header in your Middleware

Your middleware file should be placed at the root of your project. If you are using the src directory, the file should be placed in the src directory.

middleware.js
import { NextResponse } from 'next/server';
export default function middleware() {
// Store the response so we can modify its headers
const response = NextResponse.next();
// Set custom header
response.headers.set('x-modified-edge', 'true');
// Return response
return response;
}
middleware.ts
import { NextResponse } from 'next/server';
export default function middleware() {
// Store the response so we can modify its headers
const response = NextResponse.next();
// Set custom header
response.headers.set('x-modified-edge', 'true');
// Return response
return response;
}
middleware.js
import { NextResponse } from 'next/server';
export default function middleware() {
// Store the response so we can modify its headers
const response = NextResponse.next();
// Set custom header
response.headers.set('x-modified-edge', 'true');
// Return response
return response;
}
middleware.ts
import { NextResponse } from 'next/server';
export default function middleware() {
// Store the response so we can modify its headers
const response = NextResponse.next();
// Set custom header
response.headers.set('x-modified-edge', 'true');
// Return response
return response;
}
middleware.js
import { next } from '@vercel/functions';
export default function middleware() {
// Store the response so we can modify its headers
const response = next();
// Set custom header
response.headers.set('x-modified-edge', 'true');
// Return response
return response;
}
middleware.ts
import { next } from '@vercel/functions';
export default function middleware() {
// Store the response so we can modify its headers
const response = next();
// Set custom header
response.headers.set('x-modified-edge', 'true');
// Return response
return response;
}

Was this helpful?

supported.