Merge 8aa487da88
into 0f209f62eb
commit
c107656615
|
@ -42,6 +42,9 @@ func init() {
|
||||||
caddy.RegisterModule(FileServer{})
|
caddy.RegisterModule(FileServer{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const FileServerFilenameVarKey = "fileserver_filename"
|
||||||
|
const FileServerFileinfoVarKey = "fileserver_fileinfo"
|
||||||
|
|
||||||
// FileServer implements a handler that serves static files.
|
// FileServer implements a handler that serves static files.
|
||||||
//
|
//
|
||||||
// The path of the file to serve is constructed by joining the site root
|
// The path of the file to serve is constructed by joining the site root
|
||||||
|
@ -561,6 +564,14 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
|
||||||
w = statusOverrideResponseWriter{ResponseWriter: w, code: statusCodeOverride}
|
w = statusOverrideResponseWriter{ResponseWriter: w, code: statusCodeOverride}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add filename and file info to the request context vars so that other middlewares
|
||||||
|
// can find out what static file has been served by the fileserver.
|
||||||
|
// middlewares can access the vars as follows:
|
||||||
|
// caddyhttp.GetVar(r.Context(), fileserver.FileServerFilenameVarKey).(string)
|
||||||
|
// caddyhttp.GetVar(r.Context(), fileserver.FileServerFileinfoVarKey).(fs.FileInfo)
|
||||||
|
caddyhttp.SetVar(r.Context(), FileServerFilenameVarKey, filename)
|
||||||
|
caddyhttp.SetVar(r.Context(), FileServerFileinfoVarKey, info)
|
||||||
|
|
||||||
// let the standard library do what it does best; note, however,
|
// let the standard library do what it does best; note, however,
|
||||||
// that errors generated by ServeContent are written immediately
|
// that errors generated by ServeContent are written immediately
|
||||||
// to the response, so we cannot handle them (but errors there
|
// to the response, so we cannot handle them (but errors there
|
||||||
|
|
Loading…
Reference in New Issue