@@ -58,7 +58,7 @@ import (
5858 "github.com/ethereum/go-ethereum/p2p/enode"
5959 "github.com/ethereum/go-ethereum/p2p/nat"
6060 "github.com/ethereum/go-ethereum/params"
61- "golang.org/x/net /websocket"
61+ "github.com/gorilla /websocket"
6262)
6363
6464var (
@@ -296,8 +296,7 @@ func (f *faucet) listenAndServe(port int) error {
296296 go f .loop ()
297297
298298 http .HandleFunc ("/" , f .webHandler )
299- http .Handle ("/api" , websocket .Handler (f .apiHandler ))
300-
299+ http .HandleFunc ("/api" , f .apiHandler )
301300 return http .ListenAndServe (fmt .Sprintf (":%d" , port ), nil )
302301}
303302
@@ -308,7 +307,13 @@ func (f *faucet) webHandler(w http.ResponseWriter, r *http.Request) {
308307}
309308
310309// apiHandler handles requests for Ether grants and transaction statuses.
311- func (f * faucet ) apiHandler (conn * websocket.Conn ) {
310+ func (f * faucet ) apiHandler (w http.ResponseWriter , r * http.Request ) {
311+ upgrader := websocket.Upgrader {}
312+ conn , err := upgrader .Upgrade (w , r , nil )
313+ if err != nil {
314+ return
315+ }
316+
312317 // Start tracking the connection and drop at the end
313318 defer conn .Close ()
314319
@@ -331,7 +336,6 @@ func (f *faucet) apiHandler(conn *websocket.Conn) {
331336 head * types.Header
332337 balance * big.Int
333338 nonce uint64
334- err error
335339 )
336340 for head == nil || balance == nil {
337341 // Retrieve the current stats cached by the faucet
@@ -376,7 +380,7 @@ func (f *faucet) apiHandler(conn *websocket.Conn) {
376380 Tier uint `json:"tier"`
377381 Captcha string `json:"captcha"`
378382 }
379- if err = websocket . JSON . Receive ( conn , & msg ); err != nil {
383+ if err = conn . ReadJSON ( & msg ); err != nil {
380384 return
381385 }
382386 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
657661 timeout = 60 * time .Second
658662 }
659663 conn .SetWriteDeadline (time .Now ().Add (timeout ))
660- return websocket . JSON . Send ( conn , value )
664+ return conn . WriteJSON ( value )
661665}
662666
663667// sendError transmits an error to the remote end of the websocket, also setting
0 commit comments