@@ -12,7 +12,6 @@ import (
1212 "net/url"
1313 "strings"
1414 "sync"
15- "time"
1615
1716 "github.com/coder/boundary/audit"
1817 "github.com/coder/boundary/rules"
@@ -26,7 +25,7 @@ type Server struct {
2625 tlsConfig * tls.Config
2726 httpPort int
2827
29- httpServer * http. Server
28+ listener net. Listener
3029}
3130
3231// Config holds configuration for the proxy server
@@ -51,27 +50,22 @@ func NewProxyServer(config Config) *Server {
5150
5251// Start starts the HTTP proxy server with TLS termination capability
5352func (p * Server ) Start (ctx context.Context ) error {
54- // Create HTTP server with TLS termination capability
55- p .httpServer = & http.Server {
56- Addr : fmt .Sprintf (":%d" , p .httpPort ),
57- Handler : http .HandlerFunc (p .handleHTTPWithTLSTermination ),
58- }
59-
6053 // Start HTTP server with custom listener for TLS detection
6154 go func () {
6255 p .logger .Info ("Starting HTTP proxy with TLS termination" , "port" , p .httpPort )
63- listener , err := net .Listen ("tcp" , fmt .Sprintf (":%d" , p .httpPort ))
56+ var err error
57+ p .listener , err = net .Listen ("tcp" , fmt .Sprintf (":%d" , p .httpPort ))
6458 if err != nil {
6559 p .logger .Error ("Failed to create HTTP listener" , "error" , err )
6660 return
6761 }
6862
6963 for {
70- conn , err := listener .Accept ()
64+ conn , err := p . listener .Accept ()
7165 if err != nil {
7266 select {
7367 case <- ctx .Done ():
74- err = listener .Close ()
68+ err = p . listener .Close ()
7569 if err != nil {
7670 p .logger .Error ("Failed to close listener" , "error" , err )
7771 }
@@ -94,17 +88,17 @@ func (p *Server) Start(ctx context.Context) error {
9488
9589// Stops proxy server
9690func (p * Server ) Stop () error {
97- ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
98- defer cancel ()
99-
100- var httpErr error
101- if p .httpServer != nil {
102- httpErr = p .httpServer .Shutdown (ctx )
91+ if p .listener == nil {
92+ return nil
10393 }
10494
105- if httpErr != nil {
106- return httpErr
95+ err := p .listener .Close ()
96+ if err != nil {
97+ p .logger .Error ("Failed to close listener" , "error" , err )
10798 }
99+
100+ fmt .Printf ("STOP is finished\n " )
101+
108102 return nil
109103}
110104
@@ -479,13 +473,6 @@ func (p *Server) handleConnectionWithTLSDetection(conn net.Conn) {
479473 }
480474}
481475
482- // handleHTTPWithTLSTermination is the main handler (currently just delegates to regular HTTP)
483- func (p * Server ) handleHTTPWithTLSTermination (w http.ResponseWriter , r * http.Request ) {
484- // This handler is not used when we do custom connection handling
485- // All traffic goes through handleConnectionWithTLSDetection
486- p .handleHTTP (w , r )
487- }
488-
489476// connectionWrapper lets us "unread" the peeked byte
490477type connectionWrapper struct {
491478 net.Conn
0 commit comments