From 2687e164d8f3381af4519b0c407c11d0c7dc2b0b Mon Sep 17 00:00:00 2001 From: henrylee2cn Date: Thu, 14 Nov 2019 21:25:31 +0800 Subject: [PATCH] fix: package ident Change-Id: I944469daa9fd259b64112eaf669a8a382c0051cf --- examples/bench/client.go | 2 +- examples/bench/server.go | 2 +- mixer/evio/bench/tp_client.go | 2 +- mixer/evio/bench/tp_evio_server.go | 2 +- mixer/evio/evio/README.md | 2 +- .../github.com/kavu/go_reuseport/README.md | 4 +-- .../github.com/kavu/go_reuseport/tcp_test.go | 14 ++++---- mixer/websocket/README.md | 4 +-- mixer/websocket/server.go | 26 +++++++------- mixer/websocket/websocket/client.go | 2 +- mixer/websocket/websocket/hybi.go | 26 +++++++------- mixer/websocket/websocket/hybi_test.go | 34 +++++++++---------- mixer/websocket/websocket/server.go | 30 ++++++++-------- mixer/websocket/websocket/websocket.go | 18 +++++----- mixer/websocket/websocket/websocket_test.go | 24 ++++++------- mixer/websocket/websocket_test.go | 4 +-- proto/httproto/README.md | 2 +- proto/httproto/httproto.go | 6 ++-- proto/httproto/httproto_test.go | 4 +-- 19 files changed, 104 insertions(+), 104 deletions(-) diff --git a/examples/bench/client.go b/examples/bench/client.go index c45cf320..ceb51b88 100644 --- a/examples/bench/client.go +++ b/examples/bench/client.go @@ -28,7 +28,7 @@ func main() { erpc.SetGopool(1024*1024*100, time.Minute*10) go func() { - log.Println(hterpc.ListenAndServe(*debugAddr, nil)) + log.Println(http.ListenAndServe(*debugAddr, nil)) }() conc, tn, err := msg.CheckArgs(*concurrency, *total) diff --git a/examples/bench/server.go b/examples/bench/server.go index 0ef03c48..384eb868 100644 --- a/examples/bench/server.go +++ b/examples/bench/server.go @@ -44,7 +44,7 @@ func main() { erpc.SetGopool(1024*1024*100, time.Minute*10) go func() { - log.Println(hterpc.ListenAndServe(*debugAddr, nil)) + log.Println(http.ListenAndServe(*debugAddr, nil)) }() erpc.SetServiceMethodMapper(erpc.RPCServiceMethodMapper) diff --git a/mixer/evio/bench/tp_client.go b/mixer/evio/bench/tp_client.go index c45cf320..ceb51b88 100644 --- a/mixer/evio/bench/tp_client.go +++ b/mixer/evio/bench/tp_client.go @@ -28,7 +28,7 @@ func main() { erpc.SetGopool(1024*1024*100, time.Minute*10) go func() { - log.Println(hterpc.ListenAndServe(*debugAddr, nil)) + log.Println(http.ListenAndServe(*debugAddr, nil)) }() conc, tn, err := msg.CheckArgs(*concurrency, *total) diff --git a/mixer/evio/bench/tp_evio_server.go b/mixer/evio/bench/tp_evio_server.go index ba0a98b2..91fef811 100644 --- a/mixer/evio/bench/tp_evio_server.go +++ b/mixer/evio/bench/tp_evio_server.go @@ -45,7 +45,7 @@ func main() { erpc.SetGopool(1024*1024*100, time.Minute*10) go func() { - log.Println(hterpc.ListenAndServe(*debugAddr, nil)) + log.Println(http.ListenAndServe(*debugAddr, nil)) }() erpc.SetServiceMethodMapper(erpc.RPCServiceMethodMapper) diff --git a/mixer/evio/evio/README.md b/mixer/evio/evio/README.md index 807d0a00..bc5f9678 100644 --- a/mixer/evio/evio/README.md +++ b/mixer/evio/evio/README.md @@ -155,7 +155,7 @@ $ go run examples/echo-server/main.go These benchmarks were run on an ec2 c4.xlarge instance in single-threaded mode (GOMAXPROC=1) over Ipv4 localhost. Check out [benchmarks](benchmarks) for more info. -echo benchmarkhttp benchmarkredis 1 benchmarkredis 8 benchmark +echo benchmarkhttp benchmarkredis 1 benchmarkredis 8 benchmark ## Contact diff --git a/mixer/evio/evio/vendor/github.com/kavu/go_reuseport/README.md b/mixer/evio/evio/vendor/github.com/kavu/go_reuseport/README.md index 5c18faff..9e9726b6 100644 --- a/mixer/evio/evio/vendor/github.com/kavu/go_reuseport/README.md +++ b/mixer/evio/evio/vendor/github.com/kavu/go_reuseport/README.md @@ -30,8 +30,8 @@ func main() { } defer listener.Close() - server := &hterpc.Server{} - hterpc.HandleFunc("/", func(w hterpc.ResponseWriter, r *hterpc.Request) { + server := &http.Server{} + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Println(os.Getgid()) fmt.Fprintf(w, "Hello, %q\n", html.EscapeString(r.URL.Path)) }) diff --git a/mixer/evio/evio/vendor/github.com/kavu/go_reuseport/tcp_test.go b/mixer/evio/evio/vendor/github.com/kavu/go_reuseport/tcp_test.go index a6c9f773..1620f9d3 100644 --- a/mixer/evio/evio/vendor/github.com/kavu/go_reuseport/tcp_test.go +++ b/mixer/evio/evio/vendor/github.com/kavu/go_reuseport/tcp_test.go @@ -29,7 +29,7 @@ var ( ) func NewHTTPServer(resp string) *httptest.Server { - return httptest.NewUnstartedServer(hterpc.HandlerFunc(func(w hterpc.ResponseWriter, r *hterpc.Request) { + return httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, resp) })) } @@ -129,7 +129,7 @@ func TestNewReusablePortServers(t *testing.T) { httpServerTwo.Start() // Server One — First Response - resp1, err := hterpc.Get(httpServerOne.URL) + resp1, err := http.Get(httpServerOne.URL) if err != nil { t.Error(err) } @@ -143,7 +143,7 @@ func TestNewReusablePortServers(t *testing.T) { } // Server Two — First Response - resp2, err := hterpc.Get(httpServerTwo.URL) + resp2, err := http.Get(httpServerTwo.URL) if err != nil { t.Error(err) } @@ -159,7 +159,7 @@ func TestNewReusablePortServers(t *testing.T) { httpServerTwo.Close() // Server One — Second Response - resp3, err := hterpc.Get(httpServerOne.URL) + resp3, err := http.Get(httpServerOne.URL) if err != nil { t.Error(err) } @@ -173,7 +173,7 @@ func TestNewReusablePortServers(t *testing.T) { } // Server One — Third Response - resp5, err := hterpc.Get(httpServerOne.URL) + resp5, err := http.Get(httpServerOne.URL) if err != nil { t.Error(err) } @@ -208,8 +208,8 @@ func ExampleNewReusablePortListener() { } defer listener.Close() - server := &hterpc.Server{} - hterpc.HandleFunc("/", func(w hterpc.ResponseWriter, r *hterpc.Request) { + server := &http.Server{} + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Println(os.Getgid()) fmt.Fprintf(w, "Hello, %q\n", html.EscapeString(r.URL.Path)) }) diff --git a/mixer/websocket/README.md b/mixer/websocket/README.md index 6bdfb8db..a0b518a6 100644 --- a/mixer/websocket/README.md +++ b/mixer/websocket/README.md @@ -86,8 +86,8 @@ func TestPbWebsocketTLS(t *testing.T) { func TestCustomizedWebsocket(t *testing.T) { srv := erpc.NewPeer(erpc.PeerConfig{}) - hterpc.Handle("/ws", ws.NewJSONServeHandler(srv, nil)) - go hterpc.ListenAndServe(":9092", nil) + http.Handle("/ws", ws.NewJSONServeHandler(srv, nil)) + go http.ListenAndServe(":9092", nil) srv.RouteCall(new(P)) time.Sleep(time.Second * 1) diff --git a/mixer/websocket/server.go b/mixer/websocket/server.go index bfcf89fa..1bea5cf9 100644 --- a/mixer/websocket/server.go +++ b/mixer/websocket/server.go @@ -31,18 +31,18 @@ import ( type Server struct { erpc.Peer cfg erpc.PeerConfig - serveMux *hterpc.ServeMux - server *hterpc.Server + serveMux *http.ServeMux + server *http.Server rootPath string lis net.Listener lisAddr net.Addr - handshake func(*ws.Config, *hterpc.Request) error + handshake func(*ws.Config, *http.Request) error } // NewServer creates a websocket server. func NewServer(rootPath string, cfg erpc.PeerConfig, globalLeftPlugin ...erpc.Plugin) *Server { p := erpc.NewPeer(cfg, globalLeftPlugin...) - serveMux := hterpc.NewServeMux() + serveMux := http.NewServeMux() lisAddr := cfg.ListenAddr() host, port, _ := net.SplitHostPort(lisAddr.String()) if port == "0" { @@ -59,7 +59,7 @@ func NewServer(rootPath string, cfg erpc.PeerConfig, globalLeftPlugin ...erpc.Pl serveMux: serveMux, rootPath: fixRootPath(rootPath), lisAddr: lisAddr, - server: &hterpc.Server{Addr: lisAddr.String(), Handler: serveMux}, + server: &http.Server{Addr: lisAddr.String(), Handler: serveMux}, } } @@ -115,33 +115,33 @@ func (srv *Server) Close() error { } // SetHandshake sets customized handshake function. -func (srv *Server) SetHandshake(handshake func(*ws.Config, *hterpc.Request) error) { +func (srv *Server) SetHandshake(handshake func(*ws.Config, *http.Request) error) { srv.handshake = handshake } // Handle registers the handler for the given rootPath. // If a handler already exists for rootPath, Handle panics. -func (srv *Server) Handle(rootPath string, handler hterpc.Handler) { +func (srv *Server) Handle(rootPath string, handler http.Handler) { srv.serveMux.Handle(rootPath, handler) } // HandleFunc registers the handler function for the given rootPath. -func (srv *Server) HandleFunc(rootPath string, handler func(hterpc.ResponseWriter, *hterpc.Request)) { +func (srv *Server) HandleFunc(rootPath string, handler func(http.ResponseWriter, *http.Request)) { srv.serveMux.HandleFunc(rootPath, handler) } // NewJSONServeHandler creates a websocket json handler. -func NewJSONServeHandler(peer erpc.Peer, handshake func(*ws.Config, *hterpc.Request) error) hterpc.Handler { +func NewJSONServeHandler(peer erpc.Peer, handshake func(*ws.Config, *http.Request) error) http.Handler { return NewServeHandler(peer, handshake, jsonSubProto.NewJSONSubProtoFunc()) } // NewPbServeHandler creates a websocket protobuf handler. -func NewPbServeHandler(peer erpc.Peer, handshake func(*ws.Config, *hterpc.Request) error) hterpc.Handler { +func NewPbServeHandler(peer erpc.Peer, handshake func(*ws.Config, *http.Request) error) http.Handler { return NewServeHandler(peer, handshake, pbSubProto.NewPbSubProtoFunc()) } // NewServeHandler creates a websocket handler. -func NewServeHandler(peer erpc.Peer, handshake func(*ws.Config, *hterpc.Request) error, protoFunc ...erpc.ProtoFunc) hterpc.Handler { +func NewServeHandler(peer erpc.Peer, handshake func(*ws.Config, *http.Request) error, protoFunc ...erpc.ProtoFunc) http.Handler { w := &serverHandler{ peer: peer, Server: new(ws.Server), @@ -154,7 +154,7 @@ func NewServeHandler(peer erpc.Peer, handshake func(*ws.Config, *hterpc.Request) scheme = "wss" } if handshake != nil { - w.Server.Handshake = func(cfg *ws.Config, r *hterpc.Request) error { + w.Server.Handshake = func(cfg *ws.Config, r *http.Request) error { cfg.Origin = &url.URL{ Host: r.RemoteAddr, Scheme: scheme, @@ -162,7 +162,7 @@ func NewServeHandler(peer erpc.Peer, handshake func(*ws.Config, *hterpc.Request) return handshake(cfg, r) } } else { - w.Server.Handshake = func(cfg *ws.Config, r *hterpc.Request) error { + w.Server.Handshake = func(cfg *ws.Config, r *http.Request) error { cfg.Origin = &url.URL{ Host: r.RemoteAddr, Scheme: scheme, diff --git a/mixer/websocket/websocket/client.go b/mixer/websocket/websocket/client.go index 402f3f68..69a4ac7e 100755 --- a/mixer/websocket/websocket/client.go +++ b/mixer/websocket/websocket/client.go @@ -34,7 +34,7 @@ func NewConfig(server, origin string) (config *Config, err error) { if err != nil { return } - config.Header = hterpc.Header(make(map[string][]string)) + config.Header = http.Header(make(map[string][]string)) return } diff --git a/mixer/websocket/websocket/hybi.go b/mixer/websocket/websocket/hybi.go index a0119054..8cffdd16 100755 --- a/mixer/websocket/websocket/hybi.go +++ b/mixer/websocket/websocket/hybi.go @@ -332,7 +332,7 @@ func (handler *hybiFrameHandler) WritePong(msg []byte) (n int, err error) { } // newHybiConn creates a new WebSocket connection speaking hybi draft protocol. -func newHybiConn(config *Config, buf *bufio.ReadWriter, rwc io.ReadWriteCloser, request *hterpc.Request) *Conn { +func newHybiConn(config *Config, buf *bufio.ReadWriter, rwc io.ReadWriteCloser, request *http.Request) *Conn { if buf == nil { br := bufio.NewReader(rwc) bw := bufio.NewWriter(rwc) @@ -437,7 +437,7 @@ func hybiClientHandshake(config *Config, br *bufio.Reader, bw *bufio.Writer) (er return err } - resp, err := hterpc.ReadResponse(br, &hterpc.Request{Method: "GET"}) + resp, err := http.ReadResponse(br, &http.Request{Method: "GET"}) if err != nil { return err } @@ -487,28 +487,28 @@ type hybiServerHandshaker struct { accept []byte } -func (c *hybiServerHandshaker) ReadHandshake(buf *bufio.Reader, req *hterpc.Request) (code int, err error) { +func (c *hybiServerHandshaker) ReadHandshake(buf *bufio.Reader, req *http.Request) (code int, err error) { c.Version = ProtocolVersionHybi13 if req.Method != "GET" { - return hterpc.StatusMethodNotAllowed, ErrBadRequestMethod + return http.StatusMethodNotAllowed, ErrBadRequestMethod } // HTTP version can be safely ignored. if strings.ToLower(req.Header.Get("Upgrade")) != "websocket" || !strings.Contains(strings.ToLower(req.Header.Get("Connection")), "upgrade") { - return hterpc.StatusBadRequest, ErrNotWebSocket + return http.StatusBadRequest, ErrNotWebSocket } key := req.Header.Get("Sec-Websocket-Key") if key == "" { - return hterpc.StatusBadRequest, ErrChallengeResponse + return http.StatusBadRequest, ErrChallengeResponse } version := req.Header.Get("Sec-Websocket-Version") switch version { case "13": c.Version = ProtocolVersionHybi13 default: - return hterpc.StatusBadRequest, ErrBadWebSocketVersion + return http.StatusBadRequest, ErrBadWebSocketVersion } var scheme string if req.TLS != nil { @@ -518,7 +518,7 @@ func (c *hybiServerHandshaker) ReadHandshake(buf *bufio.Reader, req *hterpc.Requ } c.Location, err = url.ParseRequestURI(scheme + "://" + req.Host + req.URL.RequestURI()) if err != nil { - return hterpc.StatusBadRequest, err + return http.StatusBadRequest, err } protocol := strings.TrimSpace(req.Header.Get("Sec-Websocket-Protocol")) if protocol != "" { @@ -529,14 +529,14 @@ func (c *hybiServerHandshaker) ReadHandshake(buf *bufio.Reader, req *hterpc.Requ } c.accept, err = getNonceAccept([]byte(key)) if err != nil { - return hterpc.StatusInternalServerError, err + return http.StatusInternalServerError, err } - return hterpc.StatusSwitchingProtocols, nil + return http.StatusSwitchingProtocols, nil } // Origin parses the Origin header in req. // If the Origin header is not set, it returns nil and nil. -func Origin(config *Config, req *hterpc.Request) (*url.URL, error) { +func Origin(config *Config, req *http.Request) (*url.URL, error) { var origin string switch config.Version { case ProtocolVersionHybi13: @@ -573,11 +573,11 @@ func (c *hybiServerHandshaker) AcceptHandshake(buf *bufio.Writer) (err error) { return buf.Flush() } -func (c *hybiServerHandshaker) NewServerConn(buf *bufio.ReadWriter, rwc io.ReadWriteCloser, request *hterpc.Request) *Conn { +func (c *hybiServerHandshaker) NewServerConn(buf *bufio.ReadWriter, rwc io.ReadWriteCloser, request *http.Request) *Conn { return newHybiServerConn(c.Config, buf, rwc, request) } // newHybiServerConn returns a new WebSocket connection speaking hybi draft protocol. -func newHybiServerConn(config *Config, buf *bufio.ReadWriter, rwc io.ReadWriteCloser, request *hterpc.Request) *Conn { +func newHybiServerConn(config *Config, buf *bufio.ReadWriter, rwc io.ReadWriteCloser, request *http.Request) *Conn { return newHybiConn(config, buf, rwc, request) } diff --git a/mixer/websocket/websocket/hybi_test.go b/mixer/websocket/websocket/hybi_test.go index 78479c54..9504aa2d 100755 --- a/mixer/websocket/websocket/hybi_test.go +++ b/mixer/websocket/websocket/hybi_test.go @@ -71,7 +71,7 @@ Sec-WebSocket-Protocol: chat if err := hybiClientHandshake(&config, br, bw); err != nil { t.Fatal("handshake", err) } - req, err := hterpc.ReadRequest(bufio.NewReader(&b)) + req, err := http.ReadRequest(bufio.NewReader(&b)) if err != nil { t.Fatal("read request", err) } @@ -126,7 +126,7 @@ Sec-WebSocket-Protocol: chat config.Protocol = append(config.Protocol, "chat") config.Protocol = append(config.Protocol, "superchat") config.Version = ProtocolVersionHybi13 - config.Header = hterpc.Header(make(map[string][]string)) + config.Header = http.Header(make(map[string][]string)) config.Header.Add("User-Agent", "test") config.handshakeData = map[string]string{ @@ -136,7 +136,7 @@ Sec-WebSocket-Protocol: chat if err != nil { t.Errorf("handshake failed: %v", err) } - req, err := hterpc.ReadRequest(bufio.NewReader(b)) + req, err := http.ReadRequest(bufio.NewReader(b)) if err != nil { t.Fatalf("read request: %v", err) } @@ -181,7 +181,7 @@ Sec-WebSocket-Protocol: chat, superchat Sec-WebSocket-Version: 13 `)) - req, err := hterpc.ReadRequest(br) + req, err := http.ReadRequest(br) if err != nil { t.Fatal("request", err) } @@ -189,8 +189,8 @@ Sec-WebSocket-Version: 13 if err != nil { t.Errorf("handshake failed: %v", err) } - if code != hterpc.StatusSwitchingProtocols { - t.Errorf("status expected %q but got %q", hterpc.StatusSwitchingProtocols, code) + if code != http.StatusSwitchingProtocols { + t.Errorf("status expected %q but got %q", http.StatusSwitchingProtocols, code) } expectedProtocols := []string{"chat", "superchat"} if fmt.Sprintf("%v", config.Protocol) != fmt.Sprintf("%v", expectedProtocols) { @@ -230,7 +230,7 @@ Origin: http://example.com Sec-WebSocket-Version: 13 `)) - req, err := hterpc.ReadRequest(br) + req, err := http.ReadRequest(br) if err != nil { t.Fatal("request", err) } @@ -238,8 +238,8 @@ Sec-WebSocket-Version: 13 if err != nil { t.Errorf("handshake failed: %v", err) } - if code != hterpc.StatusSwitchingProtocols { - t.Errorf("status expected %q but got %q", hterpc.StatusSwitchingProtocols, code) + if code != http.StatusSwitchingProtocols { + t.Errorf("status expected %q but got %q", http.StatusSwitchingProtocols, code) } if len(config.Protocol) != 0 { t.Errorf("len(config.Protocol) expected 0, but got %q", len(config.Protocol)) @@ -276,7 +276,7 @@ Sec-WebSocket-Protocol: chat, superchat Sec-WebSocket-Version: 9 `)) - req, err := hterpc.ReadRequest(br) + req, err := http.ReadRequest(br) if err != nil { t.Fatal("request", err) } @@ -284,8 +284,8 @@ Sec-WebSocket-Version: 9 if err != ErrBadWebSocketVersion { t.Errorf("handshake expected err %q but got %q", ErrBadWebSocketVersion, err) } - if code != hterpc.StatusBadRequest { - t.Errorf("status expected %q but got %q", hterpc.StatusBadRequest, code) + if code != http.StatusBadRequest { + t.Errorf("status expected %q but got %q", http.StatusBadRequest, code) } } @@ -493,7 +493,7 @@ func TestHybiServerRead(t *testing.T) { } br := bufio.NewReader(bytes.NewBuffer(wireData)) bw := bufio.NewWriter(bytes.NewBuffer([]byte{})) - conn := newHybiConn(newConfig(t, "/"), bufio.NewReadWriter(br, bw), nil, new(hterpc.Request)) + conn := newHybiConn(newConfig(t, "/"), bufio.NewReadWriter(br, bw), nil, new(http.Request)) expected := [][]byte{[]byte("hello"), []byte("world")} @@ -533,7 +533,7 @@ func TestHybiServerReadWithoutMasking(t *testing.T) { wireData := []byte{0x81, 0x05, 'h', 'e', 'l', 'l', 'o'} br := bufio.NewReader(bytes.NewBuffer(wireData)) bw := bufio.NewWriter(bytes.NewBuffer([]byte{})) - conn := newHybiConn(newConfig(t, "/"), bufio.NewReadWriter(br, bw), nil, new(hterpc.Request)) + conn := newHybiConn(newConfig(t, "/"), bufio.NewReadWriter(br, bw), nil, new(http.Request)) // server MUST close the connection upon receiving a non-masked frame. msg := make([]byte, 512) _, err := conn.Read(msg) @@ -574,7 +574,7 @@ Sec-WebSocket-Protocol: chat, superchat Sec-WebSocket-Version: 13 `)) - req, err := hterpc.ReadRequest(br) + req, err := http.ReadRequest(br) if err != nil { t.Fatal("request", err) } @@ -582,8 +582,8 @@ Sec-WebSocket-Version: 13 if err != nil { t.Errorf("handshake failed: %v", err) } - if code != hterpc.StatusSwitchingProtocols { - t.Errorf("status expected %q but got %q", hterpc.StatusSwitchingProtocols, code) + if code != http.StatusSwitchingProtocols { + t.Errorf("status expected %q but got %q", http.StatusSwitchingProtocols, code) } b := bytes.NewBuffer([]byte{}) bw := bufio.NewWriter(b) diff --git a/mixer/websocket/websocket/server.go b/mixer/websocket/websocket/server.go index b27e86c4..0895dea1 100755 --- a/mixer/websocket/websocket/server.go +++ b/mixer/websocket/websocket/server.go @@ -11,11 +11,11 @@ import ( "net/http" ) -func newServerConn(rwc io.ReadWriteCloser, buf *bufio.ReadWriter, req *hterpc.Request, config *Config, handshake func(*Config, *hterpc.Request) error) (conn *Conn, err error) { +func newServerConn(rwc io.ReadWriteCloser, buf *bufio.ReadWriter, req *http.Request, config *Config, handshake func(*Config, *http.Request) error) (conn *Conn, err error) { var hs serverHandshaker = &hybiServerHandshaker{Config: config} code, err := hs.ReadHandshake(buf.Reader, req) if err == ErrBadWebSocketVersion { - fmt.Fprintf(buf, "HTTP/1.1 %03d %s\r\n", code, hterpc.StatusText(code)) + fmt.Fprintf(buf, "HTTP/1.1 %03d %s\r\n", code, http.StatusText(code)) fmt.Fprintf(buf, "Sec-WebSocket-Version: %s\r\n", SupportedProtocolVersion) buf.WriteString("\r\n") buf.WriteString(err.Error()) @@ -23,7 +23,7 @@ func newServerConn(rwc io.ReadWriteCloser, buf *bufio.ReadWriter, req *hterpc.Re return } if err != nil { - fmt.Fprintf(buf, "HTTP/1.1 %03d %s\r\n", code, hterpc.StatusText(code)) + fmt.Fprintf(buf, "HTTP/1.1 %03d %s\r\n", code, http.StatusText(code)) buf.WriteString("\r\n") buf.WriteString(err.Error()) buf.Flush() @@ -32,8 +32,8 @@ func newServerConn(rwc io.ReadWriteCloser, buf *bufio.ReadWriter, req *hterpc.Re if handshake != nil { err = handshake(config, req) if err != nil { - code = hterpc.StatusForbidden - fmt.Fprintf(buf, "HTTP/1.1 %03d %s\r\n", code, hterpc.StatusText(code)) + code = http.StatusForbidden + fmt.Fprintf(buf, "HTTP/1.1 %03d %s\r\n", code, http.StatusText(code)) buf.WriteString("\r\n") buf.Flush() return @@ -41,8 +41,8 @@ func newServerConn(rwc io.ReadWriteCloser, buf *bufio.ReadWriter, req *hterpc.Re } err = hs.AcceptHandshake(buf.Writer) if err != nil { - code = hterpc.StatusBadRequest - fmt.Fprintf(buf, "HTTP/1.1 %03d %s\r\n", code, hterpc.StatusText(code)) + code = http.StatusBadRequest + fmt.Fprintf(buf, "HTTP/1.1 %03d %s\r\n", code, http.StatusText(code)) buf.WriteString("\r\n") buf.Flush() return @@ -59,19 +59,19 @@ type Server struct { // Handshake is an optional function in WebSocket handshake. // For example, you can check, or don't check Origin header. // Another example, you can select config.Protocol. - Handshake func(*Config, *hterpc.Request) error + Handshake func(*Config, *http.Request) error // Handler handles a WebSocket connection. Handler } -// ServeHTTP implements the hterpc.Handler interface for a WebSocket -func (s Server) ServeHTTP(w hterpc.ResponseWriter, req *hterpc.Request) { +// ServeHTTP implements the http.Handler interface for a WebSocket +func (s Server) ServeHTTP(w http.ResponseWriter, req *http.Request) { s.serveWebSocket(w, req) } -func (s Server) serveWebSocket(w hterpc.ResponseWriter, req *hterpc.Request) { - rwc, buf, err := w.(hterpc.Hijacker).Hijack() +func (s Server) serveWebSocket(w http.ResponseWriter, req *http.Request) { + rwc, buf, err := w.(http.Hijacker).Hijack() if err != nil { panic("Hijack failed: " + err.Error()) } @@ -98,7 +98,7 @@ func (s Server) serveWebSocket(w hterpc.ResponseWriter, req *hterpc.Request) { // Server.Handshake that does not check the origin. type Handler func(*Conn) -func checkOrigin(config *Config, req *hterpc.Request) (err error) { +func checkOrigin(config *Config, req *http.Request) (err error) { config.Origin, err = Origin(config, req) if err == nil && config.Origin == nil { return fmt.Errorf("null origin") @@ -106,8 +106,8 @@ func checkOrigin(config *Config, req *hterpc.Request) (err error) { return err } -// ServeHTTP implements the hterpc.Handler interface for a WebSocket -func (h Handler) ServeHTTP(w hterpc.ResponseWriter, req *hterpc.Request) { +// ServeHTTP implements the http.Handler interface for a WebSocket +func (h Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) { s := Server{Handler: h, Handshake: checkOrigin} s.serveWebSocket(w, req) } diff --git a/mixer/websocket/websocket/websocket.go b/mixer/websocket/websocket/websocket.go index ee462688..42b37120 100755 --- a/mixer/websocket/websocket/websocket.go +++ b/mixer/websocket/websocket/websocket.go @@ -96,7 +96,7 @@ type Config struct { TLSConfig *tls.Config // Additional header fields to be sent in WebSocket opening handshake. - Header hterpc.Header + Header http.Header // Dialer used when opening websocket connections. Dialer *net.Dialer @@ -108,14 +108,14 @@ type Config struct { type serverHandshaker interface { // ReadHandshake reads handshake request message from client. // Returns http response code and error if any. - ReadHandshake(buf *bufio.Reader, req *hterpc.Request) (code int, err error) + ReadHandshake(buf *bufio.Reader, req *http.Request) (code int, err error) // AcceptHandshake accepts the client handshake request and sends // handshake response back to client. AcceptHandshake(buf *bufio.Writer) (err error) // NewServerConn creates a new WebSocket connection. - NewServerConn(buf *bufio.ReadWriter, rwc io.ReadWriteCloser, request *hterpc.Request) (conn *Conn) + NewServerConn(buf *bufio.ReadWriter, rwc io.ReadWriteCloser, request *http.Request) (conn *Conn) } // frameReader is an interface to read a WebSocket frame. @@ -163,7 +163,7 @@ type frameHandler interface { // Multiple goroutines may invoke methods on a Conn simultaneously. type Conn struct { config *Config - request *hterpc.Request + request *http.Request buf *bufio.ReadWriter rwc io.ReadWriteCloser @@ -293,7 +293,7 @@ func (ws *Conn) Config() *Config { return ws.config } // Request returns the http request upgraded to the WebSocket. // It is nil for client side. -func (ws *Conn) Request() *hterpc.Request { return ws.request } +func (ws *Conn) Request() *http.Request { return ws.request } // Codec represents a symmetric pair of functions that implement a codec. type Codec struct { @@ -400,19 +400,19 @@ Trivial usage: // receive text frame var message string - weberpc.Message.Receive(ws, &message) + websocket.Message.Receive(ws, &message) // send text frame message = "hello" - weberpc.Message.Send(ws, message) + websocket.Message.Send(ws, message) // receive binary frame var data []byte - weberpc.Message.Receive(ws, &data) + websocket.Message.Receive(ws, &data) // send binary frame data = []byte{0, 1, 2} - weberpc.Message.Send(ws, data) + websocket.Message.Send(ws, data) */ var Message = Codec{marshal, unmarshal} diff --git a/mixer/websocket/websocket/websocket_test.go b/mixer/websocket/websocket/websocket_test.go index 2bd4c800..2054ce85 100755 --- a/mixer/websocket/websocket/websocket_test.go +++ b/mixer/websocket/websocket/websocket_test.go @@ -101,7 +101,7 @@ func ctrlAndDataServer(ws *Conn) { } } -func subProtocolHandshake(config *Config, req *hterpc.Request) error { +func subProtocolHandshake(config *Config, req *http.Request) error { for _, proto := range config.Protocol { if proto == "chat" { config.Protocol = []string{proto} @@ -118,14 +118,14 @@ func subProtoServer(ws *Conn) { } func startServer() { - hterpc.Handle("/echo", Handler(echoServer)) - hterpc.Handle("/count", Handler(countServer)) - hterpc.Handle("/ctrldata", Handler(ctrlAndDataServer)) + http.Handle("/echo", Handler(echoServer)) + http.Handle("/count", Handler(countServer)) + http.Handle("/ctrldata", Handler(ctrlAndDataServer)) subproto := Server{ Handshake: subProtocolHandshake, Handler: Handler(subProtoServer), } - hterpc.Handle("/subproto", subproto) + http.Handle("/subproto", subproto) server := httptest.NewServer(nil) serverAddr = server.Listener.Addr().String() log.Print("Test WebSocket server listening on ", serverAddr) @@ -313,7 +313,7 @@ func TestHTTP(t *testing.T) { // If the client did not send a handshake that matches the protocol // specification, the server MUST return an HTTP response with an // appropriate error code (such as 400 Bad Request) - resp, err := hterpc.Get(fmt.Sprintf("http://%s/echo", serverAddr)) + resp, err := http.Get(fmt.Sprintf("http://%s/echo", serverAddr)) if err != nil { t.Errorf("Get: error %#v", err) return @@ -322,8 +322,8 @@ func TestHTTP(t *testing.T) { t.Error("Get: resp is null") return } - if resp.StatusCode != hterpc.StatusBadRequest { - t.Errorf("Get: expected %q got %q", hterpc.StatusBadRequest, resp.StatusCode) + if resp.StatusCode != http.StatusBadRequest { + t.Errorf("Get: expected %q got %q", http.StatusBadRequest, resp.StatusCode) } } @@ -533,12 +533,12 @@ func TestClose(t *testing.T) { } var originTests = []struct { - req *hterpc.Request + req *http.Request origin *url.URL }{ { - req: &hterpc.Request{ - Header: hterpc.Header{ + req: &http.Request{ + Header: http.Header{ "Origin": []string{"http://www.example.com"}, }, }, @@ -548,7 +548,7 @@ var originTests = []struct { }, }, { - req: &hterpc.Request{}, + req: &http.Request{}, }, } diff --git a/mixer/websocket/websocket_test.go b/mixer/websocket/websocket_test.go index 4426f586..e6cdabf4 100644 --- a/mixer/websocket/websocket_test.go +++ b/mixer/websocket/websocket_test.go @@ -76,8 +76,8 @@ func TestPbWebsocketTLS(t *testing.T) { func TestCustomizedWebsocket(t *testing.T) { srv := erpc.NewPeer(erpc.PeerConfig{}) - hterpc.Handle("/ws", ws.NewJSONServeHandler(srv, nil)) - go hterpc.ListenAndServe(":9092", nil) + http.Handle("/ws", ws.NewJSONServeHandler(srv, nil)) + go http.ListenAndServe(":9092", nil) srv.RouteCall(new(P)) time.Sleep(time.Second * 1) diff --git a/proto/httproto/README.md b/proto/httproto/README.md index b0627daa..c9b71490 100644 --- a/proto/httproto/README.md +++ b/proto/httproto/README.md @@ -127,7 +127,7 @@ func TestHTTProto(t *testing.T) { // HTTP Client contentType, body, _ := httpbody.NewJSONBody(arg) - resp, err := hterpc.Post(url, contentType, body) + resp, err := http.Post(url, contentType, body) if err != nil { t.Fatal(err) } diff --git a/proto/httproto/httproto.go b/proto/httproto/httproto.go index fc1cf27b..15ff26d2 100644 --- a/proto/httproto/httproto.go +++ b/proto/httproto/httproto.go @@ -121,7 +121,7 @@ func (h *httproto) Pack(m erpc.Message) (err error) { return err } - var header = make(hterpc.Header, m.Meta().Len()) + var header = make(http.Header, m.Meta().Len()) // do transfer pipe m.XferPipe().Range(func(idx int, filter xfer.XferFilter) bool { @@ -175,7 +175,7 @@ var ( crlfBytes = []byte("\r\n") ) -func (h *httproto) packRequest(m erpc.Message, header hterpc.Header, bb *utils.ByteBuffer, bodyBytes []byte) error { +func (h *httproto) packRequest(m erpc.Message, header http.Header, bb *utils.ByteBuffer, bodyBytes []byte) error { u, err := url.Parse(m.ServiceMethod()) if err != nil { return err @@ -208,7 +208,7 @@ var ( bizErrBytes = []byte("299 Business Error") ) -func (h *httproto) packResponse(m erpc.Message, header hterpc.Header, bb *utils.ByteBuffer, bodyBytes []byte) error { +func (h *httproto) packResponse(m erpc.Message, header http.Header, bb *utils.ByteBuffer, bodyBytes []byte) error { bb.Write(versionBytes) bb.WriteByte(' ') if stat := m.Status(); !stat.OK() { diff --git a/proto/httproto/httproto_test.go b/proto/httproto/httproto_test.go index 426e717d..17882ba8 100644 --- a/proto/httproto/httproto_test.go +++ b/proto/httproto/httproto_test.go @@ -58,7 +58,7 @@ func TestHTTProto(t *testing.T) { // HTTP Client contentType, body, _ := httpbody.NewJSONBody(arg) - resp, err := hterpc.Post(testURL, contentType, body) + resp, err := http.Post(testURL, contentType, body) if err != nil { t.Fatal(err) } @@ -81,7 +81,7 @@ func TestHTTProto(t *testing.T) { t.Logf("erpc client response: %v, %v", stat, result) contentType, body, _ := httpbody.NewJSONBody(arg) - resp, err := hterpc.Post(testErrURL, contentType, body) + resp, err := http.Post(testErrURL, contentType, body) if err != nil { t.Fatal(err) }