(conn net.Conn, req *http.Request, isConnectMethod bool)
| 132 | } |
| 133 | |
| 134 | func (s *Server) handleHTTP(conn net.Conn, req *http.Request, isConnectMethod bool) error { |
| 135 | if s.UserConnectHandle == nil { |
| 136 | return s.embedHandleHTTP(conn, req, isConnectMethod) |
| 137 | } |
| 138 | |
| 139 | if isConnectMethod { |
| 140 | _, err := conn.Write([]byte("HTTP/1.1 200 Connection Established\r\n\r\n")) |
| 141 | if err != nil { |
| 142 | return err |
| 143 | } |
| 144 | } else { |
| 145 | cConn := &customConn{ |
| 146 | Conn: conn, |
| 147 | req: req, |
| 148 | } |
| 149 | conn = cConn |
| 150 | } |
| 151 | |
| 152 | targetAddr := req.URL.Host |
| 153 | host, portStr, err := net.SplitHostPort(targetAddr) |
| 154 | if err != nil { |
| 155 | host = targetAddr |
| 156 | if req.URL.Scheme == "https" || isConnectMethod { |
| 157 | portStr = "443" |
| 158 | } else { |
| 159 | portStr = "80" |
| 160 | } |
| 161 | targetAddr = net.JoinHostPort(host, portStr) |
| 162 | } |
| 163 | |
| 164 | portInt, err := strconv.Atoi(portStr) |
| 165 | if err != nil { |
| 166 | return err // Handle the error if the port string is not a valid integer. |
| 167 | } |
| 168 | port := int32(portInt) |
| 169 | |
| 170 | proxyReq := &statute.ProxyRequest{ |
| 171 | Conn: conn, |
| 172 | Reader: io.Reader(conn), |
| 173 | Writer: io.Writer(conn), |
| 174 | Network: "tcp", |
| 175 | Destination: targetAddr, |
| 176 | DestHost: host, |
| 177 | DestPort: port, |
| 178 | } |
| 179 | |
| 180 | return s.UserConnectHandle(proxyReq) |
| 181 | } |
| 182 | |
| 183 | func (s *Server) embedHandleHTTP(conn net.Conn, req *http.Request, isConnectMethod bool) error { |
| 184 | defer func() { |
no test coverage detected