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
This commit is contained in:
Andrew
2019-05-08 13:22:13 +10:00
committed by Adrian Gallagher
parent 35b94268e0
commit 8be0682bca
2 changed files with 9 additions and 4 deletions

View File

@@ -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 {

View File

@@ -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)