Skip to content

Commit 8b0b93e

Browse files
fix: https and ignore redirects
1 parent 6f121bf commit 8b0b93e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

proxy/proxy.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,7 @@ func (p *Server) handleHTTPConnection(conn net.Conn) {
169169

170170
func (p *Server) handleTLSConnection(conn net.Conn) {
171171
// Create TLS connection
172-
tlsConn := tls.Server(conn, &tls.Config{
173-
InsecureSkipVerify: true, // For demo purposes
174-
// In production, you'd need proper certificates
175-
})
172+
tlsConn := tls.Server(conn, p.tlsConfig)
176173

177174
// Perform TLS handshake
178175
if err := tlsConn.Handshake(); err != nil {
@@ -183,7 +180,7 @@ func (p *Server) handleTLSConnection(conn net.Conn) {
183180
log.Println("✅ TLS handshake successful")
184181

185182
// Read HTTP request over TLS
186-
req, err := http.ReadRequest(bufio.NewReader(conn))
183+
req, err := http.ReadRequest(bufio.NewReader(tlsConn))
187184
if err != nil {
188185
log.Printf("Failed to read HTTPS request: %v", err)
189186
return
@@ -199,7 +196,11 @@ func (p *Server) handleTLSConnection(conn net.Conn) {
199196

200197
func (p *Server) forwardHTTPRequest(conn net.Conn, req *http.Request) {
201198
// Create HTTP client
202-
client := &http.Client{}
199+
client := &http.Client{
200+
CheckRedirect: func(req *http.Request, via []*http.Request) error {
201+
return http.ErrUseLastResponse // Don't follow redirects
202+
},
203+
}
203204

204205
req.RequestURI = ""
205206

@@ -235,6 +236,9 @@ func (p *Server) forwardHTTPSRequest(conn net.Conn, req *http.Request) {
235236
InsecureSkipVerify: true, // For demo purposes
236237
},
237238
},
239+
CheckRedirect: func(req *http.Request, via []*http.Request) error {
240+
return http.ErrUseLastResponse // Don't follow redirects
241+
},
238242
}
239243

240244
req.RequestURI = ""

0 commit comments

Comments
 (0)