(c net.Conn)
| 55 | func (c *Conn) SetWriteDeadline(t time.Time) error { return c.Conn.SetWriteDeadline(t) } |
| 56 | |
| 57 | func NewProxyConn(c net.Conn) *Conn { |
| 58 | _, port, err := net.SplitHostPort(c.LocalAddr().String()) |
| 59 | |
| 60 | if err != nil { |
| 61 | log.Println("invalid forward port") |
| 62 | return nil |
| 63 | } |
| 64 | |
| 65 | // proxy src:local-ip4 to dst:remote-ip4 / src:local-ip6 to dst:remote-ip6 |
| 66 | typ, _ := tcp4or6(c.LocalAddr()) |
| 67 | |
| 68 | br := bufio.NewReader(c) |
| 69 | |
| 70 | httpHostName := httpHostHeader(br) |
| 71 | sniServerName := clientHelloServerName(br) |
| 72 | |
| 73 | var upstream string |
| 74 | if len(httpHostName) > 0 { |
| 75 | upstream = httpHostName |
| 76 | } else if len(sniServerName) > 0 { |
| 77 | upstream = sniServerName |
| 78 | } else { |
| 79 | fmt.Printf("host/sni missing %s %s\n", c.LocalAddr(), c.RemoteAddr()) |
| 80 | } |
| 81 | |
| 82 | peeked, _ := br.Peek(br.Buffered()) |
| 83 | |
| 84 | return &Conn{ |
| 85 | Typ: typ, // tcp or tcp4 or tcp6 |
| 86 | HostName: upstream, // may be nil |
| 87 | Port: port, |
| 88 | Peeked: peeked, // len may be 0 |
| 89 | Conn: c, |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | func (src *Conn) Forward() { |
| 94 | defer src.Close() |
no test coverage detected