Skip to content

Commit

Permalink
Merge pull request #3618 from kobergj/FixConnectionClosedOnPUT
Browse files Browse the repository at this point in the history
Drain body on failed PUT and POST requests
  • Loading branch information
kobergj committed Jan 24, 2023
2 parents a6fe69c + 75c54cb commit fae9753
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/drain-body-on-put.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions internal/http/services/owncloud/ocdav/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package ocdav

import (
"context"
"io"
"net/http"
"path"
"strconv"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions internal/http/services/owncloud/ocdav/tus.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package ocdav
import (
"context"
"encoding/json"
"io"
"net/http"
"path"
"strconv"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fae9753

Please sign in to comment.