match :report, "/documents/:id", DocumentsController, :show
I can get to the endpoint fine. However, when I pass in a body to the REPORT verb, it does not show up in the body_params.
I am trying to figure out. I have a similar endpoint using POST, and when I use a similar curl command, the payload comes through into body_params. I kind of wonder if this was something that got filtered out from Cowboy, but I am having difficulty finding information about this.
If you’d like to treat REPORT as POST in your application, meaning all routes support both verbs and they are semantically identical to your server, you just want clients to be able to use REPORT in order to change the behaviour of external elements (e.g. proxies), then you could write a little plug inspired by Plug.Head (https://github.com/elixir-plug/plug/blob/master/lib/plug/head.ex) to replace the request method prior to invoking Plug.Parsers. You could add a conn flag to indicate the original request method, if needed.
Your router would only need the POST routes in that case.
Thanks, that explains how that works. It makes sense to minimize the body params parsing to known verbs.
I appreciate the suggested solution, though I don’t think it will work in this circumstance. I’m going to look into writing a plugin parser that hooks into the existing one.
I’m sure the Plug team would consider a PR for Plug.Parsers making the list of verbs a compile-time configuration option. The default would be the current list, but applications that require support for WebDAV and other extensions might change the list to suit their needs.
For those interested, I ended up doing what @voltone suggested with an additional Plug to restore the real method after extraction. Having tried this, I think I know what I would need to do for submitting a patch to the Plug team.