mirror of
https://github.com/nadoo/glider.git
synced 2025-02-23 01:15:41 +08:00
ws: support set a different host header #157
This commit is contained in:
parent
666c76f921
commit
855907c46b
60
README.md
60
README.md
@ -116,47 +116,47 @@ glider -config CONFIGPATH -listen :8080 -verbose
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
glider 0.9.0 usage:
|
||||
glider 0.10.0 usage:
|
||||
-checkinterval int
|
||||
proxy check interval(seconds) (default 30)
|
||||
proxy check interval(seconds) (default 30)
|
||||
-checktimeout int
|
||||
proxy check timeout(seconds) (default 10)
|
||||
proxy check timeout(seconds) (default 10)
|
||||
-checkwebsite string
|
||||
proxy check HTTP(NOT HTTPS) website address, format: HOST[:PORT], default port: 80 (default "www.apple.com")
|
||||
proxy check HTTP(NOT HTTPS) website address, format: HOST[:PORT], default port: 80 (default "www.apple.com")
|
||||
-config string
|
||||
config file path
|
||||
config file path
|
||||
-dns string
|
||||
local dns server listen address
|
||||
local dns server listen address
|
||||
-dnsalwaystcp
|
||||
always use tcp to query upstream dns servers no matter there is a forwarder or not
|
||||
always use tcp to query upstream dns servers no matter there is a forwarder or not
|
||||
-dnsmaxttl int
|
||||
maximum TTL value for entries in the CACHE(seconds) (default 1800)
|
||||
maximum TTL value for entries in the CACHE(seconds) (default 1800)
|
||||
-dnsminttl int
|
||||
minimum TTL value for entries in the CACHE(seconds)
|
||||
minimum TTL value for entries in the CACHE(seconds)
|
||||
-dnsrecord value
|
||||
custom dns record, format: domain/ip
|
||||
custom dns record, format: domain/ip
|
||||
-dnsserver value
|
||||
remote dns server address
|
||||
remote dns server address
|
||||
-dnstimeout int
|
||||
timeout value used in multiple dnsservers switch(seconds) (default 3)
|
||||
timeout value used in multiple dnsservers switch(seconds) (default 3)
|
||||
-forward value
|
||||
forward url, format: SCHEME://[USER|METHOD:PASSWORD@][HOST]:PORT?PARAMS[,SCHEME://[USER|METHOD:PASSWORD@][HOST]:PORT?PARAMS]
|
||||
forward url, format: SCHEME://[USER|METHOD:PASSWORD@][HOST]:PORT?PARAMS[,SCHEME://[USER|METHOD:PASSWORD@][HOST]:PORT?PARAMS]
|
||||
-include value
|
||||
include file
|
||||
include file
|
||||
-interface string
|
||||
source ip or source interface
|
||||
source ip or source interface
|
||||
-listen value
|
||||
listen url, format: SCHEME://[USER|METHOD:PASSWORD@][HOST]:PORT?PARAMS
|
||||
listen url, format: SCHEME://[USER|METHOD:PASSWORD@][HOST]:PORT?PARAMS
|
||||
-maxfailures int
|
||||
max failures to change forwarder status to disabled (default 3)
|
||||
max failures to change forwarder status to disabled (default 3)
|
||||
-rulefile value
|
||||
rule file path
|
||||
rule file path
|
||||
-rules-dir string
|
||||
rule file folder
|
||||
rule file folder
|
||||
-strategy string
|
||||
forward strategy, default: rr (default "rr")
|
||||
forward strategy, default: rr (default "rr")
|
||||
-verbose
|
||||
verbose mode
|
||||
verbose mode
|
||||
|
||||
Available Schemes:
|
||||
mixed: serve as a http/socks5 proxy on the same port. (default)
|
||||
@ -221,19 +221,19 @@ Proxy over tls server:
|
||||
tls://host:port?cert=PATH&key=PATH,ss://method:pass@
|
||||
|
||||
Websocket scheme:
|
||||
ws://host:port[/path]
|
||||
ws://host:port[/path][?host=HOST]
|
||||
|
||||
Websocket with a specified proxy protocol:
|
||||
ws://host:port[/path],scheme://
|
||||
ws://host:port[/path],http://[user:pass@]
|
||||
ws://host:port[/path],socks5://[user:pass@]
|
||||
ws://host:port[/path],vmess://[security:]uuid@?alterID=num
|
||||
ws://host:port[/path][?host=HOST],scheme://
|
||||
ws://host:port[/path][?host=HOST],http://[user:pass@]
|
||||
ws://host:port[/path][?host=HOST],socks5://[user:pass@]
|
||||
ws://host:port[/path][?host=HOST],vmess://[security:]uuid@?alterID=num
|
||||
|
||||
TLS and Websocket with a specified proxy protocol:
|
||||
tls://host:port[?skipVerify=true],ws://[@/path],scheme://
|
||||
tls://host:port[?skipVerify=true],ws://[@/path],http://[user:pass@]
|
||||
tls://host:port[?skipVerify=true],ws://[@/path],socks5://[user:pass@]
|
||||
tls://host:port[?skipVerify=true],ws://[@/path],vmess://[security:]uuid@?alterID=num
|
||||
tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],scheme://
|
||||
tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],http://[user:pass@]
|
||||
tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],socks5://[user:pass@]
|
||||
tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],vmess://[security:]uuid@?alterID=num
|
||||
|
||||
Unix domain socket scheme:
|
||||
unix://path
|
||||
|
18
conf.go
18
conf.go
@ -185,21 +185,21 @@ func usage() {
|
||||
fmt.Fprintf(w, "\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, "Websocket with a specified proxy protocol:\n")
|
||||
fmt.Fprintf(w, " ws://host:port[/path],scheme://\n")
|
||||
fmt.Fprintf(w, " ws://host:port[/path],http://[user:pass@]\n")
|
||||
fmt.Fprintf(w, " ws://host:port[/path],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],scheme://\n")
|
||||
fmt.Fprintf(w, " ws://host:port[/path][?host=HOST],http://[user:pass@]\n")
|
||||
fmt.Fprintf(w, " ws://host:port[/path][?host=HOST],socks5://[user:pass@]\n")
|
||||
fmt.Fprintf(w, " ws://host:port[/path][?host=HOST],vmess://[security:]uuid@?alterID=num\n")
|
||||
fmt.Fprintf(w, "\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],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],vmess://[security:]uuid@?alterID=num\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[?host=HOST]],http://[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[?host=HOST]],vmess://[security:]uuid@?alterID=num\n")
|
||||
fmt.Fprintf(w, "\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 {
|
||||
qtype := ""
|
||||
var qtype string
|
||||
switch q.QTYPE {
|
||||
case QTypeA:
|
||||
qtype = "A"
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
type WS struct {
|
||||
dialer proxy.Dialer
|
||||
addr string
|
||||
host string
|
||||
|
||||
client *Client
|
||||
}
|
||||
@ -27,7 +28,7 @@ func init() {
|
||||
func NewWS(s string, d proxy.Dialer) (*WS, error) {
|
||||
u, err := url.Parse(s)
|
||||
if err != nil {
|
||||
log.F("parse url err: %s", err)
|
||||
log.F("[ws] parse url err: %s", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -38,21 +39,26 @@ func NewWS(s string, d proxy.Dialer) (*WS, error) {
|
||||
addr = d.Addr()
|
||||
}
|
||||
|
||||
colonPos := strings.LastIndex(addr, ":")
|
||||
if colonPos == -1 {
|
||||
colonPos = len(addr)
|
||||
query := u.Query()
|
||||
host := query.Get("host")
|
||||
if host == "" {
|
||||
colonPos := strings.LastIndex(addr, ":")
|
||||
if colonPos == -1 {
|
||||
colonPos = len(addr)
|
||||
}
|
||||
host = addr[:colonPos]
|
||||
}
|
||||
serverName := addr[:colonPos]
|
||||
|
||||
client, err := NewClient(serverName, u.Path)
|
||||
client, err := NewClient(host, u.Path)
|
||||
if err != nil {
|
||||
log.F("create ws client err: %s", err)
|
||||
log.F("[ws] create ws client error: %s", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
p := &WS{
|
||||
dialer: d,
|
||||
addr: addr,
|
||||
host: host,
|
||||
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.
|
||||
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 {
|
||||
config *Config
|
||||
fwdrs priSlice
|
||||
avail []*Forwarder // avaliable forwarders
|
||||
avail []*Forwarder // available forwarders
|
||||
mu sync.RWMutex
|
||||
index uint32
|
||||
priority uint32
|
||||
|
Loading…
Reference in New Issue
Block a user