Skip to content
This repository has been archived by the owner on Oct 30, 2022. It is now read-only.

Latest commit

 

History

History
20 lines (13 loc) · 1.03 KB

README.md

File metadata and controls

20 lines (13 loc) · 1.03 KB

go-auth-cache

Description

This middleware assigns value "true" to header "go-auth-cache-Authenticated" to http.ResponseWriter if http.Request's header "Authorization" in this middleware's cache (cache hit). Assigns "false" otherwise.

One efficient usage is for Basic authentication. We use this middleware to know if the http.Request already authenticated in the past, avoid overhead of authenticating the same user over and over again.

Before exists, this middleware cache the request if http.ResponseWriter's header "go-auth-cache-Authenticated" is set to "cache".

Usage:

authCacheMiddleware := cache.NewDefault()

We then plug authCacheMiddleware in front of any middleware. Check this for example.

Note: Any of the following middleware of this middleware has to explicitly set http.ResponseWriter's header "go-auth-cache-Authenticated" to:

  • "cache", if it want the request to be cached.
  • don't set, do nothing.