Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
http2-proxy
Advanced tools
A simple high performance http/2 & http/1 to http/1 spec compliant proxy helper for Node.
A simple high performance http/2 & http/1 to http/1 spec compliant proxy helper for Node.
$ npm install http2-proxy
http2-proxy
requires node v8.5.0 or newer with http2
enabled. Pass the --expose-http2
option when starting node v8.x.x.
You must pass allowHTTP1: true
to the http2.createServer
or http2.createSecureServer
factory methods.
import http2 from 'http2'
import proxy from 'http2-proxy'
const server = http2.createServer({ allowHTTP1: true })
server.listen(8000)
server.on('request', (req, res) => {
proxy.web(req, res, {
hostname: 'localhost'
port: 9000
}, err => {
if (err) {
console.error('proxy error', err)
}
})
})
server.on('upgrade', (req, socket, head) => {
proxy.ws(req, socket, head, {
hostname: 'localhost'
port: 9000
}, err => {
if (err) {
console.error('proxy error', err)
}
})
})
server.on('request', (req, res) => {
proxy.web(req, res, {
hostname: 'localhost'
port: 9000,
onRes: (req, res) => helmet(req, res, () => {})
}, err => {
if (err) {
console.error('proxy error', err)
}
})
})
server.on('request', (req, res) => {
proxy.web(req, res, {
hostname: 'localhost'
port: 9000,
onReq: (req, { headers }) => {
headers['x-forwarded-for'] = req.socket.remoteAddress
headers['x-forwarded-proto'] = req.socket.encrypted ? 'https' : 'http'
headers['x-forwarded-host'] = req.headers['host']
}
}, err => {
if (err) {
console.error('proxy error', err)
}
})
})
req
: http.IncomingMessage
or http2.Http2ServerRequest
res
: http.ServerResponse
or http2.Http2ServerResponse
options
: See Optionscallback(err)
: Called on completion or error. OptionalReturns a promise if no callback is provided.
See request
req
: http.IncomingMessage
socket
: net.Socket
head
: Buffer
options
: See Optionscallback(err)
: Called on completion or error. OptionalReturns a promise if no callback is provided.
See upgrade
hostname
: Proxy http.request(options)
target hostnameport
: Proxy http.request(options)
target portproxyTimeout
: Proxy http.request(options)
timeoutproxyName
: Proxy name used for Via headertimeout
: http.IncomingMessage
or http2.Http2ServerRequest
timeoutonReq(req, options)
: Called before proxy request
req
: http.IncomingMessage
or http2.Http2ServerRequest
options
: Options passed to http.request(options)
onRes(req, resOrSocket)
: Called before proxy response
req
: http.IncomingMessage
or http2.Http2ServerRequest
resOrSocket
: For web
http.ServerResponse
or http2.Http2ServerResponse
and for ws
net.Socket
If HTTP/1 support is not required use the HTTP/2 stream
API which has a lower overhead.
Note that the onRes
signature differs from HTTP/1 mode.
import http2 from 'http2'
import proxy from 'http2-proxy'
const server = http2.createServer()
server.listen(8000)
server.on('stream', (stream, headers) => {
proxy.web(stream, headers, {
hostname: 'localhost'
port: 9000
}, err => {
if (err) {
console.error('proxy error', err)
}
})
})
server.on('stream', (stream, headers) => {
proxy.web(stream, headers, {
hostname: 'localhost'
port: 9000,
onReq: (stream, { headers }) => {
headers['x-forwarded-for'] = stream.socket.remoteAddress
headers['x-forwarded-proto'] = stream.socket.encrypted ? 'https' : 'http'
headers['x-forwarded-host'] = stream.headers['host']
}
}, err => {
if (err) {
console.error('proxy error', err)
}
})
})
stream
: http2.Http2Stream
headers
: Request headers objectoptions
: See Optionscallback(err)
: Called on completion or error. OptionalReturns a promise if no callback is provided.
See request
hostname
: Proxy http.request(options)
target hostnameport
: Proxy http.request(options)
target portproxyTimeout
: Proxy http.request(options)
timeoutproxyName
: Proxy name used for Via headertimeout
: http.IncomingMessage
or http2.Http2ServerRequest
timeoutonReq(req, options)
: Called before proxy request
req
: http.IncomingMessage
or http2.Http2ServerRequest
options
: Options passed to http.request(options)
onRes(req, headers)
: Called before proxy response
req
: http.IncomingMessage
or http2.Http2ServerRequest
headers
: Response headers objectFAQs
A simple http/2 & http/1.1 spec compliant proxy helper for Node.
The npm package http2-proxy receives a total of 23,369 weekly downloads. As such, http2-proxy popularity was classified as popular.
We found that http2-proxy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.