OptimalBits / redbird

A modern reverse proxy for node
BSD 2-Clause "Simplified" License
4.41k stars 280 forks source link

Removing headers to work with other web servers and systems #257

Open Starystars67 opened 4 years ago

Starystars67 commented 4 years ago

Hello,

So I am having a bit of an issue with redbird proxy and trying to make it work with the following project: https://github.com/plan-player-analytics/Plan/issues/1488 . So first a little background, I currently have several domains running through my redbird setup all pointing to various web servers over a selection of machines connected via vlans using a mix of http and https.

I am currently trying to add Plan to the list of websites run through redbird however i get the following error: HPE_UNEXPECTED_CONTENT_LENGTH when loading the page. When looking in the console of redbird is see the following: image After talking to the developer of Plan and creating a ticket on their github (link above) it appears to be related to the headers, specifically redbird using: Transfer-encoding: where as plan uses: Content-Length. Is anyone able to help with either solving the problem or advising how i can tap into the system to manipulate the request / response accordingly. Currently this is the code i am trying to run but as you can see it does not run in the above image:

proxy.register("example.net", "http://192.168.100.2:8804", {
    ssl: {
        key: "certs/example.net-key.pem",
        cert: "certs/example.net-cert.pem",
    },
//},{
    onRequest: (req, res, target) => {
      // called before forwarding is occurred, you can modify req.headers for example
      // return undefined to forward to default target
      console.log(target)
      console.log("=================================================")
      console.log(req)
      console.log("=================================================")
      console.log(res)
      console.log("=================================================")
      res.removeHeader('transfer-encoding'); // changing the header
    }
});

It seems that the onRequest is never called and I dont seem to be able to find any good documentation on it either which is not helping matters.

Many thanks to anyone who can help. I really would prefer not to have to change my proxy over this.

jackmaresca commented 4 years ago

Maybe you are using latest version on npm which does not contains commits regarding onRequest, proxyTimeout..

Starystars67 commented 4 years ago

@jackmaresca that is correct, latest from npm. Given your comment can you tell me a github version/tag or commit version to work from if you know of a stable one?

jackmaresca commented 4 years ago

You can insert github link in package.json and download latest as explained here: https://stackoverflow.com/questions/17509669/how-to-install-an-npm-package-from-github-directly