em-midori 0.0.9 → 0.0.9.1

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: 98fbd92141350243b9a3e3d1419d3cc7364270d8
4
- data.tar.gz: 6cb7c2807690751d6d0796511aa00d974ec51148
3
+ metadata.gz: 3c9b1b11b8b12fdf155197d7c635e7be5da31fe6
4
+ data.tar.gz: b6278a14ac7fbdb502d6585cad1f00735379de12
5
5
  SHA512:
6
- metadata.gz: 014ae17886c6a64490fa0b9ace13c98cd6873e2aa11bfe649f799e150e64477dabd734440bdd9553129fa1db49454dadd088d5957cbcf738f1e8332040e40821
7
- data.tar.gz: 1178bfea1e5d3da5b34aa3b1a0b1c22c4fcfd1b844c0466166d33994202ddf022048c62530e3ded73074de980459a09e6f84d9e81fa4ab427efd113b4b5aa439
6
+ metadata.gz: 774886075e8cf1c3d12ca43f28589fcaa0cd1bc11d645d5c12c1604400388a8bfb8fcd2580efcd0d678a16c2975a4f43725fd64eda186e0490431e669fa1cae9
7
+ data.tar.gz: 7c5f25c5051c387e3b86cee19d4dcea157fc797164b36a01ba9e0752195b324cbe5432e5824e4982c143526af53abaf96b228ea03a0dd9391ff302a79ef1a346
data/.gitignore CHANGED
@@ -50,4 +50,5 @@ build-iPhoneSimulator/
50
50
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
51
51
  .rvmrc
52
52
 
53
- /.vscode/
53
+ /.vscode/
54
+ benchmark/express/node_modules
data/lib/em-midori/api.rb CHANGED
@@ -167,7 +167,7 @@ class Midori::API
167
167
  # Convert String to Regexp to provide performance boost (Precompiled Regexp)
168
168
  path = convert_route path
169
169
  end
170
- @route = [] if @route.nil?
170
+ @route = @route || []
171
171
  @route << Midori::Route.new(method, path, block)
172
172
  nil
173
173
  end
@@ -182,11 +182,12 @@ class Midori::API
182
182
  matched = match(route.method, route.path, request.method, request.path)
183
183
  next unless matched
184
184
  if @middleware.nil?
185
- @middleware = []
186
- @body_accept = [String]
185
+ middlewares, body_accept = [], [String]
186
+ else
187
+ middlewares, body_accept = @middleware.clone, @body_accept.clone
187
188
  end
188
- @middleware.each { |middleware| request = middleware.before(request) }
189
- clean_room = Midori::CleanRoom.new(request)
189
+ middlewares.each { |middleware| request = middleware.before(request) }
190
+ clean_room = Midori::CleanRoom.new(request, middlewares, body_accept)
190
191
  if request.websocket?
191
192
  # Send 101 Switching Protocol
192
193
  connection.send_data Midori::Response.new(101, websocket_header(request.header['Sec-WebSocket-Key']), '')
@@ -198,9 +199,9 @@ class Midori::API
198
199
  return Midori::Response.new
199
200
  else
200
201
  result = -> { clean_room.instance_exec(*matched, &route.function) }.call
201
- clean_room.body = result if @body_accept.include?(result.class)
202
+ clean_room.body = result if body_accept.include?(result.class)
202
203
  response = clean_room.response
203
- @middleware.reverse.each { |middleware| response = middleware.after(request, response) }
204
+ middlewares.reverse.each { |middleware| response = middleware.after(request, response) }
204
205
  return response
205
206
  end
206
207
  end
@@ -243,11 +244,11 @@ class Midori::API
243
244
  Regexp.new path
244
245
  end
245
246
 
246
- def use(middleware)
247
- raise Midori::Error::MiddlewareError unless middleware.new.is_a?Midori::Middleware
247
+ def use(middleware, *args)
248
+ middleware = middleware.new(*args)
248
249
  @middleware = [] if @middleware.nil?
249
250
  @middleware << middleware
250
- @body_accept = middleware.accept
251
+ @body_accept = middleware.body_accept
251
252
  end
252
253
 
253
254
  def websocket_header(key)
@@ -1,13 +1,23 @@
1
1
  class Midori::CleanRoom
2
2
  attr_accessor :code, :header, :body, :request
3
- def initialize(request)
3
+ def initialize(request, middleware = [], body_accept = [String])
4
4
  @status = 200
5
5
  @header = Midori::Const::DEFAULT_HEADER.clone
6
6
  @body = ''
7
7
  @request = request
8
+ @middleware = middleware
9
+ @body_accept = body_accept
8
10
  end
9
11
 
10
12
  def response
11
13
  Midori::Response.new(@status, @header, @body)
12
14
  end
15
+
16
+ def use(middleware, *args)
17
+ middleware = middleware.new(*args)
18
+ @middleware = [] if @middleware.nil?
19
+ @middleware << middleware
20
+ @body_accept.replace middleware.body_accept
21
+ @request = middleware.before(request)
22
+ end
13
23
  end
@@ -1,13 +1,16 @@
1
1
  class Midori::Middleware
2
- def self.before(request)
2
+ def initialize
3
+ end
4
+
5
+ def before(request)
3
6
  request
4
7
  end
5
8
 
6
- def self.after(_request, response)
9
+ def after(_request, response)
7
10
  response
8
11
  end
9
-
10
- def self.accept
12
+
13
+ def body_accept
11
14
  [String]
12
15
  end
13
16
  end
@@ -1,3 +1,3 @@
1
1
  module Midori
2
- VERSION = '0.0.9'.freeze
2
+ VERSION = '0.0.9.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-midori
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - HeckPsi Lab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-17 00:00:00.000000000 Z
11
+ date: 2016-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine