diff --git a/changelog/unreleased/drain-body-on-put.md b/changelog/unreleased/drain-body-on-put.md new file mode 100644 index 0000000000..2047456996 --- /dev/null +++ b/changelog/unreleased/drain-body-on-put.md @@ -0,0 +1,5 @@ +Bugfix: Drain body on failed put + +When a put request fails the server would not drain the body. This will lead to `connection closed` errors on clients when using http 1 + +https://github.com/cs3org/reva/pull/3618 diff --git a/internal/http/services/owncloud/ocdav/put.go b/internal/http/services/owncloud/ocdav/put.go index 1ffcc543c7..c4f4005547 100644 --- a/internal/http/services/owncloud/ocdav/put.go +++ b/internal/http/services/owncloud/ocdav/put.go @@ -20,6 +20,7 @@ package ocdav import ( "context" + "io" "net/http" "path" "strconv" @@ -239,6 +240,10 @@ func (s *svc) handlePut(ctx context.Context, w http.ResponseWriter, r *http.Requ } if uRes.Status.Code != rpc.Code_CODE_OK { + if r.ProtoMajor == 1 { + // drain body to avoid `connection closed` errors + _, _ = io.Copy(io.Discard, r.Body) + } switch uRes.Status.Code { case rpc.Code_CODE_PERMISSION_DENIED: status := http.StatusForbidden diff --git a/internal/http/services/owncloud/ocdav/tus.go b/internal/http/services/owncloud/ocdav/tus.go index b792f034c8..ff4d58b04d 100644 --- a/internal/http/services/owncloud/ocdav/tus.go +++ b/internal/http/services/owncloud/ocdav/tus.go @@ -21,6 +21,7 @@ package ocdav import ( "context" "encoding/json" + "io" "net/http" "path" "strconv" @@ -204,6 +205,10 @@ func (s *svc) handleTusPost(ctx context.Context, w http.ResponseWriter, r *http. } if uRes.Status.Code != rpc.Code_CODE_OK { + if r.ProtoMajor == 1 { + // drain body to avoid `connection closed` errors + _, _ = io.Copy(io.Discard, r.Body) + } if uRes.Status.Code == rpc.Code_CODE_NOT_FOUND { w.WriteHeader(http.StatusPreconditionFailed) return