Skip to content

question: setting dynamic headers #582

@azaslonov

Description

@azaslonov

Hi there,

I have a case where I need to setup headers dynamically, e.g.:

response.setHeader("Expires", dateFormat.format("ddd, DD MMM YYYY HH:mm:ss") + " GMT");

If I do that using response object @Res() response: any, I always get error:

(node:29688) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:470:11)
    at ServerResponse.header (webpack:///./node_modules/express/lib/response.js?:771:10)
    at eval (webpack:///./node_modules/routing-controllers/driver/express/ExpressDriver.js?:364:32)
    at Array.forEach (<anonymous>)
    at ExpressDriver.handleError (webpack:///./node_modules/routing-controllers/driver/express/ExpressDriver.js?:363:45)
    at eval (webpack:///./node_modules/routing-controllers/RoutingControllers.js?:104:33)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Please advise how to handle this kind of scenario.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: questionQuestions about the usage of the library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions