diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index 905eeb24a..3700ff9c5 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -58,7 +58,7 @@ import ( "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/nat" "github.com/ethereum/go-ethereum/params" - "golang.org/x/net/websocket" + "github.com/gorilla/websocket" ) var ( @@ -296,8 +296,7 @@ func (f *faucet) listenAndServe(port int) error { go f.loop() http.HandleFunc("/", f.webHandler) - http.Handle("/api", websocket.Handler(f.apiHandler)) - + http.HandleFunc("/api", f.apiHandler) return http.ListenAndServe(fmt.Sprintf(":%d", port), nil) } @@ -308,7 +307,13 @@ func (f *faucet) webHandler(w http.ResponseWriter, r *http.Request) { } // apiHandler handles requests for Ether grants and transaction statuses. -func (f *faucet) apiHandler(conn *websocket.Conn) { +func (f *faucet) apiHandler(w http.ResponseWriter, r *http.Request) { + upgrader := websocket.Upgrader{} + conn, err := upgrader.Upgrade(w, r, nil) + if err != nil { + return + } + // Start tracking the connection and drop at the end defer conn.Close() @@ -331,7 +336,6 @@ func (f *faucet) apiHandler(conn *websocket.Conn) { head *types.Header balance *big.Int nonce uint64 - err error ) for head == nil || balance == nil { // Retrieve the current stats cached by the faucet @@ -376,7 +380,7 @@ func (f *faucet) apiHandler(conn *websocket.Conn) { Tier uint `json:"tier"` Captcha string `json:"captcha"` } - if err = websocket.JSON.Receive(conn, &msg); err != nil { + if err = conn.ReadJSON(&msg); err != nil { return } if !*noauthFlag && !strings.HasPrefix(msg.URL, "https://gist.github.com/") && !strings.HasPrefix(msg.URL, "https://twitter.com/") && @@ -657,7 +661,7 @@ func send(conn *websocket.Conn, value interface{}, timeout time.Duration) error timeout = 60 * time.Second } conn.SetWriteDeadline(time.Now().Add(timeout)) - return websocket.JSON.Send(conn, value) + return conn.WriteJSON(value) } // sendError transmits an error to the remote end of the websocket, also setting