From 9311f12db3fb775ec47e2dd9adc6b2980b942060 Mon Sep 17 00:00:00 2001
From: Noam Gal <noam.gal@octopus.com>
Date: Wed, 11 Dec 2024 12:28:00 +0200
Subject: [PATCH] support PUT and DELETE

---
 common/docker-entrypoint.sh           | 8 ++++----
 common/etc/nginx/include/s3gateway.js | 7 -------
 2 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/common/docker-entrypoint.sh b/common/docker-entrypoint.sh
index 939c57b2..f2cea5e5 100644
--- a/common/docker-entrypoint.sh
+++ b/common/docker-entrypoint.sh
@@ -57,11 +57,11 @@ export CORS_ENABLED="$(parseBoolean "${CORS_ENABLED}")"
 # is not normally used as part of the gateway. The following variable
 # defines the set of acceptable headers.
 if [ "${CORS_ENABLED}" == "1" ]; then
-  export LIMIT_METHODS_TO="GET HEAD OPTIONS"
-  export LIMIT_METHODS_TO_CSV="GET, HEAD, OPTIONS"
+  export LIMIT_METHODS_TO="GET HEAD OPTIONS PUT DELETE"
+  export LIMIT_METHODS_TO_CSV="GET, HEAD, OPTIONS, PUT, DELETE"
 else
-  export LIMIT_METHODS_TO="GET HEAD"
-  export LIMIT_METHODS_TO_CSV="GET, HEAD"
+  export LIMIT_METHODS_TO="GET HEAD PUT DELETE"
+  export LIMIT_METHODS_TO_CSV="GET, HEAD, PUT, DELETE"
 fi
 
 if [ -z "${CORS_ALLOWED_ORIGIN+x}" ]; then
diff --git a/common/etc/nginx/include/s3gateway.js b/common/etc/nginx/include/s3gateway.js
index de58b404..2a226a36 100644
--- a/common/etc/nginx/include/s3gateway.js
+++ b/common/etc/nginx/include/s3gateway.js
@@ -366,13 +366,6 @@ function _s3DirQueryParams(uriPath, method) {
  * @param r {NginxHTTPRequest} HTTP request object
  */
 function redirectToS3(r) {
-    // This is a read-only S3 gateway, so we do not support any other methods
-    if (!(r.method === 'GET' || r.method === 'HEAD')) {
-        utils.debug_log(r, 'Invalid method requested: ' + r.method);
-        r.internalRedirect("@error405");
-        return;
-    }
-
     const uriPath = r.variables.uri_path;
     const isDirectoryListing = ALLOW_LISTING && _isDirectory(uriPath);