@@ -18,7 +18,7 @@ import (
1818// It is responsible for:
1919// - intercepting HTTPS requests to AI providers
2020// - decrypting requests using the configured CA certificate
21- // - forwarding requests toaibridge for processing
21+ // - forwarding requests toaibridged for processing
2222type Server struct {
2323logger slog.Logger
2424proxy * goproxy.ProxyHttpServer
@@ -55,8 +55,7 @@ func New(ctx context.Context, logger slog.Logger, opts Options) (*Server, error)
5555
5656// Decrypt all HTTPS requests via MITM. Requests are forwarded to
5757// the original destination without modification for now.
58- // TODO(ssncferreira): Route requests to aibridged
59- // will be implemented upstack.
58+ // TODO(ssncferreira): Route requests to aibridged will be implemented upstack.
6059// Related to https://github.com/coder/internal/issues/1181
6160proxy .OnRequest ().HandleConnect (goproxy .AlwaysMitm )
6261
@@ -82,6 +81,16 @@ func New(ctx context.Context, logger slog.Logger, opts Options) (*Server, error)
8281return srv ,nil
8382}
8483
84+ // Close gracefully shuts down the proxy server.
85+ func (s * Server )Close ()error {
86+ if s .httpServer == nil {
87+ return nil
88+ }
89+ ctx ,cancel := context .WithTimeout (context .Background (),5 * time .Second )
90+ defer cancel ()
91+ return s .httpServer .Shutdown (ctx )
92+ }
93+
8594// loadMitmCertificate loads the CA certificate and key for MITM into goproxy.
8695func loadMitmCertificate (certFile ,keyFile string )error {
8796tlsCert ,err := tls .LoadX509KeyPair (certFile ,keyFile )
@@ -102,13 +111,3 @@ func loadMitmCertificate(certFile, keyFile string) error {
102111
103112return nil
104113}
105-
106- // Close gracefully shuts down the proxy server.
107- func (s * Server )Close ()error {
108- if s .httpServer == nil {
109- return nil
110- }
111- ctx ,cancel := context .WithTimeout (context .Background (),5 * time .Second )
112- defer cancel ()
113- return s .httpServer .Shutdown (ctx )
114- }