Skip to content

Commit

Permalink
setup a timeout to avoid slowloris attacks
Browse files Browse the repository at this point in the history
  • Loading branch information
kpacha committed Oct 1, 2024
1 parent 5653ddd commit d569096
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions gin/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ type Metrics struct {
func (m *Metrics) RunEndpoint(ctx context.Context, e *gin.Engine, l logging.Logger) {
logPrefix := "[SERVICE: Stats]"
server := &http.Server{
Addr: m.Config.ListenAddr,
Handler: e,
Addr: m.Config.ListenAddr,
Handler: e,
ReadHeaderTimeout: 3 * time.Second,
}
go func() {
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
Expand Down
5 changes: 3 additions & 2 deletions mux/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ type Metrics struct {
// RunEndpoint runs the *gin.Engine (that should have the stats endpoint) with the logger
func (m *Metrics) RunEndpoint(ctx context.Context, s *http.ServeMux, l logging.Logger) {
server := &http.Server{
Addr: m.Config.ListenAddr,
Handler: s,
Addr: m.Config.ListenAddr,
Handler: s,
ReadHeaderTimeout: 3 * time.Second,
}
go func() {
l.Error(server.ListenAndServe())
Expand Down

0 comments on commit d569096

Please sign in to comment.