@vercel/node-bridge
Advanced tools
Comparing version 2.2.0 to 2.2.1-canary.0
@@ -189,5 +189,2 @@ const { request } = require('http'); | ||
) { | ||
// statusCode and headers are required to match when using | ||
// multiple payloads in a single invocation so we can use | ||
// the first | ||
let statusCode = 200; | ||
@@ -204,2 +201,10 @@ /** | ||
const CLRF = '\r\n'; | ||
/** | ||
* @type {Record<string, any>[]} | ||
*/ | ||
const separateHeaders = []; | ||
/** | ||
* @type {Set<string>} | ||
*/ | ||
const allHeaderKeys = new Set(); | ||
@@ -214,6 +219,6 @@ // we execute the payloads one at a time to ensure | ||
combinedBody += `--${multipartBoundary}${CLRF}`; | ||
if (response.headers['content-type']) { | ||
combinedBody += `content-type: ${response.headers['content-type']}${CLRF}${CLRF}`; | ||
} | ||
combinedBody += response.body; | ||
combinedBody += `content-type: ${ | ||
response.headers['content-type'] || 'text/plain' | ||
}${CLRF}${CLRF}`; | ||
combinedBody += response.body || ''; | ||
combinedBody += CLRF; | ||
@@ -224,7 +229,36 @@ | ||
} | ||
statusCode = response.statusCode; | ||
headers = response.headers; | ||
// pass non-200 status code in header so it can be handled | ||
// separately from other payloads e.g. HTML payload redirects | ||
// (307) but data payload does not (200) | ||
if (response.statusCode !== 200) { | ||
headers[`x-vercel-payload-${i + 1}-status`] = | ||
response.statusCode + ''; | ||
} | ||
separateHeaders.push(response.headers); | ||
Object.keys(response.headers).forEach(key => allHeaderKeys.add(key)); | ||
} | ||
allHeaderKeys.forEach(curKey => { | ||
/** | ||
* @type string | string[] | undefined | ||
*/ | ||
const curValue = separateHeaders[0] && separateHeaders[0][curKey]; | ||
const canDedupe = separateHeaders.every( | ||
headers => headers[curKey] === curValue | ||
); | ||
if (canDedupe) { | ||
headers[curKey] = curValue; | ||
} else { | ||
// if a header is unique per payload ensure it is prefixed | ||
// so it can be parsed and provided separately | ||
separateHeaders.forEach((curHeaders, idx) => { | ||
if (curHeaders[curKey]) { | ||
headers[`x-vercel-payload-${idx + 1}-${curKey}`] = | ||
curHeaders[curKey]; | ||
} | ||
}); | ||
} | ||
}); | ||
headers[ | ||
@@ -231,0 +265,0 @@ 'content-type' |
{ | ||
"name": "@vercel/node-bridge", | ||
"version": "2.2.0", | ||
"version": "2.2.1-canary.0", | ||
"license": "MIT", | ||
@@ -27,3 +27,3 @@ "main": "./index.js", | ||
}, | ||
"gitHead": "c76781fac978fee923d8180706103bad13ca33a0" | ||
"gitHead": "11d3dd04aaf02aba271483d64d805cc5820b7776" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
183063
4868
2