Skip to content

Commit

Permalink
RPC server host/port fix (thrasher-corp#292)
Browse files Browse the repository at this point in the history
* Fix to conform with standards on Host header needing a port if its not on port 80

* Fix test to use correct address
xtda authored and thrasher- committed May 8, 2019
1 parent 35b9426 commit 8be0682
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 8 additions & 2 deletions restful_router.go
Original file line number Diff line number Diff line change
@@ -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 {
3 changes: 1 addition & 2 deletions restful_server_test.go
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 8be0682

Please sign in to comment.