aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorbas-vk <bas-vk@users.noreply.github.com>2017-04-13 05:04:14 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-04-13 05:04:14 +0800
commit5e29f4be935ff227bbf07a0c6e80e8809f5e0202 (patch)
tree18e1ef8db3c66c3bf777dc90326aa971f1343d34 /rpc
parent43671067fb453a1ed798bcc3d8016710460f2bdf (diff)
downloadgo-tangerine-5e29f4be935ff227bbf07a0c6e80e8809f5e0202.tar
go-tangerine-5e29f4be935ff227bbf07a0c6e80e8809f5e0202.tar.gz
go-tangerine-5e29f4be935ff227bbf07a0c6e80e8809f5e0202.tar.bz2
go-tangerine-5e29f4be935ff227bbf07a0c6e80e8809f5e0202.tar.lz
go-tangerine-5e29f4be935ff227bbf07a0c6e80e8809f5e0202.tar.xz
go-tangerine-5e29f4be935ff227bbf07a0c6e80e8809f5e0202.tar.zst
go-tangerine-5e29f4be935ff227bbf07a0c6e80e8809f5e0202.zip
cmd/utils, node: remove unused solc references and improve RPC config (#14324)
Currently http cors and websocket origins are a comma separated string in the config object. These are replaced with string arrays that are more expressive in case of a config file.
Diffstat (limited to 'rpc')
-rw-r--r--rpc/client_test.go4
-rw-r--r--rpc/http.go11
-rw-r--r--rpc/websocket.go6
3 files changed, 8 insertions, 13 deletions
diff --git a/rpc/client_test.go b/rpc/client_test.go
index 41471dcea..10d74670b 100644
--- a/rpc/client_test.go
+++ b/rpc/client_test.go
@@ -394,7 +394,7 @@ func TestClientReconnect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- go http.Serve(l, srv.WebsocketHandler("*"))
+ go http.Serve(l, srv.WebsocketHandler([]string{"*"}))
return srv, l
}
@@ -466,7 +466,7 @@ func httpTestClient(srv *Server, transport string, fl *flakeyListener) (*Client,
var hs *httptest.Server
switch transport {
case "ws":
- hs = httptest.NewUnstartedServer(srv.WebsocketHandler("*"))
+ hs = httptest.NewUnstartedServer(srv.WebsocketHandler([]string{"*"}))
case "http":
hs = httptest.NewUnstartedServer(srv)
default:
diff --git a/rpc/http.go b/rpc/http.go
index 89175b149..022f9ce8f 100644
--- a/rpc/http.go
+++ b/rpc/http.go
@@ -25,7 +25,6 @@ import (
"io/ioutil"
"net"
"net/http"
- "strings"
"sync"
"time"
@@ -140,8 +139,8 @@ func (t *httpReadWriteNopCloser) Close() error {
// NewHTTPServer creates a new HTTP RPC server around an API provider.
//
// Deprecated: Server implements http.Handler
-func NewHTTPServer(corsString string, srv *Server) *http.Server {
- return &http.Server{Handler: newCorsHandler(srv, corsString)}
+func NewHTTPServer(cors []string, srv *Server) *http.Server {
+ return &http.Server{Handler: newCorsHandler(srv, cors)}
}
// ServeHTTP serves JSON-RPC requests over HTTP.
@@ -162,11 +161,7 @@ func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
srv.ServeSingleRequest(codec, OptionMethodInvocation)
}
-func newCorsHandler(srv *Server, corsString string) http.Handler {
- var allowedOrigins []string
- for _, domain := range strings.Split(corsString, ",") {
- allowedOrigins = append(allowedOrigins, strings.TrimSpace(domain))
- }
+func newCorsHandler(srv *Server, allowedOrigins []string) http.Handler {
c := cors.New(cors.Options{
AllowedOrigins: allowedOrigins,
AllowedMethods: []string{"POST", "GET"},
diff --git a/rpc/websocket.go b/rpc/websocket.go
index 587010820..5f9593a43 100644
--- a/rpc/websocket.go
+++ b/rpc/websocket.go
@@ -36,9 +36,9 @@ import (
//
// allowedOrigins should be a comma-separated list of allowed origin URLs.
// To allow connections with any origin, pass "*".
-func (srv *Server) WebsocketHandler(allowedOrigins string) http.Handler {
+func (srv *Server) WebsocketHandler(allowedOrigins []string) http.Handler {
return websocket.Server{
- Handshake: wsHandshakeValidator(strings.Split(allowedOrigins, ",")),
+ Handshake: wsHandshakeValidator(allowedOrigins),
Handler: func(conn *websocket.Conn) {
srv.ServeCodec(NewJSONCodec(conn), OptionMethodInvocation|OptionSubscriptions)
},
@@ -48,7 +48,7 @@ func (srv *Server) WebsocketHandler(allowedOrigins string) http.Handler {
// NewWSServer creates a new websocket RPC server around an API provider.
//
// Deprecated: use Server.WebsocketHandler
-func NewWSServer(allowedOrigins string, srv *Server) *http.Server {
+func NewWSServer(allowedOrigins []string, srv *Server) *http.Server {
return &http.Server{Handler: srv.WebsocketHandler(allowedOrigins)}
}