Hold Go's server privately in waf.Server and rproxy.Server (closes #437)
check / check (push) Waiting to run
check / check (push) Waiting to run
Neither Server embeds *http.Server any more. Each holds it as a private field, is its handler, and has Serve, Shutdown, Close and ServeHTTP. sww's serve hook takes the new daemonServer interface of those first three, and fx provides each Server as it. Model: opus-5-5
This commit was merged in pull request #481.
This commit is contained in:
1 parent
9afbd1b683
commit
1b9ca94774
15 files changed
+134
-54
No files matched your search
+36
-13
@@ -16,6 +16,7 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
@@ -63,9 +64,8 @@ type Params struct {
|
||||
|
||||
// Server is the server `sww rproxy` runs.
|
||||
type Server struct {
|
||||
*http.Server
|
||||
|
||||
h *handler
|
||||
httpServer *http.Server
|
||||
h *handler
|
||||
}
|
||||
|
||||
// New returns the server `sww rproxy` runs. Go's server itself refuses
|
||||
@@ -94,17 +94,40 @@ func New(params Params) *Server {
|
||||
breakerClock: time.Now,
|
||||
}
|
||||
|
||||
return &Server{
|
||||
Server: &http.Server{
|
||||
Addr: params.Config.ListenAddr,
|
||||
Handler: h,
|
||||
ErrorLog: errorLog,
|
||||
ReadHeaderTimeout: params.Config.MaxRequestTime,
|
||||
IdleTimeout: idleTimeout,
|
||||
MaxHeaderBytes: requestHeaderMaxBytes - goServerExtraHeaderBytes,
|
||||
},
|
||||
h: h,
|
||||
s := &Server{h: h}
|
||||
s.httpServer = &http.Server{
|
||||
Addr: params.Config.ListenAddr,
|
||||
Handler: s,
|
||||
ErrorLog: errorLog,
|
||||
ReadHeaderTimeout: params.Config.MaxRequestTime,
|
||||
IdleTimeout: idleTimeout,
|
||||
MaxHeaderBytes: requestHeaderMaxBytes - goServerExtraHeaderBytes,
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// Serve serves requests on listener until Shutdown or Close, as Go's
|
||||
// http.Server.Serve does.
|
||||
func (s *Server) Serve(listener net.Listener) error {
|
||||
return s.httpServer.Serve(listener)
|
||||
}
|
||||
|
||||
// Shutdown stops serving once the requests in progress have finished, or
|
||||
// when ctx is done, as Go's http.Server.Shutdown does.
|
||||
func (s *Server) Shutdown(ctx context.Context) error {
|
||||
return s.httpServer.Shutdown(ctx)
|
||||
}
|
||||
|
||||
// Close stops serving at once and closes every connection, as Go's
|
||||
// http.Server.Close does.
|
||||
func (s *Server) Close() error {
|
||||
return s.httpServer.Close()
|
||||
}
|
||||
|
||||
// ServeHTTP handles one request from a visitor, as handler.ServeHTTP says.
|
||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
s.h.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
// WaitForReports returns once the reports being sent have gone or failed,
|
||||
|
||||
Reference in new issue
Block a user