File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -81,10 +81,18 @@ func (s *Items) Join(sep string) (data string) {
8181
8282type StaticHandler struct {
8383 Root string
84+ Cache bool
8485 fileServer http.Handler
8586}
8687
8788func (h * StaticHandler ) Handle (c * gin.Context ) {
89+ if ! h .Cache {
90+ c .Writer .Header ().Add ("Cache-Control" ,
91+ "no-cache, no-store, must-revalidate" )
92+ c .Writer .Header ().Add ("Pragma" , "no-cache" )
93+ c .Writer .Header ().Add ("Expires" , "0" )
94+ }
95+
8896 path := filepath .Join (h .Root , filepath .FromSlash (
8997 filepath .Clean ("/" + c .Param ("filepath" ))))
9098
@@ -199,18 +207,21 @@ func main() {
199207 pathPtr := flag .String ("path" , path , "Path to serve" )
200208 hostPtr := flag .String ("host" , "" , "Server host" )
201209 portPtr := flag .Int ("port" , 8000 , "Server port number" )
210+ cachePtr := flag .Bool ("cache" , false , "Enable cache" )
202211 flag .Parse ()
203212 path = * pathPtr
204213 host := * hostPtr
205214 port := * portPtr
215+ cache := * cachePtr
206216
207217 path , err = filepath .Abs (path )
208218 if err != nil {
209219 panic (err )
210220 }
211221
212222 static := & StaticHandler {
213- Root : path ,
223+ Root : path ,
224+ Cache : cache ,
214225 }
215226
216227 gin .SetMode (gin .ReleaseMode )
You can’t perform that action at this time.
0 commit comments