angelo 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +18 -2
- data/lib/angelo/base.rb +19 -4
- data/lib/angelo/responder.rb +10 -6
- data/lib/angelo/server.rb +2 -2
- data/lib/angelo/version.rb +1 -1
- data/lib/angelo.rb +4 -0
- data/spec/angelo_spec.rb +65 -0
- 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: d3ee383cbc5d2f838c1a46aa1d5e18e7e22bb900
|
4
|
+
data.tar.gz: fbf02365249c4c948c81148906247bb357e0c887
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bc808f0d1104da6f11f7d7b9e8e97ed7a6613f516e91f7734eac2d9a614babb6bbd727c947a72647791b1606dc5cbad025f972909ef4ccf3ffbc0033e3f0d78
|
7
|
+
data.tar.gz: 5daa0814e6825926be13f01b5a42b40b20b3ffaba6ddd88ad9ee4e0001b398ce13286c3f1407e0c0af58c7ceda6875b263979be416114a16637e153b8b2be731
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
changelog
|
2
2
|
=========
|
3
3
|
|
4
|
+
### 0.1.6 2 apr 2014
|
5
|
+
|
6
|
+
* better testing of Responder#headers
|
7
|
+
* better handling of Responder#redirect
|
8
|
+
* add Base#request_headers helper
|
9
|
+
* rename Base.async -> Base.task, add Base#future
|
10
|
+
|
4
11
|
### 0.1.5 31 mar 2014
|
5
12
|
|
6
13
|
* add WebsocketsArray#all
|
data/README.md
CHANGED
@@ -20,8 +20,10 @@ Lots of work left to do!
|
|
20
20
|
|
21
21
|
```ruby
|
22
22
|
require 'angelo'
|
23
|
+
require 'angelo/mustermann'
|
23
24
|
|
24
25
|
class Foo < Angelo::Base
|
26
|
+
include Angelo::Mustermann
|
25
27
|
|
26
28
|
TEST = {foo: "bar", baz: 123, bat: false}.to_json
|
27
29
|
|
@@ -74,14 +76,28 @@ class Foo < Angelo::Base
|
|
74
76
|
websockets[:hearts] << ws
|
75
77
|
end
|
76
78
|
|
77
|
-
# this is a call to Base.
|
79
|
+
# this is a call to Base.task, defining the task
|
78
80
|
# to perform on the reactor
|
79
81
|
#
|
80
|
-
|
82
|
+
task :hearts do
|
81
83
|
@@hearting = true
|
82
84
|
every(10){ websockets[:hearts].each {|ws| ws.write HEART } }
|
83
85
|
end
|
84
86
|
|
87
|
+
post '/in/:sec/sec/:msg' do
|
88
|
+
|
89
|
+
# this is a call to Base#future, telling the reactor
|
90
|
+
# do this thing and we'' want the value eventually
|
91
|
+
#
|
92
|
+
f = future :in_sec params[:sec], params[:msg]
|
93
|
+
f.value
|
94
|
+
end
|
95
|
+
|
96
|
+
task :in_sec do |sec, msg|
|
97
|
+
sleep sec.to_i
|
98
|
+
msg
|
99
|
+
end
|
100
|
+
|
85
101
|
end
|
86
102
|
|
87
103
|
Foo.run
|
data/lib/angelo/base.rb
CHANGED
@@ -82,8 +82,8 @@ module Angelo
|
|
82
82
|
WebsocketResponder.on_pong = block
|
83
83
|
end
|
84
84
|
|
85
|
-
def
|
86
|
-
Angelo::Server.
|
85
|
+
def task name, &block
|
86
|
+
Angelo::Server.define_task name, &block
|
87
87
|
end
|
88
88
|
|
89
89
|
def websockets
|
@@ -112,6 +112,10 @@ module Angelo
|
|
112
112
|
self.class.server.async.__send__ meth, *args
|
113
113
|
end
|
114
114
|
|
115
|
+
def future meth, *args
|
116
|
+
self.class.server.future.__send__ meth, *args
|
117
|
+
end
|
118
|
+
|
115
119
|
def params
|
116
120
|
@params ||= case request.method
|
117
121
|
when GET; parse_query_string
|
@@ -122,7 +126,18 @@ module Angelo
|
|
122
126
|
|
123
127
|
def websockets; self.class.websockets; end
|
124
128
|
|
125
|
-
|
129
|
+
def request_headers
|
130
|
+
@request_headers ||= Hash.new do |hash, key|
|
131
|
+
if Symbol === key
|
132
|
+
k = key.to_s.upcase
|
133
|
+
k.gsub! UNDERSCORE, DASH
|
134
|
+
rhv = request.headers.select {|header_key,v| header_key.upcase == k}
|
135
|
+
hash[key] = rhv.values.first
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
task :handle_websocket do |ws|
|
126
141
|
begin
|
127
142
|
while !ws.closed? do
|
128
143
|
ws.read
|
@@ -132,7 +147,7 @@ module Angelo
|
|
132
147
|
end
|
133
148
|
end
|
134
149
|
|
135
|
-
|
150
|
+
task :ping_websockets do
|
136
151
|
every(@@ping_time) do
|
137
152
|
websockets.all.each do |ws|
|
138
153
|
ws.socket << ::WebSocket::Message.ping.to_data
|
data/lib/angelo/responder.rb
CHANGED
@@ -46,6 +46,7 @@ module Angelo
|
|
46
46
|
|
47
47
|
def request= request
|
48
48
|
@params = nil
|
49
|
+
@redirect = nil
|
49
50
|
@request = request
|
50
51
|
handle_request
|
51
52
|
respond
|
@@ -121,18 +122,21 @@ module Angelo
|
|
121
122
|
when Hash
|
122
123
|
raise 'html response requires String' if respond_with? :html
|
123
124
|
@body.to_json if respond_with? :json
|
125
|
+
when NilClass
|
126
|
+
EMPTY_STRING
|
124
127
|
end
|
125
|
-
|
126
|
-
@
|
128
|
+
|
129
|
+
status = @redirect.nil? ? :ok : :moved_permanently
|
130
|
+
headers LOCATION_HEADER_KEY => @redirect if @redirect
|
131
|
+
|
132
|
+
Angelo.log @connection, @request, nil, status, @body.size
|
133
|
+
@connection.respond status, headers, @body
|
127
134
|
rescue => e
|
128
135
|
handle_error e, :internal_server_error, false
|
129
136
|
end
|
130
137
|
|
131
138
|
def redirect url
|
132
|
-
|
133
|
-
@connection.respond :moved_permanently, headers(LOCATION_HEADER_KEY => url), ''
|
134
|
-
rescue => e
|
135
|
-
handle_error e, :internal_server_error, false
|
139
|
+
@redirect = url
|
136
140
|
end
|
137
141
|
|
138
142
|
end
|
data/lib/angelo/server.rb
CHANGED
@@ -25,11 +25,11 @@ module Angelo
|
|
25
25
|
# RubyProf.pause
|
26
26
|
end
|
27
27
|
|
28
|
-
def self.
|
28
|
+
def self.define_task name, &action
|
29
29
|
define_method name, &action
|
30
30
|
end
|
31
31
|
|
32
|
-
def self.
|
32
|
+
def self.remove_task name
|
33
33
|
remove_method name
|
34
34
|
end
|
35
35
|
|
data/lib/angelo/version.rb
CHANGED
data/lib/angelo.rb
CHANGED
data/spec/angelo_spec.rb
CHANGED
@@ -122,6 +122,36 @@ describe Angelo::Base do
|
|
122
122
|
|
123
123
|
end
|
124
124
|
|
125
|
+
describe 'headers helper' do
|
126
|
+
|
127
|
+
headers_count = 0
|
128
|
+
|
129
|
+
define_app do
|
130
|
+
|
131
|
+
put '/incr' do
|
132
|
+
headers 'X-Http-Angelo-Server' => 'catbutt' if headers_count % 2 == 0
|
133
|
+
headers_count += 1
|
134
|
+
''
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'sets headers for a response' do
|
140
|
+
put '/incr'
|
141
|
+
expect(last_response.headers['X-Http-Angelo-Server']).to eq('catbutt')
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'does not carry headers over responses' do
|
145
|
+
headers_count = 0
|
146
|
+
put '/incr'
|
147
|
+
expect(last_response.headers['X-Http-Angelo-Server']).to eq('catbutt')
|
148
|
+
|
149
|
+
put '/incr'
|
150
|
+
expect(last_response.headers['X-Http-Angelo-Server']).to be_nil
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
125
155
|
describe 'content_type helper' do
|
126
156
|
|
127
157
|
describe 'when in route block' do
|
@@ -315,4 +345,39 @@ describe Angelo::Base do
|
|
315
345
|
|
316
346
|
end
|
317
347
|
|
348
|
+
describe 'request_headers helper' do
|
349
|
+
|
350
|
+
define_app do
|
351
|
+
|
352
|
+
get '/rh' do
|
353
|
+
content_type :json
|
354
|
+
{ values: [
|
355
|
+
request_headers[params[:hk_1].to_sym],
|
356
|
+
request_headers[params[:hk_2].to_sym],
|
357
|
+
request_headers[params[:hk_3].to_sym]
|
358
|
+
]
|
359
|
+
}
|
360
|
+
end
|
361
|
+
|
362
|
+
end
|
363
|
+
|
364
|
+
it 'matches snakecased symbols against case insensitive header keys' do
|
365
|
+
ps = {
|
366
|
+
hk_1: 'foo_bar',
|
367
|
+
hk_2: 'x_http_mozilla_ie_safari_puke',
|
368
|
+
hk_3: 'authorization'
|
369
|
+
}
|
370
|
+
|
371
|
+
hs = {
|
372
|
+
'Foo-BAR' => 'abcdef',
|
373
|
+
'X-HTTP-Mozilla-IE-Safari-PuKe' => 'ghijkl',
|
374
|
+
'Authorization' => 'Bearer oauth_token_hi'
|
375
|
+
}
|
376
|
+
|
377
|
+
get '/rh', ps, hs
|
378
|
+
last_response_should_be_json 'values' => hs.values
|
379
|
+
end
|
380
|
+
|
381
|
+
end
|
382
|
+
|
318
383
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: angelo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenichi Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03
|
11
|
+
date: 2014-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reel
|