@azure/functions
Version:
Microsoft Azure Functions NodeJS Framework
83 lines (65 loc) • 2.32 kB
text/typescript
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
import * as types from '@azure/functions';
import { HttpResponseInit } from '@azure/functions';
import { Blob } from 'buffer';
import { ReadableStream } from 'stream/web';
import { FormData, Headers, Response as uResponse, ResponseInit as uResponseInit } from 'undici';
import { isDefined } from '../utils/nonNull';
interface InternalHttpResponseInit extends HttpResponseInit {
undiciResponse?: uResponse;
}
export class HttpResponse implements types.HttpResponse {
readonly cookies: types.Cookie[];
readonly enableContentNegotiation: boolean;
constructor(init?: InternalHttpResponseInit) {
init ??= {};
this.
if (init.undiciResponse) {
this.
} else {
const uResInit: uResponseInit = { status: init.status, headers: init.headers };
if (isDefined(init.jsonBody)) {
this.
} else {
this.
}
}
this.cookies = init.cookies ?? [];
this.enableContentNegotiation = !!init.enableContentNegotiation;
}
get status(): number {
return this.
}
get headers(): Headers {
return this.
}
get body(): ReadableStream<any> | null {
return this.
}
get bodyUsed(): boolean {
return this.
}
async arrayBuffer(): Promise<ArrayBuffer> {
return this.
}
async blob(): Promise<Blob> {
return this.
}
async formData(): Promise<FormData> {
return this.
}
async json(): Promise<unknown> {
return this.
}
async text(): Promise<string> {
return this.
}
clone(): HttpResponse {
const newInit = structuredClone(this.
newInit.undiciResponse = this.
return new HttpResponse(newInit);
}
}