Skip to content

x/net/webdav: no trailing slash on href to a directory #29858

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

Closed
mickael-kerjean opened this issue Jan 22, 2019 · 10 comments
Closed

x/net/webdav: no trailing slash on href to a directory #29858

mickael-kerjean opened this issue Jan 22, 2019 · 10 comments
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mickael-kerjean
Copy link

mickael-kerjean commented Jan 22, 2019

What version of Go are you using (go version)?

go version go1.11 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mickael/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mickael/Documents/projects/go/"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/7w/08pnvwm554xc18_b012cbgs00000gn/T/go-build184274398=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I've created a webdav server based on https://godoc.org/golang.org/x/net/webdav then started querying it:

echo '<?xml version="1.0"?><a:propfind xmlns:a="DAV:"><a:prop><a:resourcetype/></a:prop></a:propfind>' | curl -X PROPFIND http://127.0.0.1:8334/s/SrRunIQ/ -H "Depth: 1" --upload-file - | xmllint --format -

What did you expect to see?

Like other webdav servers I made some test with, I expected the href attribute to end with a "/" for directories

What did you see instead?

The href attribute never end with a "/"

<?xml version="1.0" encoding="UTF-8"?>
<D:multistatus xmlns:D="DAV:">
   .....
  <D:response>
    <D:href>/s/SrRunIQ/paper</D:href> <- is a folder but doesn't end with a "/"
    <D:propstat>
      <D:prop>
        <D:resourcetype>
          <D:collection xmlns:D="DAV:"/>
        </D:resourcetype>
      </D:prop>
      <D:status>HTTP/1.1 200 OK</D:status>
    </D:propstat>
  </D:response>
  ....
</D:multistatus>

I made a quick fix as this piece of code is a big deal in the context of where I'm using the webdav server for.

@bcmills bcmills changed the title net/webdav x/net/webdav: no trailing slash on href to a directory Jan 22, 2019
@gopherbot gopherbot added this to the Unreleased milestone Jan 22, 2019
@bcmills
Copy link
Contributor

bcmills commented Jan 22, 2019

CC @bradfitz @nigeltao

@bradfitz
Copy link
Contributor

Does the spec say anything about this?

@bradfitz bradfitz added help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jan 22, 2019
@mickael-kerjean
Copy link
Author

In RFC 4918:

The rules in this section apply ... to resource URLs in the 'href' ...... Identifiers for collections SHOULD end in a '/' character.

@mickael-kerjean
Copy link
Author

mickael-kerjean commented Jan 23, 2019

other webdav server - install

Apache webdav:
docker run -ti --name webdav -p 8888:80 ubuntu:latest bash
apt update
apt install curl apache2 vim libxml2-utils
mkdir /var/www/webdav
chown -R www-data:www-data /var/www/
a2enmod dav
a2enmod dav_fs
vi /etc/apache2/sites-available/000-default.conf
# https://www.digitalocean.com/community/tutorials/how-to-configure-webdav-access-with-apache-on-ubuntu-14-04
service apache2 restart

touch /var/www/webdav/test.html
mkdir /var/www/webdav/test
echo '<?xml version="1.0"?><a:propfind xmlns:a="DAV:"><a:prop><a:resourcetype/></a:prop></a:propfind>' | curl -X PROPFIND http://127.0.0.1/webdav/ --upload-file - -H "Depth: 1" | xmllint --format -
Sabre dav via Nextcloud:

Creating an account on their demo

other webdav server - test

via curl:

echo '<?xml version="1.0"?><a:propfind xmlns:a="DAV:"><a:prop><a:resourcetype/></a:prop></a:propfind>' | curl -X PROPFIND http://127.0.0.1/webdav/ --upload-file - -H "Depth: 1"
observation:

On both servers, the href attribute in the xml end with a "/" for collections. Example response using the Apache webdav with 2 things inside the webdav folder: 1 directory called "test" and a file called test.html

<?xml version="1.0" encoding="utf-8"?>
<D:multistatus xmlns:D="DAV:" xmlns:ns0="DAV:">
  <D:response xmlns:lp1="DAV:">
    <D:href>/webdav/</D:href>
    <D:propstat>
      <D:prop>
        <lp1:resourcetype>
          <D:collection/>
        </lp1:resourcetype>
      </D:prop>
      <D:status>HTTP/1.1 200 OK</D:status>
    </D:propstat>
  </D:response>
  <D:response xmlns:lp1="DAV:">
    <D:href>/webdav/test.html</D:href>
    <D:propstat>
      <D:prop>
        <lp1:resourcetype/>
      </D:prop>
      <D:status>HTTP/1.1 200 OK</D:status>
    </D:propstat>
  </D:response>
  <D:response xmlns:lp1="DAV:">
    <D:href>/webdav/test/</D:href>
    <D:propstat>
      <D:prop>
        <lp1:resourcetype>
          <D:collection/>
        </lp1:resourcetype>
      </D:prop>
      <D:status>HTTP/1.1 200 OK</D:status>
    </D:propstat>
  </D:response>
</D:multistatus>

the href field has a "/" at the end of the HREF for directories

@nigeltao
Copy link
Contributor

CC @rsto

@rsto
Copy link
Contributor

rsto commented Jan 24, 2019

The patch LGTM.

Just curious: is the trailing / for collections expected by a particular DAV client or library?

@mickael-kerjean
Copy link
Author

No idea, personally, I wanted to use this as an optimisation in this project to reduce the network round trip as my data isn't store locally but on some remote backends: S3, FTP, SFTP, ...

@mickael-kerjean
Copy link
Author

mickael-kerjean commented Jan 24, 2019

Also, let me know if I'm wrong but the current implementation of the webdav server seems to assume that opening a file and performing a stat is a cheap operation. In my scenario trying to make a webdav server of an S3 bucket, such an assumption is not true and is large of a consequence when the webdav server is mounted on the OS. To fix this, I made some additional changes in the webdav implementation to avoid unnecessary file opening, stats and close in the request lifecycle. Any chance that this problem of unnecessary file opening could be fix in the meantime?

@nigeltao
Copy link
Contributor

I only skimmed them briefly, but I think both changes are broadly acceptable (as two separate changes).

The contribution guidelines are at
https://golang.org/doc/contribute.html

If you haven't submitted a Go patch before, note that we will need https://golang.org/doc/contribute.html#cla

If you're familiar with GitHub's flow, you might want to follow https://golang.org/doc/contribute.html#sending_a_change_github which is a relatively new process.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/163863 mentions this issue: webdav: add trailing slash on directories

ncw added a commit to rclone/rclone that referenced this issue Jun 6, 2019
This is a test to fix golang/go#29858

When passed the "/" directory, it adds an additional "/" which upsets
some clients (duplicacy for instance).
@golang golang locked and limited conversation to collaborators Feb 27, 2020
dt-eric-lefevreardant pushed a commit to DiliTrust/go-webdav that referenced this issue Mar 11, 2025
Fixes golang/go#29858

Change-Id: I7bd8357a7def7daab1fd6357a888ff4e676a1bee
GitHub-Last-Rev: a6dc776fa3aad595643943dcff88efcf152d6be1
GitHub-Pull-Request: golang/net#32
Reviewed-on: https://go-review.googlesource.com/c/163863
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants