From 1f0eef5950186a373aae2b0a4f446201edc3611a Mon Sep 17 00:00:00 2001 From: Jens Giessmann <j.giessmann@herzogkommunikation.de> Date: Wed, 11 Apr 2018 09:24:02 +0200 Subject: [PATCH] allow 301, 302, 303, 307 or 308 as HTTP Status Codes used for redirect --- README.md | 5 +++-- docker-compose.yml | 3 +++ run.sh | 5 ++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 198c292..8820d33 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,9 @@ A very simple container to redirect HTTP traffic to another server, based on `ng if not set nginx var `$request_uri` is used - `SERVER_REDIRECT_SCHEME` - optionally define scheme to redirect to if not set nginx var `$scheme` is used -- `SERVER_REDIRECT_CODE` - optionally define the http code to use for redirection - if not set nginx 301 - is used +- `SERVER_REDIRECT_CODE` - optionally define the http status code to use for redirection + - if not set or not in list of allowed codes 301 is used as default + - allowed Codes are: 301, 302, 303, 307, 308 See also `docker-compose.yml` file. diff --git a/docker-compose.yml b/docker-compose.yml index 7f5304b..31f0501 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,3 +10,6 @@ to: # optionally define schema to redirect all requests # if not set nginx var $scheme is used #- SERVER_REDIRECT_SCHEME=https + # optionally define the http code to use for redirection + # allowed Codes are: 301, 302, 303, 307, 308, default is 301 + #- SERVER_REDIRECT_CODE=302 diff --git a/run.sh b/run.sh index d06824b..a366e5e 100644 --- a/run.sh +++ b/run.sh @@ -11,9 +11,8 @@ if [ ! -n "$SERVER_NAME" ] ; then fi # set redirect code from optional ENV var -if [ "$SERVER_REDIRECT_CODE" != '302' ] ; then - SERVER_REDIRECT_CODE='301' -fi +# allowed Status Codes are: 301, 302, 303, 307, 308 +expr match "$SERVER_REDIRECT_CODE" '30[12378]$' > /dev/null || SERVER_REDIRECT_CODE='301' # set redirect path from optional ENV var if [ ! -n "$SERVER_REDIRECT_PATH" ] ; then -- GitLab