mirror of
https://github.com/hanzoai/ingress.git
synced 2026-10-26 02:47:15 +00:00
- Fork github.com/traefik/paerser to github.com/hanzoai/ingress-parser with rebranded prefixes (TRAEFIK_ → INGRESS_, traefik. → ingress.) - Update all 71 Go files importing paerser to use ingress-parser - CLI flags: traefik.configfile → ingress.configfile - Env prefix: TRAEFIK_* → INGRESS_* - Deprecation loader: traefik. label prefix → ingress. - Recompute digest auth test hashes for realm "ingress" - Rename traefiker test realm → ingresser - Fix remaining comment URLs to hanzoai/ingress 7 remaining "traefik" refs are Go import paths for external packages (traefik/yaegi, traefik/grpc-web) — these are the packages' module identity, cannot be renamed without forking the entire Go interpreter and gRPC-Web proxy.
30 lines
933 B
Go
30 lines
933 B
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
ptypes "github.com/hanzoai/ingress-parser/types"
|
|
)
|
|
|
|
func newKeepAliveMiddleware(next http.Handler, maxRequests int, maxTime ptypes.Duration) http.Handler {
|
|
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
|
state, ok := req.Context().Value(connStateKey).(*connState)
|
|
if ok {
|
|
state.HTTPRequestCount++
|
|
if maxRequests > 0 && state.HTTPRequestCount >= maxRequests {
|
|
log.Debug().Msg("Close because of too many requests")
|
|
state.KeepAliveState = "Close because of too many requests"
|
|
rw.Header().Set("Connection", "close")
|
|
}
|
|
if maxTime > 0 && time.Now().After(state.Start.Add(time.Duration(maxTime))) {
|
|
log.Debug().Msg("Close because of too long connection")
|
|
state.KeepAliveState = "Close because of too long connection"
|
|
rw.Header().Set("Connection", "close")
|
|
}
|
|
}
|
|
next.ServeHTTP(rw, req)
|
|
})
|
|
}
|