From 52673ba7e58f37ac6102a5baeef481cc5a8721ad Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Thu, 3 May 2018 19:50:30 +0200 Subject: [PATCH] removed 'upgrader' interface --- upgrader/public.go | 34 ---------------------------------- upgrader/types.go | 1 - ws/client.go | 22 ++++++++++++++-------- 3 files changed, 14 insertions(+), 43 deletions(-) delete mode 100644 upgrader/public.go delete mode 100644 upgrader/types.go diff --git a/upgrader/public.go b/upgrader/public.go deleted file mode 100644 index b7dc28d..0000000 --- a/upgrader/public.go +++ /dev/null @@ -1,34 +0,0 @@ -package upgrader - -import ( - "git.xdrm.io/gws/internal/http/upgrade/response" - "fmt" - "git.xdrm.io/gws/internal/http/upgrade/request" - "net" -) - -type T struct { - Request *request.T - Response *response.T -} - -func Upgrade(s net.Conn) (*T, error) { - - /* (1) Create upgrder */ - inst := new(T) - - /* (2) Parse request */ - inst.Request, _ = request.Parse(s) - - /* (3) Build response */ - inst.Response = inst.Request.BuildResponse() - - /* (4) Write into socket */ - _, err := inst.Response.Send(s) - if err != nil { - return inst, fmt.Errorf("Socket write error: %s", err) - } - - return inst, nil - -} \ No newline at end of file diff --git a/upgrader/types.go b/upgrader/types.go deleted file mode 100644 index 2df626f..0000000 --- a/upgrader/types.go +++ /dev/null @@ -1 +0,0 @@ -package upgrader \ No newline at end of file diff --git a/ws/client.go b/ws/client.go index 09a0eaf..8ee9e89 100644 --- a/ws/client.go +++ b/ws/client.go @@ -3,7 +3,7 @@ package ws import ( "bufio" "encoding/binary" - "git.xdrm.io/gws/upgrader" + "git.xdrm.io/gws/internal/http/upgrade/request" "net" "fmt" ) @@ -38,23 +38,29 @@ func buildClient(s net.Conn, ctl ControllerSet, serverCh serverChannelSet) (*cli /* (1) Manage UPGRADE request ---------------------------------------------------------*/ - upgrader, err := upgrader.Upgrade(s) + /* (1) Parse request */ + req, _ := request.Parse(s) + + /* (3) Build response */ + res := req.BuildResponse() + + /* (4) Write into socket */ + _, err := res.Send(s) if err != nil { - s.Close() - return nil, fmt.Errorf("Upgrade error: %s\n", err) + return nil, fmt.Errorf("Upgrade write error: %s", err) } - if upgrader.Response.GetStatusCode() != 101 { + if res.GetStatusCode() != 101 { s.Close() - return nil, fmt.Errorf("Upgrade error (HTTP %d)\n", upgrader.Response.GetStatusCode()) + return nil, fmt.Errorf("Upgrade error (HTTP %d)\n", res.GetStatusCode()) } /* (2) Initialise client ---------------------------------------------------------*/ /* (1) Get upgrade data */ - clientURI := upgrader.Request.GetURI() - clientProtocol := upgrader.Response.GetProtocol() + clientURI := req.GetURI() + clientProtocol := res.GetProtocol() /* (2) Initialise client */ instance := &client{