Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use webdav verbs #1532

Closed
sdalu opened this issue Nov 13, 2023 · 3 comments
Closed

Unable to use webdav verbs #1532

sdalu opened this issue Nov 13, 2023 · 3 comments

Comments

@sdalu
Copy link

sdalu commented Nov 13, 2023

Connection#run_request checks for verb in Connection::METHODS.

Unfortunetaly Connection::METHODS is defined ad Set.new %i[get post put delete head patch options trace] which doesn't allows PROPFIND, PROPPATCH, MKCOL, COPY, ...

@iMacTia
Copy link
Member

iMacTia commented Nov 14, 2023

Hi @sdalu, that shouldn't be the case, run_request allows you to specify any method you like, including the ones from the WebDAV's extension. I tried this locally to confirm (tested with Faraday 2.7.11):

res = Faraday.new.run_request(:copy, 'http://httpbingo.org', nil, {})

res.headers # check headers to ensure the request happened
# => {"access-control-allow-credentials"=>"true",
# "access-control-allow-origin"=>"*",
# "content-type"=>"text/plain; charset=utf-8",
# "x-content-type-options"=>"nosniff",
# "date"=>"Tue, 14 Nov 2023 09:38:44 GMT",
# "content-encoding"=>"gzip",
# "transfer-encoding"=>"chunked",
# "server"=>"Fly/442f90d3 (2023-11-07)",
# "via"=>"1.1 fly.io",
# "fly-request-id"=>"01HF6K53ZP9SERP27MBTT8G93K-lhr",
# "cf-team"=>"1c6ecba7e0000048c3fb9f3400000001"}

res.body # we even got a response from httpbingo
# => "method COPY not allowed\n"

Could you please share more details around what you're trying and what error you're getting from Faraday, exactly?

@sdalu
Copy link
Author

sdalu commented Nov 14, 2023

On 2.7.11 as well:

require 'faraday'

f = Faraday.new(url: 'http://httpbingo.org') do |f|
end

f.run_request(:proppatch, "/foo", nil, {})
/usr/local/lib/ruby/gems/3.2/gems/faraday-2.7.11/lib/faraday/connection.rb:433:in `run_request': unknown http method: proppatch (ArgumentError)

        raise ArgumentError, "unknown http method: #{method}"
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	from t.rb:6:in `<main>'

@iMacTia
Copy link
Member

iMacTia commented Nov 14, 2023

You're right, I was messing with Faraday::Connection::METHODS before testing the call and I ended up adding :copy to it, which made my code work 🤦. Sorry about that!

Faraday::Connection::METHODS is not frozen, so you should be able to add all the WebDAV methods to it:

Faraday::Connection::METHODS.merge([:copy, :lock, :mkcol, :move, :propfind, :proppatch, :unlock])

After that, you'll be able to use run_request with all of them 👍.
This looks like a reasonable hack for the time being, especially considering these are not as widely used as the standard HTTP verbs.

I appreciate you were probably looking to make them first-class citizens like the others, and potentially make them methods like Faraday.copy or connection.proppatch, but I feel like that addition feels unnecessary in the core Faraday library.

If you'd like to see that happening, then my suggestion would be to instead build an extension gem (faraday-webdav?) that adds these verbs to the list of allowed verbs and also defines the missing methods ❤️ .

I'm closing this issue because of the problem described being "solved" with the hack, but if you're interested in the extension idea and would like discussing it more, then I'd encourage you to open a discussion instead 🙌 !

@iMacTia iMacTia closed this as completed Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants