mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-07-03 09:47:38 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 705c4f8001 | |||
| d648614611 | |||
| 3f86eb0f06 |
@@ -50,6 +50,10 @@ type ServerInstanceConfig struct {
|
|||||||
// GZIP enables GZIP compression middleware
|
// GZIP enables GZIP compression middleware
|
||||||
GZIP bool `mapstructure:"gzip"`
|
GZIP bool `mapstructure:"gzip"`
|
||||||
|
|
||||||
|
// HTTP2 enables HTTP/2 with the Extended CONNECT protocol (RFC 8441) for WebSocket support.
|
||||||
|
// Requires TLS; pair with SSLCert/SSLKey, SelfSignedSSL, or AutoTLS.
|
||||||
|
HTTP2 bool `mapstructure:"http2"`
|
||||||
|
|
||||||
// TLS/HTTPS configuration options (mutually exclusive)
|
// TLS/HTTPS configuration options (mutually exclusive)
|
||||||
// Option 1: Provide certificate and key files directly
|
// Option 1: Provide certificate and key files directly
|
||||||
SSLCert string `mapstructure:"ssl_cert"`
|
SSLCert string `mapstructure:"ssl_cert"`
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ func FromConfigInstanceToServerConfig(sic *config.ServerInstanceConfig, handler
|
|||||||
Description: sic.Description,
|
Description: sic.Description,
|
||||||
Handler: handler,
|
Handler: handler,
|
||||||
GZIP: sic.GZIP,
|
GZIP: sic.GZIP,
|
||||||
|
HTTP2: sic.HTTP2,
|
||||||
|
|
||||||
SSLCert: sic.SSLCert,
|
SSLCert: sic.SSLCert,
|
||||||
SSLKey: sic.SSLKey,
|
SSLKey: sic.SSLKey,
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ type Config struct {
|
|||||||
// AutoTLSEmail is the email for Let's Encrypt registration (optional but recommended)
|
// AutoTLSEmail is the email for Let's Encrypt registration (optional but recommended)
|
||||||
AutoTLSEmail string
|
AutoTLSEmail string
|
||||||
|
|
||||||
|
// PanicHandler is called when a request handler panics.
|
||||||
|
// If nil, the default middleware.PanicRecovery is used (logs, records metric, returns 500).
|
||||||
|
PanicHandler func(w http.ResponseWriter, r *http.Request, rcv any)
|
||||||
|
|
||||||
// Graceful shutdown configuration
|
// Graceful shutdown configuration
|
||||||
// ShutdownTimeout is the maximum time to wait for graceful shutdown
|
// ShutdownTimeout is the maximum time to wait for graceful shutdown
|
||||||
// Default: 30 seconds
|
// Default: 30 seconds
|
||||||
|
|||||||
+17
-1
@@ -452,8 +452,19 @@ func newInstance(cfg Config) (*serverInstance, error) {
|
|||||||
handler = gz(handler)
|
handler = gz(handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrap with the panic recovery middleware
|
// Wrap with panic recovery — use caller-supplied handler if provided
|
||||||
|
if cfg.PanicHandler != nil {
|
||||||
|
handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
defer func() {
|
||||||
|
if rcv := recover(); rcv != nil {
|
||||||
|
cfg.PanicHandler(w, r, rcv)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
handler.ServeHTTP(w, r)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
handler = middleware.PanicRecovery(handler)
|
handler = middleware.PanicRecovery(handler)
|
||||||
|
}
|
||||||
|
|
||||||
// Configure TLS if any TLS option is enabled
|
// Configure TLS if any TLS option is enabled
|
||||||
tlsConfig, certFile, keyFile, err := configureTLS(cfg)
|
tlsConfig, certFile, keyFile, err := configureTLS(cfg)
|
||||||
@@ -475,6 +486,10 @@ func newInstance(cfg Config) (*serverInstance, error) {
|
|||||||
// The GODEBUG=http2xconnect=1 flag is read by net/http's init(); setting it here
|
// The GODEBUG=http2xconnect=1 flag is read by net/http's init(); setting it here
|
||||||
// ensures it propagates to subprocesses and any future process restarts.
|
// ensures it propagates to subprocesses and any future process restarts.
|
||||||
// For the current process, set GODEBUG=http2xconnect=1 in the environment before launch.
|
// For the current process, set GODEBUG=http2xconnect=1 in the environment before launch.
|
||||||
|
if httpServer.Protocols == nil {
|
||||||
|
httpServer.Protocols = &http.Protocols{}
|
||||||
|
httpServer.Protocols.SetHTTP1(true)
|
||||||
|
}
|
||||||
if cfg.HTTP2 {
|
if cfg.HTTP2 {
|
||||||
if existing := os.Getenv("GODEBUG"); !strings.Contains(existing, "http2xconnect=1") {
|
if existing := os.Getenv("GODEBUG"); !strings.Contains(existing, "http2xconnect=1") {
|
||||||
if existing == "" {
|
if existing == "" {
|
||||||
@@ -489,6 +504,7 @@ func newInstance(cfg Config) (*serverInstance, error) {
|
|||||||
httpServer.Protocols.SetHTTP2(true)
|
httpServer.Protocols.SetHTTP2(true)
|
||||||
httpServer.Protocols.SetUnencryptedHTTP2(true)
|
httpServer.Protocols.SetUnencryptedHTTP2(true)
|
||||||
} else {
|
} else {
|
||||||
|
httpServer.Protocols.SetHTTP1(true)
|
||||||
httpServer.Protocols.SetHTTP2(false)
|
httpServer.Protocols.SetHTTP2(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user