@@ -57,6 +57,22 @@ def fetch_file(path)
57
57
ETAG = "ETag" . freeze
58
58
ACCEPT_RANGES = "Accept-Ranges" . freeze
59
59
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
+
60
76
def respond ( env , path_info , extension )
61
77
path = Path [ path_info ] . simplify
62
78
@@ -65,13 +81,7 @@ def respond(env, path_info, extension)
65
81
end
66
82
67
83
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 ] )
75
85
76
86
if file . modified? ( env )
77
87
return file . serve ( env , response_headers )
0 commit comments