From 8be0682bcaadb539616fcb5812b69747f50f3744 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 8 May 2019 13:22:13 +1000 Subject: [PATCH] RPC server host/port fix (#292) * Fix to conform with standards on Host header needing a port if its not on port 80 * Fix test to use correct address --- restful_router.go | 10 ++++++++-- restful_server_test.go | 3 +-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/restful_router.go b/restful_router.go index cbb1f00a..9d33ed81 100644 --- a/restful_router.go +++ b/restful_router.go @@ -46,7 +46,13 @@ var routes = Routes{} // router func NewRouter() *mux.Router { router := mux.NewRouter().StrictSlash(true) - listenAddr := bot.config.Webserver.ListenAddress + var listenAddr string + + if common.ExtractPort(bot.config.Webserver.ListenAddress) == 80 { + listenAddr = common.ExtractHost(bot.config.Webserver.ListenAddress) + } else { + listenAddr = bot.config.Webserver.ListenAddress + } routes = Routes{ Route{ @@ -117,7 +123,7 @@ func NewRouter() *mux.Router { Path(route.Pattern). Name(route.Name). Handler(RESTLogger(route.HandlerFunc, route.Name)). - Host(common.ExtractHost(listenAddr)) + Host(listenAddr) } if bot.config.Profiler.Enabled { diff --git a/restful_server_test.go b/restful_server_test.go index 88a450c4..b3d7fc69 100644 --- a/restful_server_test.go +++ b/restful_server_test.go @@ -9,7 +9,6 @@ import ( "strings" "testing" - "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" ) @@ -73,7 +72,7 @@ func TestValidHostRequest(t *testing.T) { if err != nil { t.Fatal(err) } - req.Host = common.ExtractHost(bot.config.Webserver.ListenAddress) + req.Host = bot.config.Webserver.ListenAddress resp := httptest.NewRecorder() NewRouter().ServeHTTP(resp, req)