mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2024-12-23 03:51:09 +00:00
07d909ff32
This change makes it possible to run geth with JSON-RPC over HTTP and WebSocket on the same TCP port. The default port for WebSocket is still 8546. geth --rpc --rpcport 8545 --ws --wsport 8545 This also removes a lot of deprecated API surface from package rpc. The rpc package is now purely about serving JSON-RPC and no longer provides a way to start an HTTP server.
39 lines
977 B
Go
39 lines
977 B
Go
package node
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNewWebsocketUpgradeHandler_websocket(t *testing.T) {
|
|
srv := rpc.NewServer()
|
|
|
|
handler := NewWebsocketUpgradeHandler(nil, srv.WebsocketHandler([]string{}))
|
|
ts := httptest.NewServer(handler)
|
|
defer ts.Close()
|
|
|
|
responses := make(chan *http.Response)
|
|
go func(responses chan *http.Response) {
|
|
client := &http.Client{}
|
|
|
|
req, _ := http.NewRequest(http.MethodGet, ts.URL, nil)
|
|
req.Header.Set("Connection", "upgrade")
|
|
req.Header.Set("Upgrade", "websocket")
|
|
req.Header.Set("Sec-WebSocket-Version", "13")
|
|
req.Header.Set("Sec-Websocket-Key", "SGVsbG8sIHdvcmxkIQ==")
|
|
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
t.Error("could not issue a GET request to the test http server", err)
|
|
}
|
|
responses <- resp
|
|
}(responses)
|
|
|
|
response := <-responses
|
|
assert.Equal(t, "websocket", response.Header.Get("Upgrade"))
|
|
}
|