mirror of
https://github.com/nadoo/glider.git
synced 2025-02-23 17:35:40 +08:00
ws: support set a different host header #157
This commit is contained in:
parent
666c76f921
commit
855907c46b
20
README.md
20
README.md
@ -116,7 +116,7 @@ glider -config CONFIGPATH -listen :8080 -verbose
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
glider 0.9.0 usage:
|
glider 0.10.0 usage:
|
||||||
-checkinterval int
|
-checkinterval int
|
||||||
proxy check interval(seconds) (default 30)
|
proxy check interval(seconds) (default 30)
|
||||||
-checktimeout int
|
-checktimeout int
|
||||||
@ -221,19 +221,19 @@ Proxy over tls server:
|
|||||||
tls://host:port?cert=PATH&key=PATH,ss://method:pass@
|
tls://host:port?cert=PATH&key=PATH,ss://method:pass@
|
||||||
|
|
||||||
Websocket scheme:
|
Websocket scheme:
|
||||||
ws://host:port[/path]
|
ws://host:port[/path][?host=HOST]
|
||||||
|
|
||||||
Websocket with a specified proxy protocol:
|
Websocket with a specified proxy protocol:
|
||||||
ws://host:port[/path],scheme://
|
ws://host:port[/path][?host=HOST],scheme://
|
||||||
ws://host:port[/path],http://[user:pass@]
|
ws://host:port[/path][?host=HOST],http://[user:pass@]
|
||||||
ws://host:port[/path],socks5://[user:pass@]
|
ws://host:port[/path][?host=HOST],socks5://[user:pass@]
|
||||||
ws://host:port[/path],vmess://[security:]uuid@?alterID=num
|
ws://host:port[/path][?host=HOST],vmess://[security:]uuid@?alterID=num
|
||||||
|
|
||||||
TLS and Websocket with a specified proxy protocol:
|
TLS and Websocket with a specified proxy protocol:
|
||||||
tls://host:port[?skipVerify=true],ws://[@/path],scheme://
|
tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],scheme://
|
||||||
tls://host:port[?skipVerify=true],ws://[@/path],http://[user:pass@]
|
tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],http://[user:pass@]
|
||||||
tls://host:port[?skipVerify=true],ws://[@/path],socks5://[user:pass@]
|
tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],socks5://[user:pass@]
|
||||||
tls://host:port[?skipVerify=true],ws://[@/path],vmess://[security:]uuid@?alterID=num
|
tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],vmess://[security:]uuid@?alterID=num
|
||||||
|
|
||||||
Unix domain socket scheme:
|
Unix domain socket scheme:
|
||||||
unix://path
|
unix://path
|
||||||
|
18
conf.go
18
conf.go
@ -185,21 +185,21 @@ func usage() {
|
|||||||
fmt.Fprintf(w, "\n")
|
fmt.Fprintf(w, "\n")
|
||||||
|
|
||||||
fmt.Fprintf(w, "Websocket scheme:\n")
|
fmt.Fprintf(w, "Websocket scheme:\n")
|
||||||
fmt.Fprintf(w, " ws://host:port[/path]\n")
|
fmt.Fprintf(w, " ws://host:port[/path][?host=HOST]\n")
|
||||||
fmt.Fprintf(w, "\n")
|
fmt.Fprintf(w, "\n")
|
||||||
|
|
||||||
fmt.Fprintf(w, "Websocket with a specified proxy protocol:\n")
|
fmt.Fprintf(w, "Websocket with a specified proxy protocol:\n")
|
||||||
fmt.Fprintf(w, " ws://host:port[/path],scheme://\n")
|
fmt.Fprintf(w, " ws://host:port[/path][?host=HOST],scheme://\n")
|
||||||
fmt.Fprintf(w, " ws://host:port[/path],http://[user:pass@]\n")
|
fmt.Fprintf(w, " ws://host:port[/path][?host=HOST],http://[user:pass@]\n")
|
||||||
fmt.Fprintf(w, " ws://host:port[/path],socks5://[user:pass@]\n")
|
fmt.Fprintf(w, " ws://host:port[/path][?host=HOST],socks5://[user:pass@]\n")
|
||||||
fmt.Fprintf(w, " ws://host:port[/path],vmess://[security:]uuid@?alterID=num\n")
|
fmt.Fprintf(w, " ws://host:port[/path][?host=HOST],vmess://[security:]uuid@?alterID=num\n")
|
||||||
fmt.Fprintf(w, "\n")
|
fmt.Fprintf(w, "\n")
|
||||||
|
|
||||||
fmt.Fprintf(w, "TLS and Websocket with a specified proxy protocol:\n")
|
fmt.Fprintf(w, "TLS and Websocket with a specified proxy protocol:\n")
|
||||||
fmt.Fprintf(w, " tls://host:port[?skipVerify=true],ws://[@/path],scheme://\n")
|
fmt.Fprintf(w, " tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],scheme://\n")
|
||||||
fmt.Fprintf(w, " tls://host:port[?skipVerify=true],ws://[@/path],http://[user:pass@]\n")
|
fmt.Fprintf(w, " tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],http://[user:pass@]\n")
|
||||||
fmt.Fprintf(w, " tls://host:port[?skipVerify=true],ws://[@/path],socks5://[user:pass@]\n")
|
fmt.Fprintf(w, " tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],socks5://[user:pass@]\n")
|
||||||
fmt.Fprintf(w, " tls://host:port[?skipVerify=true],ws://[@/path],vmess://[security:]uuid@?alterID=num\n")
|
fmt.Fprintf(w, " tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],vmess://[security:]uuid@?alterID=num\n")
|
||||||
fmt.Fprintf(w, "\n")
|
fmt.Fprintf(w, "\n")
|
||||||
|
|
||||||
fmt.Fprintf(w, "Unix domain socket scheme:\n")
|
fmt.Fprintf(w, "Unix domain socket scheme:\n")
|
||||||
|
@ -288,7 +288,7 @@ func (c *Client) GenResponse(domain string, ip string) (*Message, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getKey(q *Question) string {
|
func getKey(q *Question) string {
|
||||||
qtype := ""
|
var qtype string
|
||||||
switch q.QTYPE {
|
switch q.QTYPE {
|
||||||
case QTypeA:
|
case QTypeA:
|
||||||
qtype = "A"
|
qtype = "A"
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
type WS struct {
|
type WS struct {
|
||||||
dialer proxy.Dialer
|
dialer proxy.Dialer
|
||||||
addr string
|
addr string
|
||||||
|
host string
|
||||||
|
|
||||||
client *Client
|
client *Client
|
||||||
}
|
}
|
||||||
@ -27,7 +28,7 @@ func init() {
|
|||||||
func NewWS(s string, d proxy.Dialer) (*WS, error) {
|
func NewWS(s string, d proxy.Dialer) (*WS, error) {
|
||||||
u, err := url.Parse(s)
|
u, err := url.Parse(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.F("parse url err: %s", err)
|
log.F("[ws] parse url err: %s", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,21 +39,26 @@ func NewWS(s string, d proxy.Dialer) (*WS, error) {
|
|||||||
addr = d.Addr()
|
addr = d.Addr()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
query := u.Query()
|
||||||
|
host := query.Get("host")
|
||||||
|
if host == "" {
|
||||||
colonPos := strings.LastIndex(addr, ":")
|
colonPos := strings.LastIndex(addr, ":")
|
||||||
if colonPos == -1 {
|
if colonPos == -1 {
|
||||||
colonPos = len(addr)
|
colonPos = len(addr)
|
||||||
}
|
}
|
||||||
serverName := addr[:colonPos]
|
host = addr[:colonPos]
|
||||||
|
}
|
||||||
|
|
||||||
client, err := NewClient(serverName, u.Path)
|
client, err := NewClient(host, u.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.F("create ws client err: %s", err)
|
log.F("[ws] create ws client error: %s", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
p := &WS{
|
p := &WS{
|
||||||
dialer: d,
|
dialer: d,
|
||||||
addr: addr,
|
addr: addr,
|
||||||
|
host: host,
|
||||||
client: client,
|
client: client,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,5 +90,5 @@ func (s *WS) Dial(network, addr string) (net.Conn, error) {
|
|||||||
|
|
||||||
// DialUDP connects to the given address via the proxy.
|
// DialUDP connects to the given address via the proxy.
|
||||||
func (s *WS) DialUDP(network, addr string) (net.PacketConn, net.Addr, error) {
|
func (s *WS) DialUDP(network, addr string) (net.PacketConn, net.Addr, error) {
|
||||||
return nil, nil, errors.New("ws client does not support udp now")
|
return nil, nil, errors.New("[ws] ws client does not support udp now")
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ func (p priSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
|||||||
type Proxy struct {
|
type Proxy struct {
|
||||||
config *Config
|
config *Config
|
||||||
fwdrs priSlice
|
fwdrs priSlice
|
||||||
avail []*Forwarder // avaliable forwarders
|
avail []*Forwarder // available forwarders
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
index uint32
|
index uint32
|
||||||
priority uint32
|
priority uint32
|
||||||
|
Loading…
Reference in New Issue
Block a user