Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add KeepAliveMaxTime and KeepAliveMaxRequests features to entrypoints
- Loading branch information
Showing
9 changed files
with
258 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package server | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
ptypes "github.com/traefik/paerser/types" | ||
"github.com/traefik/traefik/v2/pkg/log" | ||
) | ||
|
||
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.WithoutContext().Debug("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.WithoutContext().Debug("Close because of too long connection") | ||
state.KeepAliveState = "Close because of too long connection" | ||
rw.Header().Set("Connection", "close") | ||
} | ||
} | ||
next.ServeHTTP(rw, req) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters