spider-gazelle 1.0.5 → 1.0.6
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.
- checksums.yaml +4 -4
- data/lib/rack/lock_patch.rb +4 -7
- data/lib/spider-gazelle/connection.rb +36 -14
- data/lib/spider-gazelle/const.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04d19c0615315a23b7d35692bf0164d1942cf060
|
4
|
+
data.tar.gz: 1bc208a4be3b5e27b5fa67e30327219dfcb08dde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4c895af6b1163f38befb2168a7462ac7a4244912e3b4b1fe1c401aecfe3443464ce3cbf9ab84503d2b48149ab8458d54ab8a002d5a45ccad276485dbcbc7b56
|
7
|
+
data.tar.gz: de884e14291e07b7e5076af6f7aaa6a51074f1050858c88caf5d43f33bbe8d2b1bf01baf5a558e65d2ca4405636c55eb9c94ec6df41f16a397e9a105bab21cd1
|
data/lib/rack/lock_patch.rb
CHANGED
@@ -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
|
-
|
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
|
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
|
-
|
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
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
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
|
-
|
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
|
data/lib/spider-gazelle/const.rb
CHANGED
@@ -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.
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2015-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|