(conn net.Conn)
| 113 | } |
| 114 | |
| 115 | func (p *SocketProxy) Proxy(conn net.Conn) error { |
| 116 | var ( |
| 117 | socketConn SocketConn |
| 118 | err error |
| 119 | ) |
| 120 | |
| 121 | socketConn.Timeout = p.options.Timeout |
| 122 | socketConn.Verbosity = p.options.Verbosity |
| 123 | socketConn.OutputHex = p.options.OutputHex |
| 124 | |
| 125 | socketConn.lconn = conn |
| 126 | defer func() { |
| 127 | _ = socketConn.lconn.Close() |
| 128 | }() |
| 129 | |
| 130 | if p.options.TLSClient { |
| 131 | config := &tls.Config{ |
| 132 | InsecureSkipVerify: true, |
| 133 | } |
| 134 | if p.options.TLSClientConfig != nil { |
| 135 | config = p.options.TLSClientConfig |
| 136 | } |
| 137 | socketConn.rconn, err = tls.Dial("tcp", p.options.RemoteAddress, config) |
| 138 | } else { |
| 139 | socketConn.rconn, err = net.Dial("tcp", p.options.RemoteAddress) |
| 140 | } |
| 141 | if err != nil { |
| 142 | log.Println(err) |
| 143 | return nil |
| 144 | } |
| 145 | |
| 146 | defer func() { |
| 147 | _ = socketConn.rconn.Close() |
| 148 | }() |
| 149 | |
| 150 | if p.options.HTTPProxy != "" { |
| 151 | proxyURL, err := url.Parse(p.options.HTTPProxy) |
| 152 | if err != nil { |
| 153 | return nil |
| 154 | } |
| 155 | socketConn.httpclient = &http.Client{ |
| 156 | Transport: &http.Transport{ |
| 157 | Proxy: http.ProxyURL(proxyURL), |
| 158 | }, |
| 159 | } |
| 160 | socketConn.HTTPServer = p.options.HTTPServer |
| 161 | } |
| 162 | |
| 163 | socketConn.OnRequest = p.options.OnRequest |
| 164 | socketConn.OnResponse = p.options.OnResponse |
| 165 | |
| 166 | socketConn.RequestMatchReplaceDSL = p.options.RequestMatchReplaceDSL |
| 167 | socketConn.ResponseMatchReplaceDSL = p.options.ResponseMatchReplaceDSL |
| 168 | |
| 169 | socketConn.errsig = make(chan bool) |
| 170 | socketConn.fullduplex() |
| 171 | |
| 172 | return nil |
no test coverage detected