spider-gazelle 1.0.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a7447a407b6297445d56cc9dc47021b598375af
4
- data.tar.gz: 16285931940c9e329b8f24d58659eca23e329822
3
+ metadata.gz: 06ce9d0c2e12d8dda15fd597dbba9026d8848520
4
+ data.tar.gz: 3c649fbf8734a3f73e50073d3cf83efdc590e2a6
5
5
  SHA512:
6
- metadata.gz: 5d4fbb8493cd111f15fbfe6f6d718aa3afac4ddc13f3ce6d952c6b13cb1c0343e700db29197594f8364a3caea933141341584603ffa1bbc91dbf1faee01972d6
7
- data.tar.gz: 46dbe2558d2678bf5aba39648cd8ac5fa64aa9c03b151cc2a4083484a1a3891ea5b9127d903e0519c1a6ae8b6b82443d64e1de3b6145915778a68733e794e8a7
6
+ metadata.gz: 438f525a31e89401f9c86dd57c50a97c3a558eca28e04dc82e1173cd9af801e3de899282f55a387fccbc2ff2d13b0da5ca74645320edc8fc2a0c4fb7b0756d32
7
+ data.tar.gz: 4a52edec124cb480ab4c51a9c584923529045f51007ee3213ef58a77669896ef51569d461ffd9d8e12e10148106fb80305bd4f8395e65d2a908771cfef5f88dd
@@ -30,7 +30,6 @@ module SpiderGazelle
30
30
 
31
31
  # Used to chain promises (ensures requests are processed in order)
32
32
  @process_next = method :process_next
33
- @write_chunk = method :write_chunk
34
33
  # Keep track of work queue head to prevent unintentional GC
35
34
  @current_worker = queue
36
35
  # Start queue with an existing resolved promise (::Libuv::Q::ResolvedPromise.new(@loop, true))
@@ -166,7 +165,6 @@ module SpiderGazelle
166
165
  end
167
166
 
168
167
  return promise
169
- # NOTE:: Somehow getting to here with a nil request... needs investigation
170
168
  elsif result
171
169
  # clear any cached responses just in case
172
170
  # could be set by error in the rack application
@@ -247,6 +245,7 @@ module SpiderGazelle
247
245
  write_headers status, headers
248
246
 
249
247
  # Stream the response
248
+ @write_chunk ||= method :write_chunk
250
249
  body.each &@write_chunk
251
250
 
252
251
  if @request.deferred.nil?
@@ -269,7 +268,7 @@ module SpiderGazelle
269
268
 
270
269
  value.split(NEWLINE).each do |unique_value|
271
270
  header << key
272
- header << COLON
271
+ header << COLON_SPACE
273
272
  header << unique_value
274
273
  header << LINE_END
275
274
  end
@@ -332,6 +331,7 @@ module SpiderGazelle
332
331
  deferred.resolve true
333
332
  else
334
333
  # Send the chunks provided
334
+ @write_chunk ||= method :write_chunk
335
335
  body.each &@write_chunk
336
336
  body.close if body.respond_to?(:close)
337
337
  end
@@ -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.0".freeze
30
+ SPIDER_GAZELLE_VERSION = VERSION = "1.0.1".freeze
31
31
  # CODE_NAME = "Earl of Sandwich Partition"
32
32
  SERVER = "SpiderGazelle".freeze
33
33
 
@@ -147,6 +147,8 @@ module SpiderGazelle
147
147
  # SPIDER_GAZELLE_SOCKET = "spider-gazelle.socket".freeze
148
148
  # SPIDER_GAZELLE_CONFIG = "spider-gazelle.config".freeze
149
149
 
150
+ ASCII_8BIT = "ASCII-8BIT".freeze
151
+
150
152
  HTTP = "http".freeze
151
153
  HTTPS = "https".freeze
152
154
 
@@ -176,9 +178,14 @@ module SpiderGazelle
176
178
  CLOSE_CHUNKED = "0\r\n\r\n".freeze
177
179
 
178
180
  COMMA = ", ".freeze
179
- COLON = ": ".freeze
181
+ COLON_SPACE = ": ".freeze
182
+ COLON = ":".freeze
183
+ DASH = "-".freeze
184
+ UNDERSCORE = "_".freeze
185
+ SPACE = " ".freeze
180
186
  NEWLINE = "\n".freeze
181
187
  EMPTY = "".freeze
188
+ QUESTION_MARK = "?".freeze
182
189
 
183
190
  ZERO = "0".freeze
184
191
 
