upgrader interface returns a wrapper for the upgrade Request + Response for further information gathering while passing to WS protocol
This commit is contained in:
parent
1c06b81cae
commit
5e4341e3d9
|
@ -1,26 +1,34 @@
|
||||||
package upgrader
|
package upgrader
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.xdrm.io/gws/internal/http/upgrade/response"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.xdrm.io/gws/internal/http/upgrade/request"
|
"git.xdrm.io/gws/internal/http/upgrade/request"
|
||||||
"net"
|
"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 */
|
/* (1) Create upgrder */
|
||||||
req, _ := request.Parse(s)
|
inst := new(T)
|
||||||
|
|
||||||
/* (2) Build response */
|
/* (2) Parse request */
|
||||||
res := req.BuildResponse()
|
inst.req, _ = request.Parse(s)
|
||||||
|
|
||||||
/* (3) Write into socket */
|
/* (3) Build response */
|
||||||
_, err := res.Send(s)
|
inst.res = inst.req.BuildResponse()
|
||||||
|
|
||||||
|
/* (4) Write into socket */
|
||||||
|
_, err := inst.res.Send(s)
|
||||||
if err != nil {
|
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
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue