I suggest to change the declaration of the method field from string to "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH" in the file "https://deno.land/[email protected]/http/server.ts". This makes switch statements easier and everything more fail-proof. Probably we should implement a type alias.
export class ServerRequest {
url!: string;
method!: "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH";
proto!: string;
protoMinor!: number;
protoMajor!: number;
headers!: Headers;
...
}
According to the following list:
mozilla.org - HTTP request methods
Does HTTP standard forbid inventing new method?
Correct, and some servers implement non-standard ones. We should not forbid non-standard HTTP methods. String literals can help, but we can't limit them.
Well, I is quite ugly and Node doesn't seem to support custom HTTP verbs either, but I guess you are right and we should be better. Let's keep it as it is 馃槶..
EDIT: What about the following?
"GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH" | string
EDIT: What about the following?
"GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH" | string
Well that won't do anything. TS naturally resolves this to string even in intellisense.
Most helpful comment
Well that won't do anything. TS naturally resolves this to
stringeven in intellisense.