diff --git a/package.json b/package.json index ef544a2..d883a2b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@azure/functions", - "version": "4.11.1", + "version": "4.11.2", "description": "Microsoft Azure Functions NodeJS Framework", "keywords": [ "azure", diff --git a/src/constants.ts b/src/constants.ts index b92e8d3..38e44a1 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT License. -export const version = '4.11.1'; +export const version = '4.11.2'; export const returnBindingKey = '$return'; diff --git a/test/http/HttpResponse.test.ts b/test/http/HttpResponse.test.ts index a5bfaa2..bfe5469 100644 --- a/test/http/HttpResponse.test.ts +++ b/test/http/HttpResponse.test.ts @@ -6,6 +6,7 @@ import { Blob } from 'buffer'; import * as chai from 'chai'; import { expect } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; +import { Readable } from 'stream'; import { ReadableStream } from 'stream/web'; import { HttpResponse } from '../../src/http/HttpResponse'; @@ -366,6 +367,39 @@ describe('HttpResponse', () => { }); expect(await res.text()).to.equal('Stream content'); }); + + it('Node.js Readable stream body', async () => { + // Create a Node.js Readable stream (common for HTTP streaming scenarios) + const readable = new Readable({ + read() { + this.push('Readable '); + this.push('stream '); + this.push('content'); + this.push(null); // Signal end of stream + }, + }); + + const res = new HttpResponse({ + body: readable, + }); + expect(await res.text()).to.equal('Readable stream content'); + }); + + it('Node.js Readable stream from async generator', async () => { + // Common pattern for HTTP streaming (e.g., AI chat responses) + function* generateChunks() { + yield 'Hello '; + yield 'from '; + yield 'stream'; + } + + const readable = Readable.from(generateChunks()); + + const res = new HttpResponse({ + body: readable, + }); + expect(await res.text()).to.equal('Hello from stream'); + }); }); describe('HttpHeadersInit types', () => { diff --git a/types/http.d.ts b/types/http.d.ts index 555b192..5373544 100644 --- a/types/http.d.ts +++ b/types/http.d.ts @@ -2,6 +2,7 @@ // Licensed under the MIT License. import { Blob } from 'buffer'; +import { Readable } from 'stream'; import { ReadableStream } from 'stream/web'; import { URLSearchParams } from 'url'; import { FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger } from './index'; @@ -11,9 +12,11 @@ import { InvocationContext } from './InvocationContext'; * Represents the body types that can be used in an HTTP response. * This is a local definition to avoid dependency on lib.dom. * Compatible with Node.js native Fetch API body types. + * Includes Node.js Readable streams for HTTP streaming scenarios. */ export type HttpResponseBodyInit = | ReadableStream + | Readable | Blob | ArrayBufferView | ArrayBuffer