Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@netlify/functions

Package Overview
Dependencies
Maintainers
19
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@netlify/functions - npm Package Compare versions

Comparing version 0.7.3-streaming.11 to 0.7.3-streaming.12

2

package.json

@@ -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)

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc