Skip to content

Running 'setHeader' during 'proxyReq' event fails for POST requests #908

Open
@cdl

Description

@cdl

Right now, it looks like trying to do a setHeader on the passed in proxyReq for POST requests fails. (see below:)

proxy.on('proxyReq', function(proxyReq, req, res, options) {
  proxyReq.setHeader('origin', 'https://example.com');
});

The following error is thrown when the above tries to execute:

Error: Can't set headers after they are sent.

This seems to work totally fine for GET requests, just not POST requests. Managed to hack around it at first by wrapping the .setHeader call in check to make sure proxyReq._header was null, but it looks like that totally fails when Firefox tries to perform a POST request (the header doesn't get set).

The same thing appears to happen when trying to do res.setHeader, as suggested by #819.

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