@@ -58,7 +58,7 @@ import (
58
58
"github.com/ethereum/go-ethereum/p2p/enode"
59
59
"github.com/ethereum/go-ethereum/p2p/nat"
60
60
"github.com/ethereum/go-ethereum/params"
61
- "golang.org/x/net /websocket"
61
+ "github.com/gorilla /websocket"
62
62
)
63
63
64
64
var (
@@ -296,8 +296,7 @@ func (f *faucet) listenAndServe(port int) error {
296
296
go f .loop ()
297
297
298
298
http .HandleFunc ("/" , f .webHandler )
299
- http .Handle ("/api" , websocket .Handler (f .apiHandler ))
300
-
299
+ http .HandleFunc ("/api" , f .apiHandler )
301
300
return http .ListenAndServe (fmt .Sprintf (":%d" , port ), nil )
302
301
}
303
302
@@ -308,7 +307,13 @@ func (f *faucet) webHandler(w http.ResponseWriter, r *http.Request) {
308
307
}
309
308
310
309
// 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
+
312
317
// Start tracking the connection and drop at the end
313
318
defer conn .Close ()
314
319
@@ -331,7 +336,6 @@ func (f *faucet) apiHandler(conn *websocket.Conn) {
331
336
head * types.Header
332
337
balance * big.Int
333
338
nonce uint64
334
- err error
335
339
)
336
340
for head == nil || balance == nil {
337
341
// Retrieve the current stats cached by the faucet
@@ -376,7 +380,7 @@ func (f *faucet) apiHandler(conn *websocket.Conn) {
376
380
Tier uint `json:"tier"`
377
381
Captcha string `json:"captcha"`
378
382
}
379
- if err = websocket . JSON . Receive ( conn , & msg ); err != nil {
383
+ if err = conn . ReadJSON ( & msg ); err != nil {
380
384
return
381
385
}
382
386
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
657
661
timeout = 60 * time .Second
658
662
}
659
663
conn .SetWriteDeadline (time .Now ().Add (timeout ))
660
- return websocket . JSON . Send ( conn , value )
664
+ return conn . WriteJSON ( value )
661
665
}
662
666
663
667
// sendError transmits an error to the remote end of the websocket, also setting
0 commit comments