RPC Server Host valdiation fix for #296 (#302)

* listenAddress updated to correctly set if RPC listens on any interface

* Update restful_router.go
This commit is contained in:
Andrew
2019-05-17 11:45:22 +10:00
committed by Adrian Gallagher
parent 46267e5975
commit 05a7ae70ba
2 changed files with 4 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"fmt"
"net/http"
"strconv"
"time"
"github.com/gorilla/mux"
@@ -51,7 +52,8 @@ func NewRouter() *mux.Router {
if common.ExtractPort(bot.config.Webserver.ListenAddress) == 80 {
listenAddr = common.ExtractHost(bot.config.Webserver.ListenAddress)
} else {
listenAddr = bot.config.Webserver.ListenAddress
listenAddr = common.JoinStrings([]string{common.ExtractHost(bot.config.Webserver.ListenAddress),
strconv.Itoa(common.ExtractPort(bot.config.Webserver.ListenAddress))}, ":")
}
routes = Routes{
@@ -136,5 +138,4 @@ func NewRouter() *mux.Router {
func getIndex(w http.ResponseWriter, _ *http.Request) {
fmt.Fprint(w, "<html>GoCryptoTrader RESTful interface. For the web GUI, please visit the <a href=https://github.com/thrasher-/gocryptotrader/blob/master/web/README.md>web GUI readme.</a></html>")
w.WriteHeader(http.StatusOK)
}

View File

@@ -72,7 +72,7 @@ func TestValidHostRequest(t *testing.T) {
if err != nil {
t.Fatal(err)
}
req.Host = bot.config.Webserver.ListenAddress
req.Host = "localhost:9050"
resp := httptest.NewRecorder()
NewRouter().ServeHTTP(resp, req)