Skip to content

Commit

Permalink
allow passing Headers object to res.set
Browse files Browse the repository at this point in the history
Signed-off-by: karthik2804 <[email protected]>

pull in latest changes

Signed-off-by: karthik2804 <[email protected]>
  • Loading branch information
karthik2804 committed Jun 13, 2024
1 parent bc626f7 commit 6ac9b48
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 61 deletions.
1 change: 1 addition & 0 deletions bin/wit/spin.wit
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fermyon:[email protected];

world spin-imports {
import wasi:http/outgoing-handler@0.2.0;
include wasi:cli/imports@0.2.0;
import llm;
import redis;
import postgres;
Expand Down
2 changes: 1 addition & 1 deletion lib/inboundHttp.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export declare class ResponseBuilder {
getStatus(): number;
set(arg1: string | {
[key: string]: string;
}, arg2?: string): ResponseBuilder;
} | Headers, arg2?: string): ResponseBuilder;
send(value?: BodyInit): void;
write(value: BodyInit): void;
end(): void;
Expand Down
5 changes: 5 additions & 0 deletions lib/inboundHttp.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export class ResponseBuilder {
if (typeof arg1 === 'string' && typeof arg2 === 'string') {
this.headers.set(arg1, arg2);
}
else if (typeof arg1 === 'object' && arg1 instanceof Headers) {
arg1.forEach((value, key) => {
this.headers.set(key, value);
});
}
else if (typeof arg1 === 'object' && arg2 === undefined) {
for (const key in arg1) {
this.headers.set(key, arg1[key]);
Expand Down
131 changes: 72 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions plugins/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class SpinSdkPlugin {
constructor() {
this.externals = {
"wasi:http/[email protected]": "wasi:http/[email protected]",
"wasi:cli/[email protected]": "wasi:cli/[email protected]",
"wasi:filesystem/[email protected]": "wasi:filesystem/[email protected]",
"fermyon:spin/[email protected]": "fermyon:spin/[email protected]",
"fermyon:spin/[email protected]": "fermyon:spin/[email protected]",
"fermyon:spin/[email protected]": "fermyon:spin/[email protected]",
Expand Down
6 changes: 5 additions & 1 deletion src/inboundHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ export class ResponseBuilder {
return this.statusCode;
}
set(
arg1: string | { [key: string]: string },
arg1: string | { [key: string]: string } | Headers,
arg2?: string,
): ResponseBuilder {
if (this.hasWrittenHeaders) {
throw new Error('Headers already sent');
}
if (typeof arg1 === 'string' && typeof arg2 === 'string') {
this.headers.set(arg1, arg2);
} else if (typeof arg1 === 'object' && arg1 instanceof Headers) {
arg1.forEach((value, key) => {
this.headers.set(key, value);
});
} else if (typeof arg1 === 'object' && arg2 === undefined) {
for (const key in arg1) {
this.headers.set(key, arg1[key]);
Expand Down

0 comments on commit 6ac9b48

Please sign in to comment.