removed 'upgrader' interface

This commit is contained in:
xdrm-brackets 2018-05-03 19:50:30 +02:00
parent a31269118f
commit 52673ba7e5
3 changed files with 14 additions and 43 deletions

View File

@ -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
}

View File

@ -1 +0,0 @@
package upgrader

View File

@ -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{