MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / WithSecret

Method WithSecret

server/middlewares.go:47–61  ·  view source on GitHub ↗

WithSecret wraps RouteHandler with secret handling

(h RouteHandler)

Source from the content-addressed store, hash-verified

45
46// WithSecret wraps RouteHandler with secret handling
47func (r *Router) WithSecret(h RouteHandler) RouteHandler {
48 if len(r.config.Secret) == 0 {
49 return h
50 }
51
52 authHeader := fmt.Appendf(nil, "Bearer %s", r.config.Secret)
53
54 return func(reqID string, rw ResponseWriter, req *http.Request) *Error {
55 if subtle.ConstantTimeCompare([]byte(req.Header.Get(httpheaders.Authorization)), authHeader) == 1 {
56 return h(reqID, rw, req)
57 } else {
58 return NewError(newInvalidSecretError(), errCategorySecurity)
59 }
60 }
61}
62
63// WithPanic recovers panic and converts it to normal error
64func (r *Router) WithPanic(h RouteHandler) RouteHandler {

Callers 1

TestWithSecretMethod · 0.80

Calls 3

NewErrorFunction · 0.85
newInvalidSecretErrorFunction · 0.85
GetMethod · 0.65

Tested by 1

TestWithSecretMethod · 0.64