diff --git a/constants_unix.go b/constants_unix.go deleted file mode 100644 index 741ed0f888ea65e19e141c125e43fee57159609e..0000000000000000000000000000000000000000 --- a/constants_unix.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2019 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - -//go:build darwin || dragonfly || freebsd || linux || nacl || netbsd || openbsd || solaris -// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris - -package jrpc - -/* -#include <sys/un.h> - -int max_socket_path_size() { -struct sockaddr_un s; -return sizeof(s.sun_path); -} -*/ -//import "C" -// -//var ( -// max_path_size = C.max_socket_path_size() -//) - -// cgo is illegal here diff --git a/constants_unix_nocgo.go b/constants_unix_nocgo.go deleted file mode 100644 index c5d5fd0af485ab3a546b532696c22532f48d1623..0000000000000000000000000000000000000000 --- a/constants_unix_nocgo.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2019 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - -//go:build !cgo && !windows -// +build !cgo,!windows - -package jrpc - -var ( - // On Linux, sun_path is 108 bytes in size - // see http://man7.org/linux/man-pages/man7/unix.7.html - max_path_size = 108 -) diff --git a/http.go b/http.go index 212c893de9a938230f791568149b461b4ce887f4..359e643faa502c6504e280c8349fd98b56d2fce2 100644 --- a/http.go +++ b/http.go @@ -25,7 +25,6 @@ import ( "mime" "net/http" "net/url" - "strings" "time" "gfx.cafe/util/go/bufpool" @@ -153,36 +152,6 @@ func (t *httpServerConn) RemoteAddr() string { // SetWriteDeadline does nothing and always returns nil. func (t *httpServerConn) SetWriteDeadline(time.Time) error { return nil } -type WebsocketServer struct { - s *Server -} - -func (s *WebsocketServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if isWebsocket(r) { - s.s.WebsocketHandler([]string{"*"}).ServeHTTP(w, r) - return - } - s.s.ServeHTTP(w, r) -} - -func isWebsocket(r *http.Request) bool { - return strings.EqualFold(r.Header.Get("Upgrade"), "websocket") && - strings.Contains(strings.ToLower(r.Header.Get("Connection")), "upgrade") -} - -func (s *Server) ServeHTTPWithWss(cb func(r *http.Request)) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if isWebsocket(r) { - if cb != nil { - cb(r) - } - s.WebsocketHandler([]string{"*"}).ServeHTTP(w, r) - return - } - s.ServeHTTP(w, r) - }) -} - // ServeHTTP serves JSON-RPC requests over HTTP. func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Permit dumb empty requests for remote health-checks (AWS) diff --git a/websocket_server.go b/websocket_server.go new file mode 100644 index 0000000000000000000000000000000000000000..9345c7e61d76cc4dcc37889d5d68b15ca2395b4f --- /dev/null +++ b/websocket_server.go @@ -0,0 +1,36 @@ +package jrpc + +import ( + "net/http" + "strings" +) + +type WebsocketServer struct { + s *Server +} + +func (s *WebsocketServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { + if isWebsocket(r) { + s.s.WebsocketHandler([]string{"*"}).ServeHTTP(w, r) + return + } + s.s.ServeHTTP(w, r) +} + +func isWebsocket(r *http.Request) bool { + return strings.EqualFold(r.Header.Get("Upgrade"), "websocket") && + strings.Contains(strings.ToLower(r.Header.Get("Connection")), "upgrade") +} + +func (s *Server) ServeHTTPWithWss(cb func(r *http.Request)) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if isWebsocket(r) { + if cb != nil { + cb(r) + } + s.WebsocketHandler([]string{"*"}).ServeHTTP(w, r) + return + } + s.ServeHTTP(w, r) + }) +}