mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
ws: allow to set Origin header and default to nil
This commit is contained in:
1 parent
8a2e95b17e
commit
4887089a4b
6 files changed
+12
-8
No files matched your search
@@ -216,7 +216,7 @@ func (t *tls12TicketAuth) Encode(data []byte) (encodedData []byte, err error) {
|
||||
encodedData[pdata-1] = 0x1
|
||||
encodedData[pdata-2] = 0x3 // tls version
|
||||
pdata -= 2
|
||||
l += 2
|
||||
// l += 2
|
||||
encodedData[pdata-1] = 0x16 // tls handshake
|
||||
// pdata -= 1
|
||||
// l += 1
|
||||
|
||||
+5
-3
@@ -52,11 +52,11 @@ type ClientConn struct {
|
||||
// NewClientConn creates a new ws client connection.
|
||||
func (s *WS) NewClientConn(rc net.Conn) (*ClientConn, error) {
|
||||
conn := &ClientConn{Conn: rc}
|
||||
return conn, conn.Handshake(s.host, s.path)
|
||||
return conn, conn.Handshake(s.host, s.path, s.origin)
|
||||
}
|
||||
|
||||
// Handshake handshakes with the server using HTTP to request a protocol upgrade.
|
||||
func (c *ClientConn) Handshake(host, path string) error {
|
||||
func (c *ClientConn) Handshake(host, path, origin string) error {
|
||||
clientKey := generateClientKey()
|
||||
|
||||
buf := pool.GetBytesBuffer()
|
||||
@@ -66,7 +66,9 @@ func (c *ClientConn) Handshake(host, path string) error {
|
||||
buf.WriteString("Host: " + host + "\r\n")
|
||||
buf.WriteString("Upgrade: websocket\r\n")
|
||||
buf.WriteString("Connection: Upgrade\r\n")
|
||||
buf.WriteString("Origin: http://" + host + "\r\n")
|
||||
if origin != "" {
|
||||
buf.WriteString("Origin: http://" + origin + "\r\n")
|
||||
}
|
||||
buf.WriteString("Sec-WebSocket-Key: " + clientKey + "\r\n")
|
||||
buf.WriteString("Sec-WebSocket-Protocol: binary\r\n")
|
||||
buf.WriteString("Sec-WebSocket-Version: 13\r\n")
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ func NewWSServer(s string, p proxy.Proxy) (proxy.Server, error) {
|
||||
// prepare transport listener
|
||||
// TODO: check here
|
||||
if len(transport) < 2 {
|
||||
return nil, errors.New("[tls] malformd listener:" + s)
|
||||
return nil, errors.New("[ws] malformd listener:" + s)
|
||||
}
|
||||
|
||||
w, err := NewWS(transport[0], nil, p)
|
||||
|
||||
@@ -21,6 +21,7 @@ type WS struct {
|
||||
addr string
|
||||
host string
|
||||
path string
|
||||
origin string
|
||||
|
||||
server proxy.Server
|
||||
}
|
||||
@@ -46,6 +47,7 @@ func NewWS(s string, d proxy.Dialer, p proxy.Proxy) (*WS, error) {
|
||||
addr: addr,
|
||||
host: u.Query().Get("host"),
|
||||
path: u.Path,
|
||||
origin: u.Query().Get("origin"),
|
||||
}
|
||||
|
||||
if w.host == "" {
|
||||
|
||||
Reference in new issue
Block a user