mirror of
https://github.com/nadoo/glider.git
synced 2025-02-23 17:35:40 +08:00
http: fix potential problem
This commit is contained in:
parent
c6a879dded
commit
51fedc8653
36
README.md
36
README.md
@ -290,7 +290,7 @@ Examples:
|
|||||||
-listen on :1080 as a socks5 proxy server, in verbose mode.
|
-listen on :1080 as a socks5 proxy server, in verbose mode.
|
||||||
|
|
||||||
glider -listen tls://:443?cert=crtFilePath&key=keyFilePath,http:// -verbose
|
glider -listen tls://:443?cert=crtFilePath&key=keyFilePath,http:// -verbose
|
||||||
-listen on :443 as a https proxy server.
|
-listen on :443 as a https(http over tls) proxy server.
|
||||||
|
|
||||||
glider -listen http://:8080 -forward socks5://127.0.0.1:1080
|
glider -listen http://:8080 -forward socks5://127.0.0.1:1080
|
||||||
-listen on :8080 as a http proxy server, forward all requests via socks5 server.
|
-listen on :8080 as a http proxy server, forward all requests via socks5 server.
|
||||||
@ -338,6 +338,40 @@ Examples:
|
|||||||
- [transparent proxy with dnsmasq](config/examples/8.transparent_proxy_with_dnsmasq)
|
- [transparent proxy with dnsmasq](config/examples/8.transparent_proxy_with_dnsmasq)
|
||||||
- [transparent proxy without dnsmasq](config/examples/9.transparent_proxy_without_dnsmasq)
|
- [transparent proxy without dnsmasq](config/examples/9.transparent_proxy_without_dnsmasq)
|
||||||
|
|
||||||
|
### Forwarder Chain
|
||||||
|
In glider, you can easily chain several proxy servers or protocols together, e.g:
|
||||||
|
|
||||||
|
- Chain proxy servers:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
forward=http://1.1.1.1:80,socks5://2.2.2.2:1080,ss://method:pass@3.3.3.3:8443@
|
||||||
|
```
|
||||||
|
|
||||||
|
- Chain protocols: https proxy (http over tls)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
forward=tls://1.1.1.1:443,http://
|
||||||
|
```
|
||||||
|
|
||||||
|
- Chain protocols: vmess over ws over tls
|
||||||
|
|
||||||
|
```bash
|
||||||
|
forward=tls://1.1.1.1:443,ws://,vmess://5a146038-0b56-4e95-b1dc-5c6f5a32cd98@?alterID=2
|
||||||
|
```
|
||||||
|
|
||||||
|
- Chain protocols and servers:
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
forward=socks5://1.1.1.1:1080,tls://2.2.2.2:443,ws://,vmess://5a146038-0b56-4e95-b1dc-5c6f5a32cd98@?alterID=2
|
||||||
|
```
|
||||||
|
|
||||||
|
- Chain protocols in listener: https proxy server
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
listen=tls://:443?cert=crtFilePath&key=keyFilePath,http://
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Service
|
## Service
|
||||||
|
|
||||||
- systemd: [https://github.com/nadoo/glider/blob/master/systemd/](https://github.com/nadoo/glider/blob/master/systemd/)
|
- systemd: [https://github.com/nadoo/glider/blob/master/systemd/](https://github.com/nadoo/glider/blob/master/systemd/)
|
||||||
|
@ -17,25 +17,30 @@ type Conn struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewConn .
|
// NewConn .
|
||||||
func NewConn(c net.Conn) Conn {
|
func NewConn(c net.Conn) *Conn {
|
||||||
return Conn{bufio.NewReader(c), c}
|
return &Conn{bufio.NewReader(c), c}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConnSize .
|
// NewConnSize .
|
||||||
func NewConnSize(c net.Conn, n int) Conn {
|
func NewConnSize(c net.Conn, n int) *Conn {
|
||||||
return Conn{bufio.NewReaderSize(c, n), c}
|
return &Conn{bufio.NewReaderSize(c, n), c}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peek .
|
// Peek .
|
||||||
func (c Conn) Peek(n int) ([]byte, error) {
|
func (c *Conn) Peek(n int) ([]byte, error) {
|
||||||
return c.r.Peek(n)
|
return c.r.Peek(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read .
|
// Read .
|
||||||
func (c Conn) Read(p []byte) (int, error) {
|
func (c *Conn) Read(p []byte) (int, error) {
|
||||||
return c.r.Read(p)
|
return c.r.Read(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reader returns the internal bufio.Reader
|
||||||
|
func (c *Conn) Reader() *bufio.Reader {
|
||||||
|
return c.r
|
||||||
|
}
|
||||||
|
|
||||||
// Relay .
|
// Relay .
|
||||||
func Relay(left, right net.Conn) (int64, int64, error) {
|
func Relay(left, right net.Conn) (int64, int64, error) {
|
||||||
type res struct {
|
type res struct {
|
||||||
|
2
conf.go
2
conf.go
@ -266,7 +266,7 @@ func usage() {
|
|||||||
fmt.Fprintf(os.Stderr, " -listen on :1080 as a socks5 proxy server, in verbose mode.\n")
|
fmt.Fprintf(os.Stderr, " -listen on :1080 as a socks5 proxy server, in verbose mode.\n")
|
||||||
fmt.Fprintf(os.Stderr, "\n")
|
fmt.Fprintf(os.Stderr, "\n")
|
||||||
fmt.Fprintf(os.Stderr, " "+app+" -listen tls://:443?cert=crtFilePath&key=keyFilePath,http:// -verbose\n")
|
fmt.Fprintf(os.Stderr, " "+app+" -listen tls://:443?cert=crtFilePath&key=keyFilePath,http:// -verbose\n")
|
||||||
fmt.Fprintf(os.Stderr, " -listen on :443 as a https proxy server.\n")
|
fmt.Fprintf(os.Stderr, " -listen on :443 as a https(http over tls) proxy server.\n")
|
||||||
fmt.Fprintf(os.Stderr, "\n")
|
fmt.Fprintf(os.Stderr, "\n")
|
||||||
fmt.Fprintf(os.Stderr, " "+app+" -listen http://:8080 -forward socks5://127.0.0.1:1080\n")
|
fmt.Fprintf(os.Stderr, " "+app+" -listen http://:8080 -forward socks5://127.0.0.1:1080\n")
|
||||||
fmt.Fprintf(os.Stderr, " -listen on :8080 as a http proxy server, forward all requests via socks5 server.\n")
|
fmt.Fprintf(os.Stderr, " -listen on :8080 as a http proxy server, forward all requests via socks5 server.\n")
|
||||||
|
@ -251,17 +251,20 @@ func (s *HTTP) Dial(network, addr string) (net.Conn, error) {
|
|||||||
|
|
||||||
// header ended
|
// header ended
|
||||||
buf.Write([]byte("\r\n"))
|
buf.Write([]byte("\r\n"))
|
||||||
rc.Write(buf.Bytes())
|
_, err = rc.Write(buf.Bytes())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
respR := bufio.NewReader(rc)
|
c := conn.NewConn(rc)
|
||||||
respTP := textproto.NewReader(respR)
|
tpr := textproto.NewReader(c.Reader())
|
||||||
|
_, code, _, ok := parseFirstLine(tpr)
|
||||||
_, code, _, ok := parseFirstLine(respTP)
|
|
||||||
if ok && code == "200" {
|
if ok && code == "200" {
|
||||||
// TODO: check here
|
tpr.ReadMIMEHeader()
|
||||||
respTP.ReadMIMEHeader()
|
return c, err
|
||||||
return rc, err
|
}
|
||||||
} else if code == "407" {
|
|
||||||
|
if code == "407" {
|
||||||
log.F("[http] authencation needed by proxy %s", s.addr)
|
log.F("[http] authencation needed by proxy %s", s.addr)
|
||||||
} else if code == "405" {
|
} else if code == "405" {
|
||||||
log.F("[http] 'CONNECT' method not allowed by proxy %s", s.addr)
|
log.F("[http] 'CONNECT' method not allowed by proxy %s", s.addr)
|
||||||
@ -280,7 +283,7 @@ func parseFirstLine(tp *textproto.Reader) (r1, r2, r3 string, ok bool) {
|
|||||||
line, err := tp.ReadLine()
|
line, err := tp.ReadLine()
|
||||||
// log.F("first line: %s", line)
|
// log.F("first line: %s", line)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.F("[http] read first line error:%s", err)
|
// log.F("[http] read first line error:%s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,6 +168,7 @@ func (s *KCP) ListenAndServe() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: change them to customizable later?
|
||||||
c.SetStreamMode(true)
|
c.SetStreamMode(true)
|
||||||
c.SetWriteDelay(false)
|
c.SetWriteDelay(false)
|
||||||
c.SetNoDelay(0, 30, 2, 1)
|
c.SetNoDelay(0, 30, 2, 1)
|
||||||
@ -204,6 +205,7 @@ func (s *KCP) Dial(network, addr string) (net.Conn, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: change them to customizable later?
|
||||||
c.SetStreamMode(true)
|
c.SetStreamMode(true)
|
||||||
c.SetWriteDelay(false)
|
c.SetWriteDelay(false)
|
||||||
c.SetNoDelay(0, 30, 2, 1)
|
c.SetNoDelay(0, 30, 2, 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user