@@ -12,7 +12,6 @@ import (
12
12
"net/url"
13
13
"strings"
14
14
"sync"
15
- "time"
16
15
17
16
"github.com/coder/boundary/audit"
18
17
"github.com/coder/boundary/rules"
@@ -26,7 +25,7 @@ type Server struct {
26
25
tlsConfig * tls.Config
27
26
httpPort int
28
27
29
- httpServer * http. Server
28
+ listener net. Listener
30
29
}
31
30
32
31
// Config holds configuration for the proxy server
@@ -51,27 +50,22 @@ func NewProxyServer(config Config) *Server {
51
50
52
51
// Start starts the HTTP proxy server with TLS termination capability
53
52
func (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
-
60
53
// Start HTTP server with custom listener for TLS detection
61
54
go func () {
62
55
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 ))
64
58
if err != nil {
65
59
p .logger .Error ("Failed to create HTTP listener" , "error" , err )
66
60
return
67
61
}
68
62
69
63
for {
70
- conn , err := listener .Accept ()
64
+ conn , err := p . listener .Accept ()
71
65
if err != nil {
72
66
select {
73
67
case <- ctx .Done ():
74
- err = listener .Close ()
68
+ err = p . listener .Close ()
75
69
if err != nil {
76
70
p .logger .Error ("Failed to close listener" , "error" , err )
77
71
}
@@ -94,17 +88,17 @@ func (p *Server) Start(ctx context.Context) error {
94
88
95
89
// Stops proxy server
96
90
func (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
103
93
}
104
94
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 )
107
98
}
99
+
100
+ fmt .Printf ("STOP is finished\n " )
101
+
108
102
return nil
109
103
}
110
104
@@ -479,13 +473,6 @@ func (p *Server) handleConnectionWithTLSDetection(conn net.Conn) {
479
473
}
480
474
}
481
475
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
-
489
476
// connectionWrapper lets us "unread" the peeked byte
490
477
type connectionWrapper struct {
491
478
net.Conn
0 commit comments