
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
forwarder-http
Advanced tools
A simple and configurable HTTP forwarder: streams incomming requests to a list of target servers
forwarder-http
is a HTTP/HTTPS forwarder. On each request it :
200
(unless you configure it
otherwise)It is meant to be simple, pluggable via Events, and totally configurable.
It currently supports only node >=6.x.x
.
We built this library because we needed a tiny-footprint tool to dispatch incomming production data to different development environments. As with any distributed system, requests sometimes fail so the forwarder should retry all requests on the production env, at least.
An example is worth a thousand words:
const Forwarder = require('forwarder-http')
const server = new Forwarder({
// The servers to forward the request to
targets: [
'http://target-nb-1.com', // use default target configs
{ // Overwrite some of the default configs
url: 'http://target-nb-2.com',
headers: {
'my-nb1-header': 'my-nb1-val'
},
retry: {
maxRetries: 3
}
}
],
// Add a header to the request before forwarding
targetHeaders: {'token': 'some-complicated-hash'},
// Define the forwarder response statusCode (default: 200)
responseStatusCode: 204
})
You'll more detailed examples in the Examples directory
The Forwarder
constructor supports a few options, meant to give the user total
control on how each request and response is handler:
false
)The forwarder options accept the targets array to contain many items in one the following forms :
string in the form http://somehost:12345
an object like:
{
url: 'https://somehost:12345',
opts: {
key: 'mykey',
cert: 'my cert',
rejectUnauthorized: false
},
headers: {
someHeader: 'someVal'
},
retry: {
maxRetries: 2
}
}
The options passed in the object will overwrite the default forwarder options.
The forwarder-http
library allows you to hook into most of the lifecycle to the
forwarding process, and change all the requests and responses along the way.
request (incommingMessage, response)
: The resquest event from the
http/https forward server. If you call response.end()
in a callback, the
request will not be forwarded.
response (incommingMessage, response)
: Called just before the
forwarder responds to the client.
requestError (error, incommingMessage)
: error when handling the
request in the forwarder
forwardRequest (options, incommingMessage)
: allows you to change the forwarded
request before it is sent. The first argument is the options array passed on to the
http.request and https.request
constructors, after all the config headers and options avec been applied. If you set options.cancel = true
it
will cancel the forwarding of the current request to the current target. Check out the examples for ... well ...
examples on this.
forwardResponse (request, incommingMessage, willRetry)
: allows you to act on individual target responses. The willRetry
option indicates if a retry will be performed by the forwarder (in the case of
5xx responses).
forwardRequestError (error, request, willRetry)
: error when forwarding a request to specific targets.
See the example on how to use the events.
node-http-proxy
also does proxying, which we do not, also supports versions of node older that 6.0.0, which we do not. But only handles a single forward target server, which didn't solve our problem. We ended up re-writing the whole thing. Anyway, many thanks to the folks at nodejitsu for this great pice of code.FAQs
A simple and configurable HTTP forwarder: streams incomming requests to a list of target servers
The npm package forwarder-http receives a total of 7 weekly downloads. As such, forwarder-http popularity was classified as not popular.
We found that forwarder-http demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.