Add obscure HTTP methods (#3553)

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
Jarred Sumner
2023-07-07 00:38:18 -07:00
committed by GitHub
parent 0ecdbf4793
commit 7ab8d832fb
2 changed files with 86 additions and 18 deletions

View File

@@ -255,19 +255,7 @@ pub const Request = struct {
this: *Request,
globalThis: *JSC.JSGlobalObject,
) callconv(.C) JSC.JSValue {
const string_contents: string = switch (this.method) {
.GET => "GET",
.HEAD => "HEAD",
.PATCH => "PATCH",
.PUT => "PUT",
.POST => "POST",
.OPTIONS => "OPTIONS",
.CONNECT => "CONNECT",
.TRACE => "TRACE",
.DELETE => "DELETE",
};
return ZigString.init(string_contents).toValueGC(globalThis);
return bun.String.static(@tagName(this.method)).toJSConst(globalThis);
}
pub fn getMode(

View File

@@ -11,15 +11,42 @@ const C = bun.C;
const std = @import("std");
pub const Method = enum {
ACL,
BIND,
CHECKOUT,
CONNECT,
COPY,
DELETE,
GET,
HEAD,
PATCH,
PUT,
POST,
LINK,
LOCK,
@"M-SEARCH",
MERGE,
MKACTIVITY,
MKCALENDAR,
MKCOL,
MOVE,
NOTIFY,
OPTIONS,
CONNECT,
PATCH,
POST,
PROPFIND,
PROPPATCH,
PURGE,
PUT,
/// https://httpwg.org/http-extensions/draft-ietf-httpbis-safe-method-w-body.html
QUERY,
REBIND,
REPORT,
SEARCH,
SOURCE,
SUBSCRIBE,
TRACE,
DELETE,
UNBIND,
UNLINK,
UNLOCK,
UNSUBSCRIBE,
const with_body: std.enums.EnumSet(Method) = brk: {
var values = std.enums.EnumSet(Method).initFull();
@@ -47,24 +74,77 @@ pub const Method = enum {
}
const Map = bun.ComptimeStringMap(Method, .{
.{ "ACL", Method.ACL },
.{ "BIND", Method.BIND },
.{ "CHECKOUT", Method.CHECKOUT },
.{ "CONNECT", Method.CONNECT },
.{ "COPY", Method.COPY },
.{ "DELETE", Method.DELETE },
.{ "GET", Method.GET },
.{ "HEAD", Method.HEAD },
.{ "LINK", Method.LINK },
.{ "LOCK", Method.LOCK },
.{ "M-SEARCH", Method.@"M-SEARCH" },
.{ "MERGE", Method.MERGE },
.{ "MKACTIVITY", Method.MKACTIVITY },
.{ "MKCALENDAR", Method.MKCALENDAR },
.{ "MKCOL", Method.MKCOL },
.{ "MOVE", Method.MOVE },
.{ "NOTIFY", Method.NOTIFY },
.{ "OPTIONS", Method.OPTIONS },
.{ "PATCH", Method.PATCH },
.{ "POST", Method.POST },
.{ "PROPFIND", Method.PROPFIND },
.{ "PROPPATCH", Method.PROPPATCH },
.{ "PURGE", Method.PURGE },
.{ "PUT", Method.PUT },
.{ "QUERY", Method.QUERY },
.{ "REBIND", Method.REBIND },
.{ "REPORT", Method.REPORT },
.{ "SEARCH", Method.SEARCH },
.{ "SOURCE", Method.SOURCE },
.{ "SUBSCRIBE", Method.SUBSCRIBE },
.{ "TRACE", Method.TRACE },
.{ "UNBIND", Method.UNBIND },
.{ "UNLINK", Method.UNLINK },
.{ "UNLOCK", Method.UNLOCK },
.{ "UNSUBSCRIBE", Method.UNSUBSCRIBE },
.{ "acl", Method.ACL },
.{ "bind", Method.BIND },
.{ "checkout", Method.CHECKOUT },
.{ "connect", Method.CONNECT },
.{ "copy", Method.COPY },
.{ "delete", Method.DELETE },
.{ "get", Method.GET },
.{ "head", Method.HEAD },
.{ "link", Method.LINK },
.{ "lock", Method.LOCK },
.{ "m-search", Method.@"M-SEARCH" },
.{ "merge", Method.MERGE },
.{ "mkactivity", Method.MKACTIVITY },
.{ "mkcalendar", Method.MKCALENDAR },
.{ "mkcol", Method.MKCOL },
.{ "move", Method.MOVE },
.{ "notify", Method.NOTIFY },
.{ "options", Method.OPTIONS },
.{ "patch", Method.PATCH },
.{ "post", Method.POST },
.{ "propfind", Method.PROPFIND },
.{ "proppatch", Method.PROPPATCH },
.{ "purge", Method.PURGE },
.{ "put", Method.PUT },
.{ "query", Method.QUERY },
.{ "rebind", Method.REBIND },
.{ "report", Method.REPORT },
.{ "search", Method.SEARCH },
.{ "source", Method.SOURCE },
.{ "subscribe", Method.SUBSCRIBE },
.{ "trace", Method.TRACE },
.{ "unbind", Method.UNBIND },
.{ "unlink", Method.UNLINK },
.{ "unlock", Method.UNLOCK },
.{ "unsubscribe", Method.UNSUBSCRIBE },
});
pub fn which(str: []const u8) ?Method {