Skip to content

Commit

Permalink
Update Call ID Middleware
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Sep 13, 2023
1 parent 25e44f0 commit d0eec5f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gateway/handlers/callid_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ import (
"time"

"github.com/docker/distribution/uuid"
"github.com/openfaas/faas/gateway/version"
)

// MakeCallIDMiddleware middleware tags a request with a uid
func MakeCallIDMiddleware(next http.HandlerFunc) http.HandlerFunc {

version := version.Version

return func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
if len(r.Header.Get("X-Call-Id")) == 0 {
Expand All @@ -24,6 +28,8 @@ func MakeCallIDMiddleware(next http.HandlerFunc) http.HandlerFunc {
r.Header.Add("X-Start-Time", fmt.Sprintf("%d", start.UTC().UnixNano()))
w.Header().Add("X-Start-Time", fmt.Sprintf("%d", start.UTC().UnixNano()))

w.Header().Add("X-Served-By", fmt.Sprintf("openfaas-community/%s", version))

next(w, r)
}
}

0 comments on commit d0eec5f

Please sign in to comment.