spider-gazelle 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aeeb2298300d8da4d2f42c72ae863890bdaf4bd1
4
- data.tar.gz: 57f36f06c105a1d4a0f1159e84f314d7643bfc66
3
+ metadata.gz: 04d19c0615315a23b7d35692bf0164d1942cf060
4
+ data.tar.gz: 1bc208a4be3b5e27b5fa67e30327219dfcb08dde
5
5
  SHA512:
6
- metadata.gz: 0e74529dcefd976af63a9ba055d0cfef12af3d12cd80aeee35bd8f7622aaf90169202e30d9753459d10231e8ca0f543351241242ffd6ddad3bf94cdfd63d27ff
7
- data.tar.gz: 173ec327155daba986d1a4d594bb0c75872a99b69f080f510d90c8d5370543dd5f93f824afd88374412cb2cfab48c12c981c89a7a3545e1f40cee9f53256d8d8
6
+ metadata.gz: b4c895af6b1163f38befb2168a7462ac7a4244912e3b4b1fe1c401aecfe3443464ce3cbf9ab84503d2b48149ab8458d54ab8a002d5a45ccad276485dbcbc7b56
7
+ data.tar.gz: de884e14291e07b7e5076af6f7aaa6a51074f1050858c88caf5d43f33bbe8d2b1bf01baf5a558e65d2ca4405636c55eb9c94ec6df41f16a397e9a105bab21cd1
@@ -8,6 +8,7 @@ module Rack
8
8
  # will effectively be executed synchronously.
9
9
  class Lock
10
10
  # FLAG = 'rack.multithread'.freeze # defined in rack/lock
11
+ RACK_MULTITHREAD ||= FLAG
11
12
 
12
13
  def initialize(app, mutex = Mutex.new)
13
14
  @app, @mutex = app, mutex
@@ -16,20 +17,16 @@ module Rack
16
17
  end
17
18
 
18
19
  def call(env)
19
- old, env[FLAG] = env[FLAG], false
20
20
  @mutex.lock
21
21
  @count += 1
22
22
  @sig.wait(@mutex) if @count > 1
23
- response = @app.call(env)
24
- body = BodyProxy.new(response[2]) {
23
+ response = @app.call(env.merge(RACK_MULTITHREAD => false))
24
+ returned = response << BodyProxy.new(response.pop) {
25
25
  @mutex.synchronize { unlock }
26
26
  }
27
- response[2] = body
28
- response
29
27
  ensure
30
- unlock unless body
28
+ unlock unless returned
31
29
  @mutex.unlock
32
- env[FLAG] = old
33
30
  end
34
31
 
35
32
  private
@@ -1,4 +1,5 @@
1
1
  require 'spider-gazelle/const'
2
+ require 'digest/md5'
2
3
  require 'stringio'
3
4
 
4
5
  module SpiderGazelle
@@ -182,30 +183,51 @@ module SpiderGazelle
182
183
 
183
184
  # If a file, stream the body in a non-blocking fashion
184
185
  if body.respond_to? :to_path
185
- if headers[CONTENT_LENGTH2]
186
- type = :raw
187
- else
188
- type = :http
189
- headers[TRANSFER_ENCODING] = CHUNKED
190
- end
191
-
192
- write_headers status, headers
186
+ file = @loop.file body.to_path, File::RDONLY
193
187
 
194
188
  # Send the body in parallel without blocking the next request in dev
195
189
  # Also if this is a head request we still want the body closed
196
190
  body.close if body.respond_to?(:close)
197
191
 
198
- if send_body
199
- file = @loop.file body.to_path, File::RDONLY
200
- file.progress do
201
- # File is open and available for reading
202
- file.send_file(@socket, type).finally do
192
+ file.progress do
193
+ statprom = file.stat
194
+ statprom.then do |stats|
195
+ headers[ETAG] = ::Digest::MD5.hexdigest "#{stats[:st_mtim][:tv_sec]}#{body.to_path}"
196
+
197
+ if headers[CONTENT_LENGTH2]
198
+ type = :raw
199
+ else
200
+ type = :http
201
+ headers[TRANSFER_ENCODING] = CHUNKED
202
+ end
203
+
204
+ write_headers status, headers
205
+
206
+ if send_body
207
+ # File is open and available for reading
208
+ file.send_file(@socket, type).finally do
209
+ file.close
210
+ @socket.shutdown if @request.keep_alive == false
211
+ end
212
+ else
203
213
  file.close
204
214
  @socket.shutdown if @request.keep_alive == false
205
215
  end
206
216
  end
207
- return file
217
+
218
+ # Ensure the file is closed if there is an error
219
+ statprom.catch do |reason|
220
+ file.close
221
+ @loop.work do
222
+ msg = "connection error: #{reason.message}\n#{reason.backtrace.join("\n") if reason.backtrace}\n"
223
+ @gazelle.logger.error msg
224
+ end
225
+
226
+ send_response [500, {}, EMPTY_RESPONSE]
227
+ end
208
228
  end
229
+
230
+ return file
209
231
  else
210
232
  # Optimize the response
211
233
  begin
@@ -27,7 +27,7 @@ module SpiderGazelle
27
27
  # REMOTE_USER, or REMOTE_HOST parameters since those are either a security problem or
28
28
  # too taxing on performance.
29
29
  module Const
30
- SPIDER_GAZELLE_VERSION = VERSION = "1.0.5".freeze
30
+ SPIDER_GAZELLE_VERSION = VERSION = "1.0.6".freeze
31
31
  # CODE_NAME = "Earl of Sandwich Partition"
32
32
  SERVER = "SpiderGazelle".freeze
33
33
 
@@ -93,7 +93,7 @@ module SpiderGazelle
93
93
  DEFAULT_TYPE = "text/plain".freeze
94
94
 
95
95
  # LAST_MODIFIED = "Last-Modified".freeze
96
- # ETAG = "ETag".freeze
96
+ ETAG = "ETag".freeze
97
97
  # SLASH = "/".freeze
98
98
  REQUEST_METHOD = "REQUEST_METHOD".freeze
99
99
  # GET = "GET".freeze
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spider-gazelle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen von Takach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-23 00:00:00.000000000 Z
11
+ date: 2015-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake