From 2e2e0cd4b69afdee9a78755fd2c4aaac2389714f Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 24 Nov 2022 14:09:02 +0100 Subject: [PATCH 1/3] fix HTTP1.1 RFC 2616 for bodies smaller than 1GB --- .../proxy/pkg/middleware/authentication.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/services/proxy/pkg/middleware/authentication.go b/services/proxy/pkg/middleware/authentication.go index d32decfe5..e36b7c8c2 100644 --- a/services/proxy/pkg/middleware/authentication.go +++ b/services/proxy/pkg/middleware/authentication.go @@ -2,6 +2,8 @@ package middleware import ( "fmt" + "io" + "io/ioutil" "net/http" "regexp" "strings" @@ -28,6 +30,9 @@ var ( "/ocs/v2.php/apps/files_sharing/api/v1/tokeninfo/unprotected", "/ocs/v1.php/cloud/capabilities", } + + // TODO: expose me in the configuration + limit int64 = 10 ^ 9 ) const ( @@ -104,6 +109,19 @@ func Authentication(auths []Authenticator, opts ...Option) func(next http.Handle webdav.HandleWebdavError(w, b, err) } + + if r.ProtoMajor == 1 { + // https://github.com/owncloud/ocis/issues/5066 + // https://github.com/golang/go/blob/d5de62df152baf4de6e9fe81933319b86fd95ae4/src/net/http/server.go#L1357-L1417 + // https://github.com/golang/go/issues/15527 + + defer r.Body.Close() + var reader io.Reader = r.Body + if limit > 0 { + reader = io.LimitReader(r.Body, limit) + } + io.Copy(ioutil.Discard, reader) + } }) } } From c6b61cd3470ff8a5fb83ca69fd237664751ce544 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 24 Nov 2022 16:48:25 +0100 Subject: [PATCH 2/3] remove any limits --- services/proxy/pkg/middleware/authentication.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/services/proxy/pkg/middleware/authentication.go b/services/proxy/pkg/middleware/authentication.go index e36b7c8c2..ebd6a2a0e 100644 --- a/services/proxy/pkg/middleware/authentication.go +++ b/services/proxy/pkg/middleware/authentication.go @@ -30,9 +30,6 @@ var ( "/ocs/v2.php/apps/files_sharing/api/v1/tokeninfo/unprotected", "/ocs/v1.php/cloud/capabilities", } - - // TODO: expose me in the configuration - limit int64 = 10 ^ 9 ) const ( @@ -116,11 +113,7 @@ func Authentication(auths []Authenticator, opts ...Option) func(next http.Handle // https://github.com/golang/go/issues/15527 defer r.Body.Close() - var reader io.Reader = r.Body - if limit > 0 { - reader = io.LimitReader(r.Body, limit) - } - io.Copy(ioutil.Discard, reader) + io.Copy(ioutil.Discard, r.Body) } }) } From 0ba134dbf601fdf047c9552f1b163d60ccf36c2e Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 24 Nov 2022 17:07:01 +0100 Subject: [PATCH 3/3] discard errors --- services/proxy/pkg/middleware/authentication.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/proxy/pkg/middleware/authentication.go b/services/proxy/pkg/middleware/authentication.go index ebd6a2a0e..4a436cb3a 100644 --- a/services/proxy/pkg/middleware/authentication.go +++ b/services/proxy/pkg/middleware/authentication.go @@ -113,7 +113,7 @@ func Authentication(auths []Authenticator, opts ...Option) func(next http.Handle // https://github.com/golang/go/issues/15527 defer r.Body.Close() - io.Copy(ioutil.Discard, r.Body) + _, _ = io.Copy(ioutil.Discard, r.Body) } }) }