MCPcopy Create free account
hub / github.com/bepass-org/proxy / handleHTTP

Method handleHTTP

pkg/http/server.go:134–181  ·  view source on GitHub ↗
(conn net.Conn, req *http.Request, isConnectMethod bool)

Source from the content-addressed store, hash-verified

132}
133
134func (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
183func (s *Server) embedHandleHTTP(conn net.Conn, req *http.Request, isConnectMethod bool) error {
184 defer func() {

Callers 1

ServeConnMethod · 0.95

Calls 2

embedHandleHTTPMethod · 0.95
WriteMethod · 0.45

Tested by

no test coverage detected