How to set webdav remote header (connection string syntax)

What is the problem you are having with rclone?

How can I set an X-Access-Token header on a webdav type remote using the connection string syntax? I can set an authorization header using the bearer_token parameter but there doesn't seem to be a 'webdav headers' flag. What am I missing?

What is your rclone version (output from rclone version)

rclone v1.55.0

Which OS you are using and how many bits (eg Windows 7, 64 bit)

  • os/type: linux
  • os/arch: amd64
  • go/version: go1.16.2
  • go/linking: static
  • go/tags: cmount

Which cloud storage system are you using? (eg Google Drive)


The command you were trying to run (eg rclone copy /tmp remote:tmp)

curl -u rclone:rclonesecret -H "Content-Type: application/json" -X POST -d '{"_async":true,"srcFs":":webdav,headers=\"x-access-token: srctoken\",url=\"http://source-remote/webdav\":/home/somedir","dstFs":":webdav,headers=\"x-access-token: desttoken\",url=\"http://dest-remote/webdav\":/home/destdir"}' http://localhost:5572/sync/copy

A log from the command with the -vv flag

Result: The x-access-token headers are not set:

2021/04/21 08:56:41 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2021/04/21 08:57:54 DEBUG : rc: "sync/copy": with parameters map[_async:true dstFs::webdav,headers="x-access-token: desttoken",url="http://dest-remote/webdav":/home/destdir srcFs::webdav,headers="x-access-token: srctoken",url="http://src-remote/webdav":/home/somedir]
2021/04/21 08:57:54 DEBUG : rc: "sync/copy": reply map[jobid:11]: <nil>
2021/04/21 08:57:54 DEBUG : Creating backend with remote ":webdav,headers=\"x-access-token: srctoken\",url=\"http://src-remote/webdav\":/home/somedir"
2021/04/21 08:57:54 DEBUG : :webdav: detected overridden config - adding "{nsyyx}" suffix to name
2021/04/21 08:57:54 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2021/04/21 08:57:54 DEBUG : HTTP REQUEST (req 0xc000521d00)
2021/04/21 08:57:54 DEBUG : PROPFIND /webdav/home/somedir HTTP/1.1
Host: src-remote
User-Agent: rclone/v1.55.0
Depth: 1
Referer: http://src-remote/webdav/
Accept-Encoding: gzip

2021/04/21 08:57:54 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Headers is an global config item, rather than a backend config item.

This means you'd need to set it with a config override like this in your JSON blob

"_config":{"Headers": [{"Key": "X-Potato", "Value": "yes"}]}

I would need config per remote. So that would be something like ?

curl ... -d '{"srcFs":{"type":"webdav","url":"http://src-remote","_path":"/folder2transfer","_config":{"Headers":[{"Key":"X-Access-Token","Value":"srctoken"}]}},"dstFs":{...,"_config":{"Headers":[{"Key":"X-Access-Token","Value":"desttoken"}]}}}'

Where the tokens of both remotes differ. But I see that this (webdav) option does not exist so I guess it's just not possible right?


I don't think that is going to work without a new parameter to the webdav remote.

That would be easy to add though - a straight port of the headers from the http backend would work.

Want to have a go at that? Happy to talk you through it.

Yeah lets do that. I'll be happy to work on that.


What you need to do is steal these bits of code from the http backend

And then a bit of code like this in NewFs to add the header(s) to all requests.

	for i := 0; i < len(opt.Headers); i += 2 {
		key := opt.Headers[i]
		value := opt.Headers[i+1]
		f.srv.SetHeader(key, value)

Hopefully that is enough hints - see this for more general stuff