Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve http trigger handling #49

Merged
merged 6 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ export {
move,
walk,
} from "https://deno.land/std@0.79.0/fs/mod.ts";
export * from "./worker_deps.ts";
export * as semver from "https://deno.land/x/semver@v1.4.0/mod.ts";
21 changes: 20 additions & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class FunctionHttpRequest implements HttpRequest {
headers: { [key: string]: string } = {};
query: { [key: string]: string } = {};
params: { [key: string]: string } = {};
url = "";
body?: any;
rawBody?: any;

Expand Down Expand Up @@ -149,7 +150,25 @@ export class AzureFunctionsWorker {
// Merge `context.res` into `context.bindings`
// `context.res` is the special property for HTTP response
// https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node?tabs=v2#response-object
if (context.res) context.bindings.res = context.res;
if (!context.bindings.res) {
if (context.res?.status) {
context.res.statusCode = context.res.status;
delete context.res.status;
}
context.bindings.res = context.res;
}
registration.metadata?.bindings?.forEach((bindingDef:any) => {
if (bindingDef.type !== "http" || bindingDef.direction !== "out") return;
if (bindingDef.name === "$return") {
result.statusCode = result.status;
delete result.status;
return;
}
if (!context.bindings[bindingDef.name].status) return
const httpOutBinding = context.bindings[bindingDef.name]
httpOutBinding.statusCode = httpOutBinding.status;
delete httpOutBinding.status;
});

ctx.response.body = {
Logs: context.log.logs,
Expand Down
8 changes: 4 additions & 4 deletions types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ export interface HttpRequest {
* HTTP request method used to invoke this function.
*/
method: HttpMethod | null;
// /**
// * Request URL.
// */
// url: string;
/**
* Request URL.
*/
url: string;
/**
* HTTP request headers.
*/
Expand Down