cache

package module
v0.0.0-...-b747326 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2015 License: GPL-2.0 Imports: 3 Imported by: 0

README

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.

Documentation

Overview

Package cache implements middleware caching Authorization header to authenticate user.

Index

Constants

View Source
const (
	DefaultAuthExpireTime = 10 * time.Minute
	DefaultAuthPurseTime  = 60 * time.Second
	AuthenticatedHeader   = "go-auth-cache-Authenticated"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	gcache.Cache
}

Type Cache stores cache for basic auth, and record.

func New

func New(authExpireTime, authPurseTime time.Duration) *Cache

New returns a Cache with given expire time, and purse time.

func NewDefault

func NewDefault() *Cache

NewDefault returns a Cache with default value for AuthCache, RecordCache

func (*Cache) ServeHTTP

func (c *Cache) ServeHTTP(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)

ServeHTTP inform next middleware this request already authenticated by looking into the cache.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL