@@ -40,17 +40,18 @@ type ServerOptions struct {
4040 CacheMeta kv.KV // 配置缓存
4141 CacheMetaTTL time.Duration // 配置缓存时长
4242
43- CacheBlob cache.Cache // blob缓存
44- CacheBlobTTL time.Duration // 配置缓存时长
45- CacheBlobLimit uint64 // blob最大缓存大小
43+ CacheBlob cache.Cache // blob缓存
44+ CacheBlobTTL time.Duration // 配置缓存时长
45+ CacheControl string // 缓存配置
4646
47- HTTPClient * http. Client // 自定义客户端
47+ CacheBlobLimit uint64 // blob最大缓存大小
4848
49- EnableRender bool // 允许渲染
50- EnableProxy bool // 允许代理
49+ HTTPClient * http. Client // 自定义客户端
50+ EnableRender bool // 允许渲染
5151
52- StaticDir string // 静态文件位置
52+ EnableProxy bool // 允许代理
5353
54+ StaticDir string // 静态文件位置
5455 DefaultErrorHandler func (w http.ResponseWriter , r * http.Request , err error )
5556}
5657
@@ -68,6 +69,7 @@ func DefaultOptions(domain string) ServerOptions {
6869 CacheBlob : cacheMemory ,
6970 CacheBlobTTL : time .Minute ,
7071 CacheBlobLimit : 1024 * 1024 * 10 ,
72+ CacheControl : "public, max-age=86400" ,
7173
7274 HTTPClient : http .DefaultClient ,
7375
@@ -243,7 +245,7 @@ func (s *Server) Serve(writer http.ResponseWriter, request *http.Request) error
243245 if reader , ok := result .(* cache.Content ); ok {
244246 writer .Header ().Add ("X-Cache" , "HIT" )
245247 writer .Header ().Set ("Content-Type" , mime .TypeByExtension (filepath .Ext (fileName )))
246- writer .Header ().Add ("Cache-Control" , "public, max-age=86400" )
248+ writer .Header ().Add ("Cache-Control" , s . options . CacheControl )
247249 if render != nil {
248250 if err = render .Render (writer , request , reader ); err != nil {
249251 return err
@@ -257,7 +259,6 @@ func (s *Server) Serve(writer http.ResponseWriter, request *http.Request) error
257259 }
258260 // todo(bug) : 直连模式下告知数据长度
259261 writer .Header ().Add ("X-Cache" , "MISS" )
260- writer .Header ().Add ("Cache-Control" , "public, max-age=86400" )
261262 writer .Header ().Set ("Content-Type" , mime .TypeByExtension (filepath .Ext (fileName )))
262263 writer .WriteHeader (http .StatusOK )
263264 if render != nil {
0 commit comments