@@ -121,24 +121,27 @@ func staticMiddleware(next http.Handler) http.Handler {
121121
122122func dynamicMiddleware (next http.Handler ) http.Handler {
123123 return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
124- var ctx context. Context
124+ nr := r
125125 switch filepath .Ext (r .URL .EscapedPath ()) {
126- case ".css" , ".ico" , ".jpeg" , ".jpg" , ".webp" :
127- ctx = context .WithValue (r .Context (), cacheInfoCtxKey , & cacheInfo {
126+ case ".css" , ".ico" , ".jpeg" , ".jpg" , ".js" , ". webp" :
127+ ctx : = context .WithValue (r .Context (), cacheInfoCtxKey , & cacheInfo {
128128 Prefix : cachePrefixStatic ,
129129 })
130+ nr = r .WithContext (ctx )
130131 case ".m3u8" , ".ts" :
131- ctx = r . Context ()
132+ break
132133 default :
133134 if rh := r .Header .Get (headerRange ); rh != "" {
134- ctx = r .Context ()
135+ break
136+ } else if upgrade := r .Header .Get (headerUpgrade ); upgrade == "websocket" {
135137 break
136138 }
137- ctx = context .WithValue (r .Context (), cacheInfoCtxKey , & cacheInfo {
139+ ctx : = context .WithValue (r .Context (), cacheInfoCtxKey , & cacheInfo {
138140 Prefix : cachePrefixDynamic ,
139141 })
142+ nr = r .WithContext (ctx )
140143 }
141- cacheMiddleware (next ).ServeHTTP (w , r . WithContext ( ctx ) )
144+ cacheMiddleware (next ).ServeHTTP (w , nr )
142145 })
143146}
144147
0 commit comments