forked from aws/aws-lambda-runtime-interface-emulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware.go
30 lines (24 loc) · 779 Bytes
/
middleware.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package standalone
import (
"net/http"
"github.com/go-chi/chi/middleware"
log "github.com/sirupsen/logrus"
)
func standaloneAccessLogDecorator(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Debugf("standalone: -> %s %s %v", r.Method, r.URL, r.Header)
ww := middleware.NewWrapResponseWriter(w, r.ProtoMajor)
next.ServeHTTP(ww, r)
status := 200
if ww.Status() != 0 {
status = ww.Status()
}
if status != 0 && status/100 != 2 {
log.Errorf("standalone: <- %s %d %v", r.URL, status, w.Header())
} else {
log.Debugf("standalone: <- %s %d %v", r.URL, status, w.Header())
}
})
}