mirror of
https://github.com/nadoo/glider.git
synced 2025-02-23 01:15:41 +08:00
fixed a bug in upstream http proxy.
This commit is contained in:
parent
0d01e8a4eb
commit
0c5950e9e8
@ -45,7 +45,7 @@ Examples:
|
||||
-listen on :8443, serve as http/socks5 proxy on the same port.
|
||||
|
||||
glider -l ss://AEAD_CHACHA20_POLY1305:pass@:8443
|
||||
-listen on 0.0.0.0:8443 as a shadowsocks server.
|
||||
-listen on 0.0.0.0:8443 as a ss server.
|
||||
|
||||
glider -l socks5://:1080 -v
|
||||
-listen on :1080 as a socks5 proxy server, in verbose mode.
|
||||
@ -102,5 +102,5 @@ systemctl start glider.service
|
||||
```
|
||||
|
||||
## Thanks
|
||||
- [go-shadowsocks2](https://github.com/shadowsocks/go-shadowsocks2): the core ss protocol support
|
||||
- [go-ss2](https://github.com/shadowsocks/go-shadowsocks2): the core ss protocol support
|
||||
- [gost](https://github.com/ginuerzh/gost): ideas and inspirations
|
14
http.go
14
http.go
@ -6,6 +6,7 @@ package main
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
@ -157,6 +158,7 @@ func (s *httpproxy) servHTTPS(method, requestURI, proto string, c net.Conn) {
|
||||
logf("failed to dial: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
c.Write([]byte("HTTP/1.0 200 Connection established\r\n\r\n"))
|
||||
|
||||
logf("proxy-https %s <-> %s", c.RemoteAddr(), requestURI)
|
||||
@ -172,26 +174,26 @@ func (s *httpproxy) servHTTPS(method, requestURI, proto string, c net.Conn) {
|
||||
|
||||
// Dial connects to the address addr on the network net via the proxy.
|
||||
func (s *httpproxy) Dial(network, addr string) (net.Conn, error) {
|
||||
c, err := s.GetProxy().Dial("tcp", s.addr)
|
||||
rc, err := s.GetProxy().Dial("tcp", s.addr)
|
||||
if err != nil {
|
||||
logf("dial to %s error: %s", s.addr, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if c, ok := c.(*net.TCPConn); ok {
|
||||
if c, ok := rc.(*net.TCPConn); ok {
|
||||
c.SetKeepAlive(true)
|
||||
}
|
||||
|
||||
c.Write([]byte("CONNECT " + addr + " HTTP/1.0\r\n"))
|
||||
rc.Write([]byte("CONNECT " + addr + " HTTP/1.0\r\n"))
|
||||
// c.Write([]byte("Proxy-Connection: Keep-Alive\r\n"))
|
||||
|
||||
var b [1024]byte
|
||||
n, err := c.Read(b[:])
|
||||
n, err := rc.Read(b[:])
|
||||
if bytes.Contains(b[:n], []byte("200")) {
|
||||
return c, err
|
||||
return rc, err
|
||||
}
|
||||
|
||||
return nil, err
|
||||
return nil, errors.New("cound not connect remote address:" + addr)
|
||||
}
|
||||
|
||||
// parseFirstLine parses "GET /foo HTTP/1.1" OR "HTTP/1.1 200 OK" into its three parts.
|
||||
|
2
main.go
2
main.go
@ -10,7 +10,7 @@ import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
const version = "0.1.1"
|
||||
const version = "0.1.3"
|
||||
|
||||
var config struct {
|
||||
Verbose bool
|
||||
|
@ -48,7 +48,7 @@ func (p *strategyProxy) NextProxy() Proxy {
|
||||
}
|
||||
|
||||
if !found {
|
||||
logf("NO AVALIABLE PROXY FOUND! please check your network or proxy server settings.")
|
||||
logf("NO AVAILABLE PROXY FOUND! please check your network or proxy server settings.")
|
||||
}
|
||||
|
||||
return p.forwarders[p.idx]
|
||||
|
Loading…
Reference in New Issue
Block a user