Socket
Socket
Sign inDemoInstall

fast-proxy

Package Overview
Dependencies
19
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.5.0 to 1.6.0

61

index.js

@@ -29,3 +29,3 @@ 'use strict'

const cache = lru(opts.cacheURLs || 100)
const cache = getCacheStorage(opts.cacheURLs)
const base = opts.base

@@ -39,17 +39,6 @@

const onResponse = opts.onResponse
const rewriteHeaders = opts.rewriteHeaders || headersNoOp
const rewriteHeaders = opts.rewriteHeaders || rewriteHeadersNoOp
const rewriteRequestHeaders = opts.rewriteRequestHeaders || rewriteRequestHeadersNoOp
if (!source) {
source = req.url
}
// we leverage caching to avoid parsing the destination URL
const reqBase = opts.base || base
const cacheKey = reqBase + source
let url = cache.get(cacheKey)
if (!url) {
url = new URL(source, reqBase)
cache.set(cacheKey, url)
}
const url = getReqUrl(source || req.url, cache, base, opts)
const sourceHttp2 = req.httpVersionMajor === 2

@@ -84,3 +73,11 @@ const headers = { ...sourceHttp2 ? filterPseudoHeaders(req.headers) : req.headers }

request({ method: req.method, url, qs, headers, body, request: reqOpts }, (err, response) => {
const reqParams = {
method: req.method,
url,
qs,
headers: rewriteRequestHeaders(req, headers),
body,
request: reqOpts
}
request(reqParams, (err, response) => {
if (err) {

@@ -144,4 +141,34 @@ if (!res.sent) {

function headersNoOp (headers) {
function rewriteHeadersNoOp (headers) {
return headers
}
function rewriteRequestHeadersNoOp (req, headers) {
return headers
}
function getCacheStorage (size) {
if (size === 0) {
return null
}
return lru(size || 100)
}
function getReqUrl (source, cache, base, opts) {
const reqBase = opts.base || base
let url
if (cache) {
const cacheKey = reqBase + source
url = cache.get(cacheKey)
if (!url) {
url = new URL(source, reqBase)
cache.set(cacheKey, url)
}
} else {
url = new URL(source, reqBase)
}
return url
}

@@ -73,6 +73,5 @@ 'use strict'

done(err)
return
} else {
setImmediate(() => done(null, { statusCode: res.statusCode, headers: res.headers, stream: res.body }))
}
setImmediate(() => done(null, { statusCode: res.statusCode, headers: res.headers, stream: res.body }))
})

@@ -79,0 +78,0 @@ }

{
"name": "fast-proxy",
"version": "1.5.0",
"version": "1.6.0",
"description": "Forward your HTTP request to another server.",

@@ -39,12 +39,12 @@ "main": "index.js",

"chai": "^4.2.0",
"fastify": "^2.12.0",
"fastify-reply-from": "^2.0.0",
"fastify": "^2.13.0",
"fastify-reply-from": "^2.0.1",
"h2url": "^0.2.0",
"http-proxy": "^1.18.0",
"mocha": "^7.0.1",
"nock": "^12.0.2",
"nyc": "^15.0.0",
"mocha": "^7.1.1",
"nock": "^12.0.3",
"nyc": "^15.0.1",
"pem": "^1.14.4",
"restana": "^4.1.0",
"standard": "^14.3.1",
"restana": "^4.3.1",
"standard": "^14.3.3",
"supertest": "^4.0.2"

@@ -55,3 +55,3 @@ },

"pump": "^3.0.0",
"semver": "^7.1.2",
"semver": "^7.2.1",
"tiny-lru": "^7.0.2",

@@ -58,0 +58,0 @@ "undici": "^0.5.0"

@@ -83,2 +83,3 @@ # fast-proxy

The number of parsed URLs that will be cached. Default: 100.
> Use value = `0` to disable the caching mechanism

@@ -125,2 +126,6 @@ #### keepAliveMsecs

##### rewriteRequestHeaders(req, headers)
Called to rewrite the headers of the request, before them being sent to the downstream server.
It must return the new headers object.
##### rewriteHeaders(headers)

@@ -127,0 +132,0 @@ Called to rewrite the headers of the response, before them being copied

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc