net_dav icon indicating copy to clipboard operation
net_dav copied to clipboard

net_dav can put textfile only?

Open sanemat opened this issue 14 years ago • 21 comments

I want to put imagefile. But I see raised error ArgumentError: Content-Length not given and Transfer-Encoding is not `chunked'

sanemat avatar Jul 08 '10 10:07 sanemat

Do you have any sample code that replicates the issue?

devrandom avatar Jul 08 '10 17:07 devrandom

My code is below. Is this wrong style of writing?

dav = Net::DAV.new('https://example.com/webdav/')
file = '1px.gif'
File.open(file, "rb") {|stream|
    dav.put(file, stream, File.size(file))
}

sanemat avatar Jul 09 '10 16:07 sanemat

It works fine when I try it. Can you make sure that File.size(file) returns a number greater than zero?

devrandom avatar Jul 09 '10 23:07 devrandom

Yes, File.size(file) returns 6.

sanemat avatar Jul 10 '10 17:07 sanemat

Hm... puzzling. What version of ruby and what OS are you on? Do you have the curb gem installed?

devrandom avatar Jul 10 '10 18:07 devrandom

my version OS : Fedora12(i686) Ruby : 1.8.7-p299, 1.9.2-rc1, REE1.8.6 (used rvm) net_dav: 0.5.0 curb : 0.7.7.1 curl : 7.19.7

sanemat avatar Jul 12 '10 14:07 sanemat

That's pretty recent, so probably not a ruby version problem.

We set the content_length in request_sending_stream(verb, path, stream, length, headers), so I don't see how this can happen.

I'll try to create a VM with fedora12, but it may take awhile. You might want to try using rdebug to step through the code and see if you can identify the issue.

devrandom avatar Jul 15 '10 19:07 devrandom

I believe I identified the issue. A new commit has been applied - 2728a01b15d9299467bed4f52629a2bc9d8f026d . Please try it and let me know.

devrandom avatar Jul 23 '10 17:07 devrandom

bump! :) we are getting the same error on ruby 1.9.2 we are sending a text file using the same code as above.

antz29 avatar Mar 22 '12 15:03 antz29

I can't replicate this, and content_length seems to be carried along. Could you add some print statements to see if req.content_length is blank in the web_dav gem?

devrandom avatar Apr 07 '12 03:04 devrandom

Same problem here.

ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]
#!/usr/bin/env ruby

require 'net/dav'
require 'tmpdir'

uri = "http://localhost:30080/cargohold/"
dav = Net::DAV.new(uri)
dav.verify_server = false
dav.credentials("airspace", "carousel")

cargo = File.join(Dir.tmpdir, "testing.txt")
File.open(cargo, 'w') {|f| f.write(100.times.map{65.+(rand(25)).chr}.join) }
File.open(cargo) { |stream|
  dav.put("#{uri}#{File.basename(cargo)}", stream, File.size(cargo))
}
/Users/mikec/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1942:in `send_request_with_body_stream': Content-Length not given and Transfer-Encoding is not `chunked' (ArgumentError)
    from /Users/mikec/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1921:in `exec'
    from /Users/mikec/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1317:in `block in transport_request'
    from /Users/mikec/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1316:in `catch'
    from /Users/mikec/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1316:in `transport_request'
    from /Users/mikec/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1293:in `request'
    from /Users/mikec/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1286:in `block in request'
    from /Users/mikec/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:745:in `start'
    from /Users/mikec/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1284:in `request'
    from /Users/mikec/.rvm/gems/ruby-1.9.3-p194@carousel/gems/net_dav-0.5.0/lib/net/dav.rb:145:in `handle_request'
    from /Users/mikec/.rvm/gems/ruby-1.9.3-p194@carousel/gems/net_dav-0.5.0/lib/net/dav.rb:162:in `handle_request'
    from /Users/mikec/.rvm/gems/ruby-1.9.3-p194@carousel/gems/net_dav-0.5.0/lib/net/dav.rb:76:in `request_sending_stream'
    from /Users/mikec/.rvm/gems/ruby-1.9.3-p194@carousel/gems/net_dav-0.5.0/lib/net/dav.rb:508:in `put'
    from ./test.rb:14:in `block in <main>'
    from ./test.rb:13:in `open'
    from ./test.rb:13:in `<main>'

mconigliaro avatar May 24 '12 23:05 mconigliaro

For what it's worth, I believe the error message from Net::HTTP is erroneous. Using netcat (nc -l 30080), I can see that the Content-Length header is in fact being sent with the request:

PUT /cargohold/testing.txt HTTP/1.1
Accept: */*
User-Agent: Ruby
Content-Length: 100
Content-Type: text/xml; charset="utf-8"
Connection: close
Host: localhost:30080

AUWQIXWUDQRAMOIHUQPMSAXPNLDQOMWUYBWLIIQRXJFUTDHIKOKARRHWTVSNRMKJABEXYCLBOTXEQFAJIKNBHKDVBONNSNLUOXRV

mconigliaro avatar May 24 '12 23:05 mconigliaro

OK guys, this definitely has something to do with authentication. Notice that in my last comment, no Authorization header gets sent with the request. I also get 401 (Unauthorized) errors in the logs when I run my test script against a real server. Disabling authentication on the server allows the script to work again.

mconigliaro avatar May 25 '12 00:05 mconigliaro

Are you able to post headers of the failure? There should be two requests, one without auto, and one with. There should be two requests, one without credentials which gets a 401. The second should be with credentials. Perhaps the second is not sending content-length.

devrandom avatar May 25 '12 17:05 devrandom

I just tried it locally with ruby 1.8 and 1.9, and it works as expected. The authentication is sent on the second requests, and the content-length header is present in both requests.

devrandom avatar May 25 '12 18:05 devrandom

The people that had this issue - can you see if the latest commits changed this behavior?

devrandom avatar Jul 06 '12 20:07 devrandom

I had this issue with the published gem, and using the latest from github (with this fix) did fix the problem. Any chance of releasing a new gem version?

jeffgran avatar Oct 03 '12 03:10 jeffgran

Same exception when uploading gpg-encrypted file into Yandex.Disk webdav using basic auth. This is when installed from gem install. It is resolved, though, when gem is installed directly from this repo.

Hey, I see you abandoned maintaining this package, but can you, at least, release current version (as 0.6.0 probably) into rubygems so it installs by default by gem install?

do11 avatar Nov 08 '15 15:11 do11

Did you have any issues building? I had issues last time I tried. If anybody can contribute a patch to bring dependencies and build up to date, that would be appreciated.

On 8 November 2015 10:57:01 GMT-05:00, do11 [email protected] wrote:

Same exception when uploading gpg-encrypted file into Yandex.Disk webdav using basic auth. This is when installed from gem install. It is resolved, though, when gem is installed directly from this repo.

Hey, I see you abandoned maintaining this package, but can you, at least, release current version (as 0.6.0 probably) into rubygems so it installs by default by gem install?


Reply to this email directly or view it on GitHub: https://github.com/devrandom/net_dav/issues/3#issuecomment-154835032

Sent from my phone. Please excuse my brevity.

devrandom avatar Nov 08 '15 19:11 devrandom

Did you have any issues building?

No. It was as simple as

git clone https://github.com/devrandom/net_dav.git
gem build net_dav.gemspec
gem install ./net_dav-0.5.0.gem

Centos 6.6, but ruby is old install from the sources: ruby 1.9.3p545 (2014-02-24 revision 45159) [x86_64-linux]

Only problem I had after is that upload for ~2G file is still failed with

/usr/local/lib/ruby/1.9.1/net/protocol.rb:146:in `rescue in rbuf_fill': Timeout::Error (Timeout::Error)
        from /usr/local/lib/ruby/1.9.1/net/protocol.rb:140:in `rbuf_fill'
        from /usr/local/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil'
        from /usr/local/lib/ruby/1.9.1/net/protocol.rb:132:in `readline'
        from /usr/local/lib/ruby/1.9.1/net/http.rb:2563:in `read_status_line'
        from /usr/local/lib/ruby/1.9.1/net/http.rb:2552:in `read_new'
        from /usr/local/lib/ruby/1.9.1/net/http.rb:1320:in `block in transport_request'
        from /usr/local/lib/ruby/1.9.1/net/http.rb:1317:in `catch'
        from /usr/local/lib/ruby/1.9.1/net/http.rb:1317:in `transport_request'
        from /usr/local/lib/ruby/1.9.1/net/http.rb:1294:in `request'
        from /usr/local/lib/ruby/1.9.1/net/http.rb:1287:in `block in request'
        from /usr/local/lib/ruby/1.9.1/net/http.rb:746:in `start'
        from /usr/local/lib/ruby/1.9.1/net/http.rb:1285:in `request'
        from /usr/local/lib/ruby/gems/1.9.1/gems/net_dav-0.5.0/lib/net/dav.rb:171:in `handle_request'
        from /usr/local/lib/ruby/gems/1.9.1/gems/net_dav-0.5.0/lib/net/dav.rb:85:in `request_sending_stream'
        from /usr/local/lib/ruby/gems/1.9.1/gems/net_dav-0.5.0/lib/net/dav.rb:610:in `put'
        from sync-yandex.rb:110:in `block in <main>'

until I did gem install curb. After that all is smooth.

do11 avatar Nov 08 '15 19:11 do11

Well, I still get timeouts on big files even with curb installed. That's unfortunate.

/usr/local/lib/ruby/1.9.1/net/protocol.rb:146:in `rescue in rbuf_fill': Timeout::Error (Timeout::Error)
        from /usr/local/lib/ruby/1.9.1/net/protocol.rb:140:in `rbuf_fill'
        from /usr/local/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil'
        from /usr/local/lib/ruby/1.9.1/net/protocol.rb:132:in `readline'
        from /usr/local/lib/ruby/1.9.1/net/http.rb:2563:in `read_status_line'
        from /usr/local/lib/ruby/1.9.1/net/http.rb:2552:in `read_new'
        from /usr/local/lib/ruby/1.9.1/net/http.rb:1320:in `block in transport_request'
        from /usr/local/lib/ruby/1.9.1/net/http.rb:1317:in `catch'
        from /usr/local/lib/ruby/1.9.1/net/http.rb:1317:in `transport_request'
        from /usr/local/lib/ruby/1.9.1/net/http.rb:1294:in `request'
        from /usr/local/lib/ruby/1.9.1/net/http.rb:1287:in `block in request'
        from /usr/local/lib/ruby/1.9.1/net/http.rb:746:in `start'
        from /usr/local/lib/ruby/1.9.1/net/http.rb:1285:in `request'
        from /usr/local/lib/ruby/gems/1.9.1/gems/net_dav-0.5.0/lib/net/dav.rb:171:in `handle_request'
        from /usr/local/lib/ruby/gems/1.9.1/gems/net_dav-0.5.0/lib/net/dav.rb:85:in `request_sending_stream'
        from /usr/local/lib/ruby/gems/1.9.1/gems/net_dav-0.5.0/lib/net/dav.rb:610:in `put'
        from sync-yandex.rb:125:in `block (2 levels) in <main>'

do11 avatar Nov 17 '15 18:11 do11