@netlify/functions
Advanced tools
Comparing version 0.7.3-streaming.11 to 0.7.3-streaming.12
@@ -5,3 +5,3 @@ { | ||
"types": "./src/main.d.ts", | ||
"version": "0.7.3-streaming.11", | ||
"version": "0.7.3-streaming.12", | ||
"description": "JavaScript utilities for Netlify Functions", | ||
@@ -8,0 +8,0 @@ "files": [ |
@@ -8,2 +8,3 @@ /* eslint-disable no-underscore-dangle , promise/prefer-await-to-callbacks, */ | ||
const METADATA_HEADER_NAME = 'X-Nf-Metadata' | ||
class StreamingResponse extends PassThrough { | ||
@@ -15,6 +16,8 @@ statusCode = 200 | ||
_metadataSent = false | ||
_sendMetadataInHeader | ||
outgoingMessage | ||
constructor(url, ip) { | ||
constructor(url, ip, sendMetadataInHeader) { | ||
super() | ||
this._sendMetadataInHeader = sendMetadataInHeader | ||
// eslint-disable-next-line node/no-unsupported-features/node-builtins | ||
@@ -35,2 +38,5 @@ const parsedUrl = new URL(url) | ||
this.pipe(this.outgoingMessage) | ||
if (sendMetadataInHeader) { | ||
this.outgoingMessage.setHeader(METADATA_HEADER_NAME, this._getMetadata()) | ||
} | ||
} | ||
@@ -47,18 +53,17 @@ | ||
_getMetadata() { | ||
return Buffer.concat([ | ||
Buffer.from( | ||
JSON.stringify({ | ||
// eslint-disable-next-line node/no-unsupported-features/es-builtins | ||
headers: Object.fromEntries(this._clientHeaders.entries()), | ||
statusCode: this.statusCode, | ||
}), | ||
), | ||
Uint8Array.from([0x00]), | ||
]) | ||
return JSON.stringify({ | ||
// eslint-disable-next-line node/no-unsupported-features/es-builtins | ||
headers: Object.fromEntries(this._clientHeaders.entries()), | ||
statusCode: this.statusCode, | ||
}) | ||
} | ||
_getMetadataBuffer() { | ||
return Buffer.concat([Buffer.from(this._getMetadata()), Uint8Array.from([0x00])]) | ||
} | ||
write(data, encoding, callback) { | ||
console.log('writing', data) | ||
if (!this._metadataSent) { | ||
super.write(this._getMetadata()) | ||
if (!this._metadataSent && !this._sendMetadataInHeader) { | ||
super.write(this._getMetadataBuffer()) | ||
// super.write(Buffer.from([0x00])) | ||
@@ -84,2 +89,4 @@ this._metadataSent = true | ||
const sendMetadataInHeader = Boolean(event.queryStringParameters.sendMetadataInHeader) | ||
if (!context.streaming) { | ||
@@ -105,3 +112,3 @@ return { | ||
try { | ||
res = new StreamingResponse(callbackUrl, callbackIP) | ||
res = new StreamingResponse(callbackUrl, callbackIP, sendMetadataInHeader) | ||
} catch (error) { | ||
@@ -108,0 +115,0 @@ console.error(error) |
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
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
15132
302