Handle DELETE and PATCH. Be lenient and hand URL query parameters to
the user with a DELETE. There is debate about whether DELETE should
handle query parameters. Additionally, some implementations even reject
DELETE requests with a body. So, leave all these additional
"protections" for a later implementation (e.g. in furnace).
Treat unknown methods like requests without parameters.
HELP: post-request?
{ $values { "?" boolean } }
-{ $description "Outputs if the current request is a POST request.s" } ;
+{ $description "Outputs if the current request is a POST request." } ;
+
+HELP: method=
+{ $values { "str" "a string" } { "?" boolean } }
+{ $description "Outputs if the current request matches the expected method." } ;
HELP: responder-nesting
{ $description "A sequence of " { $snippet "{ path responder }" } " pairs." } ;
M: raw-response write-full-response
nip write-response ;
-: post-request? ( -- ? ) request get method>> "POST" = ;
+: method= ( str -- ? ) request get method>> = ;
+
+: post-request? ( -- ? ) "POST" method= ;
SYMBOL: responder-nesting
{ "GET" [ url>> query>> ] }
{ "HEAD" [ url>> query>> ] }
{ "OPTIONS" [ url>> query>> ] }
+ { "DELETE" [ url>> query>> ] }
{ "POST" [ post-data>> params>> ] }
+ { "PATCH" [ post-data>> params>> ] }
{ "PUT" [ post-data>> params>> ] }
+ [ 2drop H{ } clone ]
} case ;
SYMBOL: params