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 +4 -4
- data/.gitignore +2 -1
- data/lib/em-midori/api.rb +11 -10
- data/lib/em-midori/clean_room.rb +11 -1
- data/lib/em-midori/middleware.rb +7 -4
- data/lib/em-midori/version.rb +1 -1
- 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: 3c9b1b11b8b12fdf155197d7c635e7be5da31fe6
|
4
|
+
data.tar.gz: b6278a14ac7fbdb502d6585cad1f00735379de12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 774886075e8cf1c3d12ca43f28589fcaa0cd1bc11d645d5c12c1604400388a8bfb8fcd2580efcd0d678a16c2975a4f43725fd64eda186e0490431e669fa1cae9
|
7
|
+
data.tar.gz: 7c5f25c5051c387e3b86cee19d4dcea157fc797164b36a01ba9e0752195b324cbe5432e5824e4982c143526af53abaf96b228ea03a0dd9391ff302a79ef1a346
|
data/.gitignore
CHANGED
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 = []
|
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
|
-
|
186
|
-
|
185
|
+
middlewares, body_accept = [], [String]
|
186
|
+
else
|
187
|
+
middlewares, body_accept = @middleware.clone, @body_accept.clone
|
187
188
|
end
|
188
|
-
|
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
|
202
|
+
clean_room.body = result if body_accept.include?(result.class)
|
202
203
|
response = clean_room.response
|
203
|
-
|
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
|
-
|
247
|
+
def use(middleware, *args)
|
248
|
+
middleware = middleware.new(*args)
|
248
249
|
@middleware = [] if @middleware.nil?
|
249
250
|
@middleware << middleware
|
250
|
-
@body_accept = middleware.
|
251
|
+
@body_accept = middleware.body_accept
|
251
252
|
end
|
252
253
|
|
253
254
|
def websocket_header(key)
|
data/lib/em-midori/clean_room.rb
CHANGED
@@ -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
|
data/lib/em-midori/middleware.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
class Midori::Middleware
|
2
|
-
def
|
2
|
+
def initialize
|
3
|
+
end
|
4
|
+
|
5
|
+
def before(request)
|
3
6
|
request
|
4
7
|
end
|
5
8
|
|
6
|
-
def
|
9
|
+
def after(_request, response)
|
7
10
|
response
|
8
11
|
end
|
9
|
-
|
10
|
-
def
|
12
|
+
|
13
|
+
def body_accept
|
11
14
|
[String]
|
12
15
|
end
|
13
16
|
end
|
data/lib/em-midori/version.rb
CHANGED
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-
|
11
|
+
date: 2016-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|