mirror of
https://github.com/openfaas/faas.git
synced 2025-06-08 16:26:47 +00:00
Update Call ID Middleware
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
parent
25e44f0b57
commit
d0eec5fbbf
@ -9,10 +9,14 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/distribution/uuid"
|
"github.com/docker/distribution/uuid"
|
||||||
|
"github.com/openfaas/faas/gateway/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MakeCallIDMiddleware middleware tags a request with a uid
|
// MakeCallIDMiddleware middleware tags a request with a uid
|
||||||
func MakeCallIDMiddleware(next http.HandlerFunc) http.HandlerFunc {
|
func MakeCallIDMiddleware(next http.HandlerFunc) http.HandlerFunc {
|
||||||
|
|
||||||
|
version := version.Version
|
||||||
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
if len(r.Header.Get("X-Call-Id")) == 0 {
|
if len(r.Header.Get("X-Call-Id")) == 0 {
|
||||||
@ -24,6 +28,8 @@ func MakeCallIDMiddleware(next http.HandlerFunc) http.HandlerFunc {
|
|||||||
r.Header.Add("X-Start-Time", fmt.Sprintf("%d", start.UTC().UnixNano()))
|
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-Start-Time", fmt.Sprintf("%d", start.UTC().UnixNano()))
|
||||||
|
|
||||||
|
w.Header().Add("X-Served-By", fmt.Sprintf("openfaas-community/%s", version))
|
||||||
|
|
||||||
next(w, r)
|
next(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user