@@ -81,7 +81,7 @@ module SpiderGazelle
81
81
  else
82
82
  header = req.header
83
83
  header.upcase!
84
- header.gsub!('-', '_')
84
+ header.gsub!(DASH, UNDERSCORE)
85
85
  header.prepend(HTTP_META)
86
86
  header.freeze
87
87
  if req.env[header]
@@ -131,7 +131,7 @@ module SpiderGazelle
131
131
  end
132
132
 
133
133
  # Data == "TLS_indicator Port APP_ID"
134
- tls, port, app_id = data.split(' ', 3)
134
+ tls, port, app_id = data.split(SPACE, 3)
135
135
  app = @app_cache[app_id.to_sym] ||= AppStore.get(app_id)
136
136
  inst = @parser_cache.pop || ::HttpParser::Parser.new_instance(&@set_instance_type)
137
137
 
@@ -139,7 +139,7 @@ module SpiderGazelle
139
139
  socket.progress @on_progress
140
140
  # TODO:: Allow some globals for supplying the certs
141
141
  # --> We could store these in the AppStore
142
- socket.start_tls(:server => true) if tls == 'T'
142
+ socket.start_tls(:server => true) if tls == USE_TLS
143
143
 
144
144
  # Keep track of the connection
145
145
  connection = Connection.new self, @gazelle, socket, port, inst, app, @connection_queue
@@ -29,7 +29,6 @@ module SpiderGazelle
29
29
  @body = ''
30
30
  @header = ''
31
31
  @url = ''
32
- @execute = method :execute
33
32
  @env = PROTO_ENV.dup
34
33
  @loop = connection.loop
35
34
  @env[SERVER_PORT] = connection.port
@@ -44,11 +43,11 @@ module SpiderGazelle
44
43
  @env[REQUEST_URI] = @url.freeze
45
44
 
46
45
  # For Rack::Lint on 1.9, ensure that the encoding is always for spec
47
- @body.force_encoding('ASCII-8BIT') if @body.respond_to?(:force_encoding)
46
+ @body.force_encoding(ASCII_8BIT) if @body.respond_to?(:force_encoding)
48
47
  @env[RACK_INPUT] = StringIO.new @body
49
48
 
50
49
  # Break the request into its components
51
- query_start = @url.index '?'
50
+ query_start = @url.index QUESTION_MARK
52
51
  if query_start
53
52
  path = @url[0...query_start].freeze
54
53
  @env[PATH_INFO] = path
@@ -57,12 +56,12 @@ module SpiderGazelle
57
56
  else
58
57
  @env[PATH_INFO] = @url
59
58
  @env[REQUEST_PATH] = @url
60
- @env[QUERY_STRING] = ''
59
+ @env[QUERY_STRING] = EMPTY
61
60
  end
62
61
 
63
62
  # Grab the host name from the request
64
63
  if host = @env[HTTP_HOST]
65
- if colon = host.index(':')
64
+ if colon = host.index(COLON)
66
65
  @env[SERVER_NAME] = host[0, colon]
67
66
  @env[SERVER_PORT] = host[colon+1, host.bytesize]
68
67
  else
@@ -81,7 +80,7 @@ module SpiderGazelle
81
80
  end
82
81
 
83
82
  # Execute the request
84
- @response = catch :async, &@execute
83
+ @response = catch(:async) { @app.call @env }
85
84
  if @response.nil? || @response[0] == -1
86
85
  @deferred = @loop.defer
87
86
 
@@ -96,12 +95,6 @@ module SpiderGazelle
96
95
 
97
96
  protected
98
97
 
99
- # Execute the request then return the result to the event loop
100
- def execute(*args)
101
- result = @app.call @env
102
- result
103
- end
104
-
105
98
  def hijack
106
99
  @hijacked = @loop.defer
107
100
  @env[HIJACK_IO] = @hijacked.promise
@@ -221,7 +221,9 @@ module SpiderGazelle
221
221
  # Called from the binding for sending to gazelles
222
222
  def delegate(client, tls, port, app_id)
223
223
  indicator = tls ? USE_TLS : NO_TLS
224
- @select_handler.next.write2(client, "#{indicator} #{port} #{app_id}")
224
+ @select_handler.next.write2(client, "#{indicator} #{port} #{app_id}").finally do
225
+ client.close
226
+ end
225
227
  end
226
228
 
227
229
  def direct_delegate(client, tls, port, app_id)
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.0
4
+ version: 1.0.1
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: 2014-05-20 00:00:00.000000000 Z
11
+ date: 2014-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake