Skip to content

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

@eroncastro

Description

@eroncastro

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.

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:

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions