removed 'upgrader' interface
This commit is contained in:
parent
a31269118f
commit
52673ba7e5
|
@ -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
|
|
||||||
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
package upgrader
|
|
22
ws/client.go
22
ws/client.go
|
@ -3,7 +3,7 @@ package ws
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"git.xdrm.io/gws/upgrader"
|
"git.xdrm.io/gws/internal/http/upgrade/request"
|
||||||
"net"
|
"net"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
@ -38,23 +38,29 @@ func buildClient(s net.Conn, ctl ControllerSet, serverCh serverChannelSet) (*cli
|
||||||
|
|
||||||
/* (1) Manage UPGRADE request
|
/* (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 {
|
if err != nil {
|
||||||
s.Close()
|
return nil, fmt.Errorf("Upgrade write error: %s", err)
|
||||||
return nil, fmt.Errorf("Upgrade error: %s\n", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if upgrader.Response.GetStatusCode() != 101 {
|
if res.GetStatusCode() != 101 {
|
||||||
s.Close()
|
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
|
/* (2) Initialise client
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
/* (1) Get upgrade data */
|
/* (1) Get upgrade data */
|
||||||
clientURI := upgrader.Request.GetURI()
|
clientURI := req.GetURI()
|
||||||
clientProtocol := upgrader.Response.GetProtocol()
|
clientProtocol := res.GetProtocol()
|
||||||
|
|
||||||
/* (2) Initialise client */
|
/* (2) Initialise client */
|
||||||
instance := &client{
|
instance := &client{
|
||||||
|
|
Loading…
Reference in New Issue