Skip to content

connection is reset when the request header Transfer encoding is set to chunked #554

@rohithkk

Description

@rohithkk

I am running into an issue where express-http-proxy appears to close connection with the client and send 504 status.

In our usecase, a client request is sent down different nodes as shown below. The Reverse Proxy server is responsible for enforcing authn/authz policies before proxying request to the UI proxy app. This reverse proxy server is injecting Transfer-Encoding header with value as chunked for all requests, irrespective of whether there is any actual payload in the request i.e. even the GET requests without any request body have this header.

Client (Browser) --> Load Balancer (Reverse Proxy) --> UI Proxy app (ExpressJs) --> Backend App

Problem is the the UI Proxy app that is using express-http-proxy appears to close connection with the ReveseProxy server immediately.
In the response received at RP, we can see the following headers.

X-Powered-By: Express
X-Timeout-Reason: express-http-proxy reset the request.
Content-Type: text/plain
Date: Tue, 10 Dec 2024 19:15:36 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Transfer-Encoding: chunked

Follow steps below to reproduce this issue.

  1. Create app.js with the following code.

const proxy = require('express-http-proxy');
const express = require('express')
const app = express()

const port = 3000

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.use('/proxy', proxy('https://example.com'));

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})
  1. Send request using following command.

curl --location 'http://localhost:3000/proxy' --header 'Transfer-Encoding: chunked'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions