Files
openchamber/packages/web/server/proxy-headers.test.js
T
shekohex 7b0e279a30 fix(server): strip hop-by-hop proxy response headers (#813)
* fix(server): strip hop-by-hop proxy response headers

* chore(ui): remove unused markdown runtime destructures
2026-04-01 16:19:20 +03:00

59 lines
1.8 KiB
JavaScript

import { describe, expect, it } from 'bun:test';
import {
applyForwardProxyResponseHeaders,
collectForwardProxyHeaders,
shouldForwardProxyResponseHeader,
} from './proxy-headers.js';
describe('OpenCode proxy header handling', () => {
it('drops accept-encoding from forwarded request headers', () => {
const headers = collectForwardProxyHeaders({
accept: 'application/json',
'accept-encoding': 'gzip, deflate, br',
connection: 'keep-alive',
});
expect(headers.accept).toBe('application/json');
expect(headers['accept-encoding']).toBeUndefined();
});
it('drops content-encoding from forwarded response headers', () => {
expect(shouldForwardProxyResponseHeader('content-encoding')).toBe(false);
expect(shouldForwardProxyResponseHeader('Content-Encoding')).toBe(false);
});
it('drops transfer-encoding from forwarded response headers', () => {
expect(shouldForwardProxyResponseHeader('transfer-encoding')).toBe(false);
expect(shouldForwardProxyResponseHeader('Transfer-Encoding')).toBe(false);
});
it('still keeps ordinary response headers', () => {
expect(shouldForwardProxyResponseHeader('content-type')).toBe(true);
expect(shouldForwardProxyResponseHeader('etag')).toBe(true);
});
it('applies upstream response headers to express response without content-encoding', () => {
const applied = [];
const response = {
setHeader(key, value) {
applied.push([key, value]);
},
};
applyForwardProxyResponseHeaders(
new Headers({
'content-type': 'application/json',
etag: 'W/"abc"',
'content-encoding': 'gzip',
}),
response,
);
expect(applied).toEqual([
['content-type', 'application/json'],
['etag', 'W/"abc"'],
]);
});
});