diff --git a/cache.go b/cache.go index 21bd614..947749f 100644 --- a/cache.go +++ b/cache.go @@ -113,7 +113,7 @@ func cache( inFlight = true respCache := &ResponseCache{} - respCache.fillWithCacheWriter(cacheWriter, cfg.withoutHeader) + respCache.fillWithCacheWriter(cacheWriter, cfg) // only cache 2xx response if !c.IsAborted() && cacheWriter.Status() < 300 && cacheWriter.Status() >= 200 { @@ -214,11 +214,15 @@ type ResponseCache struct { Data []byte } -func (c *ResponseCache) fillWithCacheWriter(cacheWriter *responseCacheWriter, withoutHeader bool) { +func (c *ResponseCache) fillWithCacheWriter(cacheWriter *responseCacheWriter, cfg *Config) { c.Status = cacheWriter.Status() c.Data = cacheWriter.body.Bytes() - if !withoutHeader { + if !cfg.withoutHeader { c.Header = cacheWriter.Header().Clone() + + for _, headerKey := range cfg.discardHeaders { + c.Header.Del(headerKey) + } } } diff --git a/option.go b/option.go index 6646725..96671a7 100644 --- a/option.go +++ b/option.go @@ -23,6 +23,7 @@ type Config struct { ignoreQueryOrder bool prefixKey string withoutHeader bool + discardHeaders []string } func newConfigByOpts(opts ...Option) *Config { @@ -158,4 +159,19 @@ func WithoutHeader() Option { return func(c *Config) { c.withoutHeader = true } -} \ No newline at end of file +} + +func DiscardHeaders(headers []string) Option { + return func(c *Config) { + c.discardHeaders = headers + } +} + +func CorsHeaders() []string { + return []string{ + "Access-Control-Allow-Credentials", + "Access-Control-Expose-Headers", + "Access-Control-Allow-Origin", + "Vary", + } +}