feat: expose HTTP2 header and protocol limits
This commit is contained in:
@@ -35,6 +35,7 @@ type Server struct {
|
||||
MaxConnections int
|
||||
MaxConcurrentRequests int
|
||||
MaxConcurrentStreams uint32
|
||||
MaxHeaderBytes int
|
||||
MaxBodyBytes int64
|
||||
IdleTimeout time.Duration
|
||||
TLSHandshakeTimeout time.Duration
|
||||
@@ -55,6 +56,7 @@ type Server struct {
|
||||
accepted atomic.Uint64
|
||||
rejectedConns atomic.Uint64
|
||||
rejectedReqs atomic.Uint64
|
||||
protocolErrors atomic.Uint64
|
||||
activeConns atomic.Int64
|
||||
activeRequests atomic.Int64
|
||||
wg sync.WaitGroup
|
||||
@@ -66,6 +68,7 @@ type Stats struct {
|
||||
AcceptedConnections uint64 `json:"acceptedConnections"`
|
||||
RejectedConnections uint64 `json:"rejectedConnections"`
|
||||
RejectedRequests uint64 `json:"rejectedRequests"`
|
||||
ProtocolErrors uint64 `json:"protocolErrors"`
|
||||
ActiveConnections int64 `json:"activeConnections"`
|
||||
ActiveRequests int64 `json:"activeRequests"`
|
||||
}
|
||||
@@ -89,6 +92,7 @@ func (s *Server) Stats() Stats {
|
||||
AcceptedConnections: s.accepted.Load(),
|
||||
RejectedConnections: s.rejectedConns.Load(),
|
||||
RejectedRequests: s.rejectedReqs.Load(),
|
||||
ProtocolErrors: s.protocolErrors.Load(),
|
||||
ActiveConnections: s.activeConns.Load(),
|
||||
ActiveRequests: s.activeRequests.Load(),
|
||||
}
|
||||
@@ -226,8 +230,11 @@ func (s *Server) Serve(ctx context.Context, listener net.Listener) error {
|
||||
protocolServer := &xhttp2.Server{
|
||||
MaxConcurrentStreams: s.MaxConcurrentStreams,
|
||||
IdleTimeout: s.IdleTimeout,
|
||||
CountError: func(string) {
|
||||
s.protocolErrors.Add(1)
|
||||
},
|
||||
}
|
||||
shutdownConfig := &http.Server{IdleTimeout: s.IdleTimeout}
|
||||
shutdownConfig := &http.Server{IdleTimeout: s.IdleTimeout, MaxHeaderBytes: s.MaxHeaderBytes}
|
||||
if err := xhttp2.ConfigureServer(shutdownConfig, protocolServer); err != nil {
|
||||
cancel()
|
||||
s.mu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user