ITADN

Property 'headers' does not exist on type 'ServerResponse<IncomingMessage>'

#2368Openeroncastro 创建于 2026-01-07
E
eroncastrocommented
Hi. First of all, thanks for this awesome library. While using it, I was dealing with an issue related to disabling headers on the logged messages and have stumbled up with [this issue](https://github.com/pinojs/pino-http/issues/5#issuecomment-1325655560). However, when implementing the afore mentioned example, I am getting the error: ``` Property 'headers' does not exist on type 'ServerResponse<IncomingMessage>'. ``` Here is my implementation: ```ts export function createHttpLogger(logger: Logger): ReturnType<typeof pinoHttp> { return pinoHttp({ logger, serializers: { req: pino.stdSerializers.wrapRequestSerializer((req) => { return { id: req.raw.id, method: req.raw.method, path: req.raw.url?.split('?')[0], // Remove query params which might be sensitive // Allowlist useful headers headers: { host: req.raw.headers.host, 'user-agent': req.raw.headers['user-agent'], referer: req.raw.headers.referer, }, }; }), res: pino.stdSerializers.wrapResponseSerializer((res) => { return { statusCode: res.raw.statusCode, // Allowlist useful headers // TODO: open issue on Github to have this handled by pino-http headers: { 'content-type': res.raw.headers['content-type'], 'content-length': res.raw.headers['content-length'], }, }; }), }, }); } ``` When I log the object `res.raw.headers` to the console I can clearly see that the property exists in the object. Am I missing something? If this is a problem, I would love to open a PR to have it fixed. Thanks!
0 条评论