Skip to content

proxyReq.setHeader in 'proxyReq' event callback throw 'Cannot set headers after they are sent to the client' #1328

Closed
@anson0370

Description

@anson0370

I did some debug and figured out what's happened.
In my case, this is because I was using curl to post a request with a body size bigger than 1024. curl sends a http request with header expect: 100-continue before sends the post request.

Looks like the problem is in Node http module:

    // _http_client.js: 221
    if (this.getHeader('expect')) {
      if (this._header) {
        throw new ERR_HTTP_HEADERS_SENT('render');
      }
      // here set headers for the request, so when we call proxyReq.setHeader later, it throw an exception
      this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n',
                        this[outHeadersKey]);
    }

Maybe we can check is here a expect header before fire proxyReq event, or ignore the setHeader invoke?

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