@@ -57,6 +57,22 @@ def fetch_file(path)
5757 ETAG = "ETag" . freeze
5858 ACCEPT_RANGES = "Accept-Ranges" . freeze
5959
60+ def response_headers_for ( file , content_type )
61+ if @cache_control . respond_to? ( :call )
62+ cache_control = @cache_control . call ( file )
63+ else
64+ cache_control = @cache_control
65+ end
66+
67+ {
68+ LAST_MODIFIED => file . mtime_date ,
69+ CONTENT_TYPE => content_type ,
70+ CACHE_CONTROL => cache_control ,
71+ ETAG => file . etag ,
72+ ACCEPT_RANGES => "bytes"
73+ }
74+ end
75+
6076 def respond ( env , path_info , extension )
6177 path = Path [ path_info ] . simplify
6278
@@ -65,13 +81,7 @@ def respond(env, path_info, extension)
6581 end
6682
6783 if file = fetch_file ( path )
68- response_headers = {
69- LAST_MODIFIED => file . mtime_date ,
70- CONTENT_TYPE => @extensions [ extension ] ,
71- CACHE_CONTROL => @cache_control ,
72- ETAG => file . etag ,
73- ACCEPT_RANGES => "bytes"
74- }
84+ response_headers = self . response_headers_for ( file , @extensions [ extension ] )
7585
7686 if file . modified? ( env )
7787 return file . serve ( env , response_headers )
0 commit comments