From 5e4341e3d980c175a9efee554f68571fa060a0eb Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Thu, 26 Apr 2018 23:01:25 +0200 Subject: [PATCH] upgrader interface returns a wrapper for the upgrade Request + Response for further information gathering while passing to WS protocol --- upgrader/public.go | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/upgrader/public.go b/upgrader/public.go index a606c62..d082d26 100644 --- a/upgrader/public.go +++ b/upgrader/public.go @@ -1,26 +1,34 @@ package upgrader import ( + "git.xdrm.io/gws/internal/http/upgrade/response" "fmt" "git.xdrm.io/gws/internal/http/upgrade/request" "net" ) +type T struct { + req *request.T + res *response.T +} -func Upgrade(s net.Conn) error { +func Upgrade(s net.Conn) (*T, error) { - /* (1) Parse request */ - req, _ := request.Parse(s) + /* (1) Create upgrder */ + inst := new(T) - /* (2) Build response */ - res := req.BuildResponse() + /* (2) Parse request */ + inst.req, _ = request.Parse(s) - /* (3) Write into socket */ - _, err := res.Send(s) + /* (3) Build response */ + inst.res = inst.req.BuildResponse() + + /* (4) Write into socket */ + _, err := inst.res.Send(s) if err != nil { - return fmt.Errorf("Socket write error: %s", err) + return inst, fmt.Errorf("Socket write error: %s", err) } - return nil + return inst, nil } \ No newline at end of file