utopia 0.9.52 → 0.9.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/utopia/middleware/static.rb +23 -2
- data/lib/utopia/version.rb +1 -1
- metadata +3 -3
@@ -130,11 +130,29 @@ module Utopia
|
|
130
130
|
return result
|
131
131
|
end
|
132
132
|
|
133
|
+
# Accelerate the response if sendfile is configured.
|
134
|
+
def sendfile(request, response)
|
135
|
+
if @sendfile.respond_to?(:call)
|
136
|
+
response = @sendfile.call(request.env, response)
|
137
|
+
elsif @sendfile && request.env['HTTP_X_SENDFILE_MODE'] == "X-Sendfile"
|
138
|
+
response[1]["X-Sendfile"] = response[2].to_path
|
139
|
+
response[2] = []
|
140
|
+
end
|
141
|
+
|
142
|
+
return response
|
143
|
+
end
|
144
|
+
|
133
145
|
public
|
134
146
|
def initialize(app, options = {})
|
135
147
|
@app = app
|
136
148
|
@root = options[:root] || Utopia::Middleware::default_root
|
137
149
|
|
150
|
+
if options.key? :sendfile
|
151
|
+
@sendfile = options[:sendfile]
|
152
|
+
else
|
153
|
+
@sendfile = (UTOPIA_ENV == :production)
|
154
|
+
end
|
155
|
+
|
138
156
|
if options[:types]
|
139
157
|
@extensions = load_mime_types(options[:types])
|
140
158
|
else
|
@@ -148,7 +166,9 @@ module Utopia
|
|
148
166
|
end
|
149
167
|
|
150
168
|
def fetch_file(path)
|
169
|
+
# We need file_path to be an absolute path for X-Sendfile to work correctly.
|
151
170
|
file_path = File.join(@root, path.components)
|
171
|
+
|
152
172
|
if File.exist?(file_path)
|
153
173
|
return FileReader.new(file_path)
|
154
174
|
else
|
@@ -201,12 +221,13 @@ module Utopia
|
|
201
221
|
"Last-Modified" => file.mtime_date,
|
202
222
|
"Content-Type" => @extensions[ext],
|
203
223
|
"Cache-Control" => @cache_control,
|
204
|
-
"ETag" => file.etag
|
224
|
+
"ETag" => file.etag,
|
205
225
|
}
|
206
226
|
|
207
227
|
if file.modified?(env)
|
208
228
|
response_headers["Content-Length"] = file.size.to_s
|
209
|
-
|
229
|
+
|
230
|
+
return sendfile(request, [200, response_headers, file])
|
210
231
|
else
|
211
232
|
return [304, response_headers, []]
|
212
233
|
end
|
data/lib/utopia/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: utopia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 81
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 53
|
10
|
+
version: 0.9.53
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Samuel Williams
|