I have a route and a controller similar to:
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
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.
For those who are not familiar with the use-case for the REPORT verb, here is an article about it: https://evertpot.com/dropbox-post-api/
Any help would be appreciated
The reason is that Plug.Parsers only reads and parses the request body for standard HTTP methods (https://hexdocs.pm/plug/Plug.Parsers.html#content), not for WebDAV extension methods.
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.
Good idea. I’m pressed for time, but I’ll see about circling back for submitting a patch like that.
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.
I created a gist if people are interested in how that might be done: https://gist.github.com/hosh/93d2d88ab31eeb3520737d6fc54ac484