Skip to content

Commit 28ae38f

Browse files
shanqueclaude
andcommitted
test: add tests for set_extra_http_headers tool
Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 8a4cf38 commit 28ae38f

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

tests/tools/network.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {describe, it} from 'node:test';
1010
import {
1111
getNetworkRequest,
1212
listNetworkRequests,
13+
setExtraHttpHeaders,
1314
} from '../../src/tools/network.js';
1415
import {serverHooks} from '../server.js';
1516
import {
@@ -132,6 +133,65 @@ describe('network', () => {
132133
});
133134
});
134135
});
136+
describe('set_extra_http_headers', () => {
137+
it('sets headers and reports count', async () => {
138+
await withMcpContext(async (response, context) => {
139+
await setExtraHttpHeaders.handler(
140+
{
141+
params: {headers: {'X-Custom': 'value', 'X-Lane': 'test'}},
142+
page: context.getSelectedMcpPage(),
143+
},
144+
response,
145+
context,
146+
);
147+
assert.strictEqual(
148+
response.responseLines[0],
149+
'Set 2 extra HTTP header(s): X-Custom, X-Lane',
150+
);
151+
});
152+
});
153+
154+
it('clears headers when empty object is passed', async () => {
155+
await withMcpContext(async (response, context) => {
156+
await setExtraHttpHeaders.handler(
157+
{
158+
params: {headers: {}},
159+
page: context.getSelectedMcpPage(),
160+
},
161+
response,
162+
context,
163+
);
164+
assert.strictEqual(
165+
response.responseLines[0],
166+
'Cleared all extra HTTP headers.',
167+
);
168+
});
169+
});
170+
171+
it('headers are included in subsequent requests', async () => {
172+
server.addRoute('/echo-headers', async (req, res) => {
173+
res.writeHead(200, {'Content-Type': 'application/json'});
174+
res.end(JSON.stringify(req.headers));
175+
});
176+
177+
await withMcpContext(async (response, context) => {
178+
const page = context.getSelectedPptrPage();
179+
await setExtraHttpHeaders.handler(
180+
{
181+
params: {headers: {'X-Test-Header': 'hello-mcp'}},
182+
page: context.getSelectedMcpPage(),
183+
},
184+
response,
185+
context,
186+
);
187+
188+
const navResponse = await page.goto(server.getRoute('/echo-headers'));
189+
const body = await navResponse!.json();
190+
assert.strictEqual(body['x-test-header'], 'hello-mcp');
191+
});
192+
});
193+
});
194+
135195
describe('network_get_request', () => {
136196
it('attaches request', async () => {
137197
await withMcpContext(async (response, context) => {

0 commit comments

Comments
 (0)