Repository: caddyserver/caddy (language: go)

Issue:
Feature Request: Add method subdirective to caddy file
As stated [here](https://caddy.community/t/v2-rewrite-get-as-post-request/7252) it looks like the subdirective `method` is not yet available in Caddy v2 to be used in the Caddyfile.
Any plans on implementing it?


Discussion / hints:

Fix patch:
diff --git a/caddyconfig/httpcaddyfile/directives.go b/caddyconfig/httpcaddyfile/directives.go
index 8d895dd92ce..feb8e91ad91 100644
--- a/caddyconfig/httpcaddyfile/directives.go
+++ b/caddyconfig/httpcaddyfile/directives.go
@@ -45,7 +45,8 @@ var directiveOrder = []string{
 
 	"redir",
 
-	// URI manipulation
+	// incoming request manipulation
+	"method",
 	"rewrite",
 	"uri",
 	"try_files",
diff --git a/modules/caddyhttp/rewrite/caddyfile.go b/modules/caddyhttp/rewrite/caddyfile.go
index 9621af14618..15abbfa74de 100644
--- a/modules/caddyhttp/rewrite/caddyfile.go
+++ b/modules/caddyhttp/rewrite/caddyfile.go
@@ -27,6 +27,7 @@ import (
 
 func init() {
 	httpcaddyfile.RegisterHandlerDirective("rewrite", parseCaddyfileRewrite)
+	httpcaddyfile.RegisterHandlerDirective("method", parseCaddyfileMethod)
 	httpcaddyfile.RegisterHandlerDirective("uri", parseCaddyfileURI)
 	httpcaddyfile.RegisterDirective("handle_path", parseCaddyfileHandlePath)
 }
@@ -51,6 +52,24 @@ func parseCaddyfileRewrite(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler,
 	return rewr, nil
 }
 
+// parseCaddyfileMethod sets up a basic method rewrite handler from Caddyfile tokens. Syntax:
+//
+//     method [<matcher>] <method>
+//
+func parseCaddyfileMethod(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) {
+	var rewr Rewrite
+	for h.Next() {
+		if !h.NextArg() {
+			return nil, h.ArgErr()
+		}
+		rewr.Method = h.Val()
+		if h.NextArg() {
+			return nil, h.ArgErr()
+		}
+	}
+	return rewr, nil
+}
+
 // parseCaddyfileURI sets up a handler for manipulating (but not "rewriting") the
 // URI from Caddyfile tokens. Syntax:
 //


Test patch:
diff --git a/caddytest/integration/caddyfile_adapt/method_directive.txt b/caddytest/integration/caddyfile_adapt/method_directive.txt
new file mode 100644
index 00000000000..786df90c8ab
--- /dev/null
+++ b/caddytest/integration/caddyfile_adapt/method_directive.txt
@@ -0,0 +1,27 @@
+:8080 {
+	method FOO
+}
+----------
+{
+	"apps": {
+		"http": {
+			"servers": {
+				"srv0": {
+					"listen": [
+						":8080"
+					],
+					"routes": [
+						{
+							"handle": [
+								{
+									"handler": "rewrite",
+									"method": "FOO"
+								}
+							]
+						}
+					]
+				}
+			}
+		}
+	}
+}
\ No newline at end of file