From 7e37cfb996421420f4e82a06323effbb71db641f Mon Sep 17 00:00:00 2001 From: Yann Stepienik Date: Sat, 6 May 2023 19:32:49 +0100 Subject: [PATCH] [release] v0.4.0-unstable4 --- package.json | 2 +- src/utils/middleware.go | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index cb2d4a4..b905825 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cosmos-server", - "version": "0.4.0-unstable3", + "version": "0.4.0-unstable4", "description": "", "main": "test-server.js", "bugs": { diff --git a/src/utils/middleware.go b/src/utils/middleware.go index ecaa143..eab5626 100644 --- a/src/utils/middleware.go +++ b/src/utils/middleware.go @@ -5,6 +5,7 @@ import ( "net/http" "time" "net" + "fmt" "github.com/mxk/go-flowrate/flowrate" "github.com/oschwald/geoip2-golang" @@ -188,15 +189,20 @@ func EnsureHostname(next http.Handler) http.Handler { hostnames := GetAllHostnames() + isOk := false for _, hostname := range hostnames { - if r.Host != hostname + port { - Error("Invalid Hostname " + r.Host + "for request. Expecting " + hostname, nil) - w.WriteHeader(http.StatusBadRequest) - http.Error(w, "Bad Request: Invalid hostname.", http.StatusBadRequest) - return + if r.Host == hostname + port { + isOk = true } } + if !isOk { + Error("Invalid Hostname " + r.Host + " for request. Expecting one of " + fmt.Sprintf("%v", hostnames), nil) + w.WriteHeader(http.StatusBadRequest) + http.Error(w, "Bad Request: Invalid hostname.", http.StatusBadRequest) + return + } + next.ServeHTTP(w, r) }) } \ No newline at end of file