Initial commit
This commit is contained in:
33
internal/domains/deconnector/connect.go
Normal file
33
internal/domains/deconnector/connect.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package deconnector
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func (d *Deconnector) handleDeconnect(clientConn net.Conn, connectReq *http.Request, upstreamURL *url.URL) {
|
||||
// Tell client the tunnel is open
|
||||
fmt.Fprintf(clientConn, "HTTP/1.1 200 Connection established\r\n\r\n")
|
||||
|
||||
// Read the real HTTP request the client sends through the tunnel
|
||||
innerReq, err := http.ReadRequest(bufio.NewReader(clientConn))
|
||||
if err != nil {
|
||||
log.Printf("failed to read inner request after CONNECT:80: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
innerReq.URL.Scheme = "http"
|
||||
innerReq.URL.Host = connectReq.Host
|
||||
innerReq.RequestURI = ""
|
||||
|
||||
d.app.Logger().
|
||||
WithField("method", innerReq.Method).
|
||||
WithField("url", innerReq.URL).
|
||||
Info("Handling de-CONNECT request")
|
||||
|
||||
d.forwardHTTP(clientConn, innerReq, upstreamURL)
|
||||
}
|
||||
Reference in New Issue
Block a user