func (proxy *ProxyServer) handleHTTPS(w http.ResponseWriter, r *http.Request) {

	// Hijack TCP connection underlaying the client's request to transfer HTTPS stream
	clientConn, err := hijackConnection(w)
	if err != nil {
		// We might not be able to send an HTTP error to the client...
		httpError(w, "Failed to hijack a client connection", http.StatusInternalServerError, err)
		return
	}

	// Connect to the remote server
	serverConn, err := net.Dial("tcp", r.Host)
	if err != nil {
		klog("Failed to connecto the remote server : %v", err)
		clientConn.Write([]byte("HTTP/1.0 502 Bad Gateway\r\n\r\n"))
		clientConn.Close()
		return
	}

	klog("HTTPS: Connected to the remote server [%s]", serverConn.RemoteAddr().String())

	// Since now we have a TCP connection to the remote server,
	// return "200 OK" to the client's CONNECT method.
	clientConn.Write([]byte("HTTP/1.0 200 OK\r\n\r\n"))

	// Transfer TCP stream from client to server, and vice versa.
	go func() {
		var wg sync.WaitGroup

		wg.Add(1)
		go proxy.transferData(clientConn, serverConn, &wg)
		wg.Add(1)
		go proxy.transferData(serverConn, clientConn, &wg)

		wg.Wait()

		clientConn.Close()
		serverConn.Close()

		klog("HTTPS: A request to the remote server [%s] was done", serverConn.RemoteAddr().String())
	}()
}
// handleHTTPS handles CONNECT method and subsequent requests with MITM disabled.
handleHTTPS handles CONNECT method and subsequent requests with MITM disabled.
// handleHTTPS handles CONNECT method and subsequent requests with MITM disabled .
func (proxy *ProxyServer) handleHTTPS(w http.ResponseWriter, r *http.Request) {
	clientConn, err := hijackConnection(w)
	if err != nil {
		httpError(w, "Failed to hijack a client connection", http.StatusInternalServerError, err)
		return
	}
	serverConn, err := net.Dial("tcp", r.Host)
	if err != nil {
		klog("Failed to connecto the remote server : %v", err)
		clientConn.Write([]byte("HTTP/1.0 502 Bad Gateway\r\n\r\n"))
		clientConn.Close()
		return
	}
	klog("HTTPS: Connected to the remote server [%s]", serverConn.RemoteAddr().String())
	clientConn.Write([]byte("HTTP/1.0 200 OK\r\n\r\n"))
	go func() {
		var wg sync.WaitGroup
		wg.Add(1)
		go proxy.transferData(clientConn, serverConn, &wg)
		wg.Add(1)
		go proxy.transferData(serverConn, clientConn, &wg)
		wg.Wait()
		clientConn.Close()
		serverConn.Close()
		klog("HTTPS: A request to the remote server [%s] was done", serverConn.RemoteAddr().String())
	}()
}
func ( proxy * ProxyServer ) handleHTTPS ( w http . ResponseWriter , r * http . Request ) { clientConn , err := hijackConnection ( w ) if err != nil { httpError ( w , " " , http . StatusInternalServerError , err ) return } serverConn , err := net . Dial ( " " , r . Host ) if err != nil { klog ( " " , err ) clientConn . Write ( [ ] byte ( " \r \n \r \n " ) ) clientConn . Close ( ) return } klog ( " " , serverConn . RemoteAddr ( ) . String ( ) ) clientConn . Write ( [ ] byte ( " \r \n \r \n " ) ) go func ( ) { var wg sync . WaitGroup wg . Add ( 1 ) go proxy . transferData ( clientConn , serverConn , & wg ) wg . Add ( 1 ) go proxy . transferData ( serverConn , clientConn , & wg ) wg . Wait ( ) clientConn . Close ( ) serverConn . Close ( ) klog ( " " , serverConn . RemoteAddr ( ) . String ( ) ) } ( ) }
handleHTTPS handles CONNECT method and subsequent requests with MITM disabled.
handleHTTPS handles CONNECT method and subsequent requests with MITM disabled .
// Hijack TCP connection underlaying the client's request to transfer HTTPS stream // We might not be able to send an HTTP error to the client... // Connect to the remote server // Since now we have a TCP connection to the remote server, // return "200 OK" to the client's CONNECT method. // Transfer TCP stream from client to server, and vice versa.