@@ -6,10 +6,8 @@ import (
6
6
"fmt"
7
7
"io"
8
8
"log/slog"
9
- "net"
10
9
"net/http"
11
10
"net/url"
12
- "strings"
13
11
"time"
14
12
15
13
"boundary/rules"
@@ -110,12 +108,6 @@ func (p *ProxyServer) handleHTTP(w http.ResponseWriter, r *http.Request) {
110
108
return
111
109
}
112
110
113
- // Handle CONNECT method for HTTPS tunneling
114
- if r .Method == http .MethodConnect {
115
- p .handleConnect (w , r )
116
- return
117
- }
118
-
119
111
// Forward regular HTTP request
120
112
p .forwardHTTPRequest (w , r )
121
113
}
@@ -139,51 +131,6 @@ func (p *ProxyServer) handleHTTPS(w http.ResponseWriter, r *http.Request) {
139
131
p .forwardHTTPSRequest (w , r )
140
132
}
141
133
142
- // handleConnect handles CONNECT requests for HTTPS tunneling
143
- func (p * ProxyServer ) handleConnect (w http.ResponseWriter , r * http.Request ) {
144
- // Extract host and port
145
- host := r .URL .Host
146
- if ! strings .Contains (host , ":" ) {
147
- host += ":443" // Default HTTPS port
148
- }
149
-
150
- // Check if CONNECT should be allowed
151
- connectURL := fmt .Sprintf ("https://%s" , strings .Split (host , ":" )[0 ])
152
- action := p .ruleEngine .Evaluate ("CONNECT" , connectURL )
153
- if action == rules .Deny {
154
- p .writeBlockedResponse (w , r )
155
- return
156
- }
157
-
158
- // Establish connection to target server
159
- targetConn , err := net .DialTimeout ("tcp" , host , 10 * time .Second )
160
- if err != nil {
161
- http .Error (w , fmt .Sprintf ("Failed to connect to %s: %v" , host , err ), http .StatusBadGateway )
162
- return
163
- }
164
- defer targetConn .Close ()
165
-
166
- // Send 200 Connection Established
167
- w .WriteHeader (http .StatusOK )
168
-
169
- // Get the underlying connection
170
- hijacker , ok := w .(http.Hijacker )
171
- if ! ok {
172
- http .Error (w , "Hijacking not supported" , http .StatusInternalServerError )
173
- return
174
- }
175
-
176
- clientConn , _ , err := hijacker .Hijack ()
177
- if err != nil {
178
- http .Error (w , fmt .Sprintf ("Failed to hijack connection: %v" , err ), http .StatusInternalServerError )
179
- return
180
- }
181
- defer clientConn .Close ()
182
-
183
- // Relay data between client and target
184
- p .relayConnections (clientConn , targetConn )
185
- }
186
-
187
134
// forwardHTTPRequest forwards a regular HTTP request
188
135
func (p * ProxyServer ) forwardHTTPRequest (w http.ResponseWriter , r * http.Request ) {
189
136
// Create a new request to the target server
@@ -322,24 +269,4 @@ To allow this request, restart boundary with:
322
269
For more help: https://github.com/coder/boundary
323
270
` ,
324
271
r .Method , r .URL .Path , host , host , r .Method , host , r .Method )
325
- }
326
-
327
- // relayConnections relays data between two connections
328
- func (p * ProxyServer ) relayConnections (client , target net.Conn ) {
329
- done := make (chan struct {}, 2 )
330
-
331
- // Client to target
332
- go func () {
333
- defer func () { done <- struct {}{} }()
334
- io .Copy (target , client )
335
- }()
336
-
337
- // Target to client
338
- go func () {
339
- defer func () { done <- struct {}{} }()
340
- io .Copy (client , target )
341
- }()
342
-
343
- // Wait for one direction to finish
344
- <- done
345
272
}
0 commit comments