From aa29171f3aa752e708b2232789ea46249d555414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 19 May 2023 16:26:59 +0200 Subject: [PATCH] fix preflight requests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- changelog/unreleased/fix-preflight-requests.md | 5 +++++ internal/http/interceptors/cors/cors.go | 2 +- internal/http/services/datagateway/datagateway.go | 2 +- internal/http/services/owncloud/ocdav/tus.go | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 changelog/unreleased/fix-preflight-requests.md diff --git a/changelog/unreleased/fix-preflight-requests.md b/changelog/unreleased/fix-preflight-requests.md new file mode 100644 index 0000000000..42f7d01020 --- /dev/null +++ b/changelog/unreleased/fix-preflight-requests.md @@ -0,0 +1,5 @@ +Bugfix: fix preflight requests + +The datagateway now correctly overwrites the preconfigured CORS related headers with the headers returned by a dataprovider. + +https://github.com/cs3org/reva/pull/ diff --git a/internal/http/interceptors/cors/cors.go b/internal/http/interceptors/cors/cors.go index a4334b941b..cebd93f0f2 100644 --- a/internal/http/interceptors/cors/cors.go +++ b/internal/http/interceptors/cors/cors.go @@ -112,7 +112,7 @@ func New(m map[string]interface{}) (global.Middleware, int, error) { } // TODO(jfd): use log from request context, otherwise fmt will be used to log, - // preventing us from pinging the log to eg jq + // preventing us from piping the log to eg jq c := cors.New(cors.Options{ AllowCredentials: conf.AllowCredentials, AllowedHeaders: conf.AllowedHeaders, diff --git a/internal/http/services/datagateway/datagateway.go b/internal/http/services/datagateway/datagateway.go index 814e479db8..7235483f0e 100644 --- a/internal/http/services/datagateway/datagateway.go +++ b/internal/http/services/datagateway/datagateway.go @@ -393,7 +393,7 @@ func (s *svc) doPatch(w http.ResponseWriter, r *http.Request) { func copyHeader(dst, src http.Header) { for key, values := range src { for i := range values { - dst.Add(key, values[i]) + dst.Set(key, values[i]) } } } diff --git a/internal/http/services/owncloud/ocdav/tus.go b/internal/http/services/owncloud/ocdav/tus.go index 14a6cd2dea..780cb6b0d7 100644 --- a/internal/http/services/owncloud/ocdav/tus.go +++ b/internal/http/services/owncloud/ocdav/tus.go @@ -92,7 +92,7 @@ func (s *svc) handleSpacesTusPost(w http.ResponseWriter, r *http.Request, spaceI func (s *svc) handleTusPost(ctx context.Context, w http.ResponseWriter, r *http.Request, meta map[string]string, ref *provider.Reference, log zerolog.Logger) { w.Header().Add(net.HeaderAccessControlAllowHeaders, strings.Join([]string{net.HeaderTusResumable, net.HeaderUploadLength, net.HeaderUploadMetadata, net.HeaderIfMatch}, ", ")) - w.Header().Add(net.HeaderAccessControlExposeHeaders, strings.Join([]string{net.HeaderTusResumable, net.HeaderLocation}, ", ")) + w.Header().Add(net.HeaderAccessControlExposeHeaders, strings.Join([]string{net.HeaderTusResumable, net.HeaderUploadOffset, net.HeaderLocation}, ", ")) w.Header().Set(net.HeaderTusExtension, "creation,creation-with-upload,checksum,expiration") w.Header().Set(net.HeaderTusResumable, "1.0.0")