@azure/functions
Version:
Microsoft Azure Functions NodeJS Framework
90 lines (70 loc) • 2.63 kB
text/typescript
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
import * as types from '@azure/functions';
import { HttpRequestParams, HttpRequestUser } from '@azure/functions';
import { RpcHttpData } from '@azure/functions-core';
import { Blob } from 'buffer';
import { ReadableStream } from 'stream/web';
import { FormData, Headers, Request as uRequest } from 'undici';
import { URLSearchParams } from 'url';
import { fromNullableMapping } from '../converters/fromRpcNullable';
import { nonNullProp } from '../utils/nonNull';
import { extractHttpUserFromHeaders } from './extractHttpUserFromHeaders';
export class HttpRequest implements types.HttpRequest {
readonly query: URLSearchParams;
readonly params: HttpRequestParams;
constructor(rpcHttp: RpcHttpData) {
const url = nonNullProp(rpcHttp, 'url');
if (rpcHttp.body?.bytes) {
this.
} else if (rpcHttp.body?.string) {
this.
}
this.
body: this.
method: nonNullProp(rpcHttp, 'method'),
headers: fromNullableMapping(rpcHttp.nullableHeaders, rpcHttp.headers),
});
this.query = new URLSearchParams(fromNullableMapping(rpcHttp.nullableQuery, rpcHttp.query));
this.params = fromNullableMapping(rpcHttp.nullableParams, rpcHttp.params);
}
get url(): string {
return this.
}
get method(): string {
return this.
}
get headers(): Headers {
return this.
}
get user(): HttpRequestUser | null {
if (this.
this.
}
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.
}
}