diff --git a/README.md b/README.md index 659836eb2359465496a6348dd0e943847636163d..0bbed128b8b0946e76d881ff74591075b555c041 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,10 @@ A very simple container to redirect HTTP traffic to another server, based on `ng - useful if client should not change the request method from POST to GET - if not set or not in allowed Codes `SERVER_REDIRECT_CODE` is used - so per default all requests will be redirected with the same status code + - `SERVER_REDIRECT_PUT_PATCH_DELETE_CODE` - optionally define the http code to use for PUT, PATCH and DELETE redirection + - useful if client should not change the request method from PUT, PATCH and DELETE to GET + - if not set or not in allowed Codes `SERVER_REDIRECT_CODE` is used + - so per default all requests will be redirected with the same status code - `SERVER_ACCESS_LOG` - optionally define the location where nginx will write its access log - if not set /dev/stdout is used - `SERVER_ERROR_LOG` - optionally define the location where nginx will write its error log diff --git a/default.conf b/default.conf index 8ac9d3ca9a6bdb0eaae3680376b9e498c02ff689..3e15cbbda8165bb33374fd62a1d707d124293275 100644 --- a/default.conf +++ b/default.conf @@ -12,6 +12,10 @@ server { return ${SERVER_REDIRECT_POST_CODE} ${SERVER_REDIRECT_SCHEME}://${SERVER_REDIRECT}${SERVER_REDIRECT_PATH}; } + if ($request_method ~ PUT|PATCH|DELETE) { + return ${SERVER_REDIRECT_PUT_PATCH_DELETE_CODE} ${SERVER_REDIRECT_SCHEME}://${SERVER_REDIRECT}${SERVER_REDIRECT_PATH}; + } + return ${SERVER_REDIRECT_CODE} ${SERVER_REDIRECT_SCHEME}://${SERVER_REDIRECT}${SERVER_REDIRECT_PATH}; # redirect server error pages to the static page /50x.html diff --git a/docker-compose.yml b/docker-compose.yml index 9ccc112923842a05343376ceec1858706c0f85c8..462f290fe1ab119f7e59eaabdb38472c3da3479b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,6 +17,9 @@ to: # optionally define the http code to redirect POST requests # if not set or not in allowed Codes, SERVER_REDIRECT_CODE will be used #- SERVER_REDIRECT_POST_CODE= + # optionally define the http code to redirect PUT, PATCH and DELETE requests + # if not set or not in allowed Codes, SERVER_REDIRECT_CODE will be used + #- SERVER_REDIRECT_PUT_PATCH_DELETE_CODE= # optionally define the location for the nginx access log # if not set /dev/stdout is used #- SERVER_ACCESS_LOG=/dev/null diff --git a/run.sh b/run.sh index 844316c588be821afe00729714111ac8f2392bbf..ada7209d9cb98ac3f7a96acee3d58b51e90c2900 100644 --- a/run.sh +++ b/run.sh @@ -17,6 +17,9 @@ expr match "$SERVER_REDIRECT_CODE" '30[12378]$' > /dev/null || SERVER_REDIRECT_C # set redirect code from optional ENV var for POST requests expr match "$SERVER_REDIRECT_POST_CODE" '30[12378]$' > /dev/null || SERVER_REDIRECT_POST_CODE=$SERVER_REDIRECT_CODE +# set redirect code from optional ENV var for PUT, PATCH and DELETE requests +expr match "$SERVER_REDIRECT_PUT_PATCH_DELETE_CODE" '30[12378]$' > /dev/null || SERVER_REDIRECT_PUT_PATCH_DELETE_CODE=$SERVER_REDIRECT_CODE + # set redirect path from optional ENV var if [ ! -n "$SERVER_REDIRECT_PATH" ] ; then SERVER_REDIRECT_PATH='$request_uri' @@ -41,6 +44,7 @@ sed -i "s|\${SERVER_REDIRECT}|${SERVER_REDIRECT}|" /etc/nginx/conf.d/default.con sed -i "s|\${SERVER_NAME}|${SERVER_NAME}|" /etc/nginx/conf.d/default.conf sed -i "s|\${SERVER_REDIRECT_CODE}|${SERVER_REDIRECT_CODE}|" /etc/nginx/conf.d/default.conf sed -i "s|\${SERVER_REDIRECT_POST_CODE}|${SERVER_REDIRECT_POST_CODE}|" /etc/nginx/conf.d/default.conf +sed -i "s|\${SERVER_REDIRECT_PUT_PATCH_DELETE_CODE}|${SERVER_REDIRECT_PUT_PATCH_DELETE_CODE}|" /etc/nginx/conf.d/default.conf sed -i "s|\${SERVER_REDIRECT_PATH}|${SERVER_REDIRECT_PATH}|" /etc/nginx/conf.d/default.conf sed -i "s|\${SERVER_REDIRECT_SCHEME}|${SERVER_REDIRECT_SCHEME}|" /etc/nginx/conf.d/default.conf