webdav: try to handle HEAD for collection too

The underlying golang webdav library returns Method Not Allowed for
HEAD requests on directories:

https://github.com/golang/net/blob/master/webdav/webdav.go#L210

let's see if we can workaround this inside SFTPGo itself in a similar
way as we do for GET.

The HEAD response will not return a Content-Length, we cannot handle
this inside SFTPGo.

Fixes #294
This commit is contained in:
Nicola Murino
2021-02-03 22:36:13 +01:00
parent 4872ba2ea0
commit fc9082c422
4 changed files with 55 additions and 27 deletions

View File

@@ -1314,6 +1314,29 @@ func TestBytesRangeRequests(t *testing.T) {
assert.NoError(t, err)
}
func TestHEAD(t *testing.T) {
u := getTestUser()
user, _, err := httpdtest.AddUser(u, http.StatusCreated)
assert.NoError(t, err)
rootPath := fmt.Sprintf("http://%v/%v", webDavServerAddr, user.Username)
httpClient := httpclient.GetHTTPClient()
req, err := http.NewRequest(http.MethodHead, rootPath, nil)
if assert.NoError(t, err) {
req.SetBasicAuth(u.Username, u.Password)
resp, err := httpClient.Do(req)
if assert.NoError(t, err) {
assert.Equal(t, http.StatusMultiStatus, resp.StatusCode)
assert.Equal(t, "text/xml; charset=utf-8", resp.Header.Get("Content-Type"))
resp.Body.Close()
}
}
_, err = httpdtest.RemoveUser(user, http.StatusOK)
assert.NoError(t, err)
err = os.RemoveAll(user.GetHomeDir())
assert.NoError(t, err)
}
func TestGETAsPROPFIND(t *testing.T) {
u := getTestUser()
subDir1 := "/sub1"