Skip to content

I'm not able to set headers for NATS response  #10273

Open
@Dzixxx

Description

@Dzixxx

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I want to send back from my method decorated with MessagePattern/EventPattern data with NATS headers and turns out that they're not passed in any way.

I tried with setting

@MessagePattern('abc')
method(@Ctx() context: NatsContext) {
  ctx.getHeaders().set('response-header', 'abc')
  return 'my data';
}

with hope that they will be applied but with no luck - they're undefined 😂

Minimum reproduction code

https://github.com/Dzixxx/nestjs-typescript-starter-we4m7w

Steps to reproduce

No response

Expected behavior

I would expect that @Ctx() context: NatsContext will have method setResponseHeader and in ServerNats.getPublisher method it will apply them to packet and default serializer will handle it:

// line 26 of nats-record.serializer.ts
: new NatsRecordBuilder(packet?.data).build()

// new line 26 of nats-record.serializer.ts
:  new NatsRecordBuilder(packet?.data).setHeaders(packet?.headers).build()

I'm open for any solution and even preparing PR (but I will need some help with preparing the solution)

Dziczek 😉

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

9

Packages versions

Node.js version

16

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

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