From cab963f21c09cfd1470efc075c7fa9aeb3fa6625 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Tue, 3 Aug 2021 19:23:20 +0000 Subject: [PATCH] Fix status code for options requests (#1290) --- router/middleware/auth.go | 6 +++--- test/automated/integrations.test.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/router/middleware/auth.go b/router/middleware/auth.go index 04ecbf7c9..adabc93c7 100644 --- a/router/middleware/auth.go +++ b/router/middleware/auth.go @@ -28,9 +28,9 @@ func RequireAdminAuth(handler http.HandlerFunc) http.HandlerFunc { w.Header().Set("Access-Control-Allow-Credentials", "true") w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization") - // For request needing CORS, send a 200. + // For request needing CORS, send a 204. if r.Method == "OPTIONS" { - w.WriteHeader(http.StatusOK) + w.WriteHeader(http.StatusNoContent) return } @@ -60,7 +60,7 @@ func RequireExternalAPIAccessToken(scope string, handler ExternalAccessTokenHand if r.Method == "OPTIONS" { // All OPTIONS requests should have a wildcard CORS header. w.Header().Set("Access-Control-Allow-Origin", "*") - w.WriteHeader(http.StatusOK) + w.WriteHeader(http.StatusNoContent) return } diff --git a/test/automated/integrations.test.js b/test/automated/integrations.test.js index 901b72cae..e3357e56d 100644 --- a/test/automated/integrations.test.js +++ b/test/automated/integrations.test.js @@ -142,7 +142,7 @@ test('test fetch chat history OPTIONS request', async (done) => { const res = await request .options('/api/integrations/chat') .set('Authorization', 'Bearer ' + accessToken) - .expect(200); + .expect(204); done(); });