Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ejizba committed Jan 31, 2024
1 parent 8303f92 commit 8006b89
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/InvocationModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { fromRpcTypedData } from './converters/fromRpcTypedData';
import { toCamelCaseValue } from './converters/toCamelCase';
import { toRpcHttp } from './converters/toRpcHttp';
import { toRpcTypedData } from './converters/toRpcTypedData';
import { waitForRequest } from './http/httpProxy';
import { waitForProxyRequest } from './http/httpProxy';
import { HttpRequest } from './http/HttpRequest';
import { InvocationContext } from './InvocationContext';
import { isHttpStreamEnabled } from './setup';
Expand Down Expand Up @@ -68,7 +68,7 @@ export class InvocationModel implements coreTypes.InvocationModel {

let input: unknown;
if (isHttpTrigger(bindingType) && isHttpStreamEnabled()) {
const proxyRequest = await waitForRequest(this.#coreCtx.invocationId);
const proxyRequest = await waitForProxyRequest(this.#coreCtx.invocationId);
input = new HttpRequest({ ...binding.data?.http, proxyRequest });
} else {
input = fromRpcTypedData(binding.data);
Expand Down
7 changes: 4 additions & 3 deletions src/converters/toRpcHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { RpcHttpData, RpcTypedData } from '@azure/functions-core';
import { AzFuncSystemError } from '../errors';
import { sendResponse } from '../http/httpProxy';
import { sendProxyResponse } from '../http/httpProxy';
import { HttpResponse } from '../http/HttpResponse';
import { isHttpStreamEnabled } from '../setup';
import { toRpcHttpCookie } from './toRpcHttpCookie';
Expand All @@ -20,8 +20,9 @@ export async function toRpcHttp(invocationId: string, data: unknown): Promise<Rp

const response = data instanceof HttpResponse ? data : new HttpResponse(data);
if (isHttpStreamEnabled()) {
await sendResponse(invocationId, response);
return undefined;
// send http data over http proxy instead of rpc
await sendProxyResponse(invocationId, response);
return;
}

const rpcResponse: RpcHttpData = {};
Expand Down
6 changes: 4 additions & 2 deletions src/http/HttpRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ interface InternalHttpRequestInit extends RpcHttpData {
proxyRequest?: IncomingMessage;
}

type RequestInitResult = [uRequest, URLSearchParams, HttpRequestParams];

export class HttpRequest implements types.HttpRequest {
readonly query: URLSearchParams;
readonly params: HttpRequestParams;
Expand All @@ -38,7 +40,7 @@ export class HttpRequest implements types.HttpRequest {
}
}

#initInMemoryRequest(init: InternalHttpRequestInit): [uRequest, URLSearchParams, HttpRequestParams] {
#initInMemoryRequest(init: InternalHttpRequestInit): RequestInitResult {
let uReq = init.undiciRequest;
if (!uReq) {
const url = nonNullProp(init, 'url');
Expand All @@ -63,7 +65,7 @@ export class HttpRequest implements types.HttpRequest {
return [uReq, query, params];
}

#initStreamRequest(init: InternalHttpRequestInit): [uRequest, URLSearchParams, HttpRequestParams] {
#initStreamRequest(init: InternalHttpRequestInit): RequestInitResult {
const proxyReq = nonNullProp(init, 'proxyRequest');

const hostHeaderName = 'x-forwarded-host';
Expand Down
4 changes: 2 additions & 2 deletions src/http/httpProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const responses: Record<string, http.ServerResponse> = {};

const invocRequestEmitter = new EventEmitter();

export async function waitForRequest(invocationId: string): Promise<http.IncomingMessage> {
export async function waitForProxyRequest(invocationId: string): Promise<http.IncomingMessage> {
return new Promise((resolve, _reject) => {
const req = requests[invocationId];
if (req) {
Expand All @@ -33,7 +33,7 @@ export async function waitForRequest(invocationId: string): Promise<http.Incomin
}

const invocationIdHeader = 'x-ms-invocation-id';
export async function sendResponse(invocationId: string, userRes: HttpResponse): Promise<void> {
export async function sendProxyResponse(invocationId: string, userRes: HttpResponse): Promise<void> {
const proxyRes = nonNullProp(responses, invocationId);
delete responses[invocationId];
for (const [key, val] of userRes.headers.entries()) {
Expand Down

0 comments on commit 8006b89

Please sign in to comment.