Skip to content

Commit

Permalink
server/server.go : Increase buffer size
Browse files Browse the repository at this point in the history
  • Loading branch information
FernandezBenjamin committed Sep 4, 2023
1 parent 5c2563a commit 7dc978e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server

import (
"bufio"
"context"
"crypto/rsa"
"encoding/json"
Expand Down Expand Up @@ -363,7 +364,19 @@ func newServer(ctx context.Context, c Config, rotationStrategy rotationStrategy)
})
}

// Buffer size middleware
bufferSizeMidldleware := func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w := bufio.NewWriterSize(w, 4096*2)
if w.Buffered() > 0 {
w.Flush()
}
next.ServeHTTP(w, r)
})
}

r := mux.NewRouter().SkipClean(true).UseEncodedPath()
r.Use(bufferSizeMidldleware)
r.Use(frameAncestorsMidldleware)
handle := func(p string, h http.Handler) {
r.Handle(path.Join(issuerURL.Path, p), instrumentHandlerCounter(p, h))
Expand Down

0 comments on commit 7dc978e

Please sign in to comment.