angelo 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/angelo/mustermann.rb +10 -2
- data/lib/angelo/responder/websocket.rb +1 -0
- data/lib/angelo/responder.rb +6 -1
- data/lib/angelo/server.rb +3 -14
- data/lib/angelo/version.rb +1 -1
- data/lib/angelo.rb +14 -0
- data/spec/angelo/mustermann_spec.rb +6 -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: 55ec6c0b7ba672c2c75bf6c18ea54e465dba68aa
|
4
|
+
data.tar.gz: 60d95a47a93e1509782c9967c0fc42f0e5d0b7e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bd103e7497922c6bf8489577f3f87d5bcbf046abf4524731b6c9c98c68f3791ca0dee51ed42232bd166d2c99ef9fc40d7f26fa1f8e6d19bbd62d4ffd9dee271
|
7
|
+
data.tar.gz: 3a33ada93accc65b7843d6c910e075932b5f556fede208eea01405d10361f458976199c0cd8086fb3048330f4eda8c4553435773f66a8df12c1cb35ad2785f11
|
data/lib/angelo/mustermann.rb
CHANGED
@@ -28,6 +28,11 @@ module Angelo
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
def socket path, &block
|
32
|
+
path = ::Mustermann.new path
|
33
|
+
routes[:socket][path] = WebsocketResponder.new &block
|
34
|
+
end
|
35
|
+
|
31
36
|
def routes
|
32
37
|
@routes ||= {}
|
33
38
|
ROUTABLE.each do |m|
|
@@ -44,9 +49,12 @@ module Angelo
|
|
44
49
|
|
45
50
|
class RouteMap < Hash
|
46
51
|
def [] route
|
52
|
+
responder = nil
|
47
53
|
mustermann = keys.select {|k| k.match(route)}.first
|
48
|
-
|
49
|
-
|
54
|
+
if mustermann
|
55
|
+
responder = fetch mustermann
|
56
|
+
responder.mustermann = mustermann
|
57
|
+
end
|
50
58
|
responder
|
51
59
|
end
|
52
60
|
end
|
data/lib/angelo/responder.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
1
3
|
module Angelo
|
2
4
|
|
3
5
|
class Responder
|
@@ -62,7 +64,9 @@ module Angelo
|
|
62
64
|
end
|
63
65
|
|
64
66
|
def handle_error _error, report = true
|
65
|
-
|
67
|
+
err_msg = error_message _error
|
68
|
+
Angelo.log @connection, @request, nil, :internal_server_error, err_msg.size
|
69
|
+
@connection.respond :internal_server_error, headers, err_msg
|
66
70
|
@connection.close
|
67
71
|
if report
|
68
72
|
error "#{_error.class} - #{_error.message}"
|
@@ -114,6 +118,7 @@ module Angelo
|
|
114
118
|
raise 'html response requires String' if respond_with? :html
|
115
119
|
@body.to_json if respond_with? :json
|
116
120
|
end
|
121
|
+
Angelo.log @connection, @request, nil, :ok, @body.size
|
117
122
|
@connection.respond :ok, headers, @body
|
118
123
|
rescue => e
|
119
124
|
handle_error e, false
|
data/lib/angelo/server.rb
CHANGED
@@ -13,26 +13,14 @@ module Angelo
|
|
13
13
|
def on_connection connection
|
14
14
|
# RubyProf.resume
|
15
15
|
connection.each_request do |request|
|
16
|
-
|
17
|
-
|
18
|
-
route_websocket connection, request
|
19
|
-
else
|
20
|
-
route_request connection, request
|
21
|
-
end
|
16
|
+
meth = request.websocket? ? :socket : request.method.downcase.to_sym
|
17
|
+
route! meth, connection, request
|
22
18
|
end
|
23
19
|
# RubyProf.pause
|
24
20
|
end
|
25
21
|
|
26
22
|
private
|
27
23
|
|
28
|
-
def route_request connection, request
|
29
|
-
route! request.method.downcase.to_sym, connection, request
|
30
|
-
end
|
31
|
-
|
32
|
-
def route_websocket connection, request
|
33
|
-
route! :socket, connection, request
|
34
|
-
end
|
35
|
-
|
36
24
|
def route! meth, connection, request
|
37
25
|
rs = @base.routes[meth][request.path]
|
38
26
|
if rs
|
@@ -41,6 +29,7 @@ module Angelo
|
|
41
29
|
responder.connection = connection
|
42
30
|
responder.request = request
|
43
31
|
else
|
32
|
+
Angelo.log connection, request, nil, :not_found
|
44
33
|
connection.respond :not_found, DEFAULT_RESPONSE_HEADERS, NOT_FOUND
|
45
34
|
end
|
46
35
|
end
|
data/lib/angelo/version.rb
CHANGED
data/lib/angelo.rb
CHANGED
@@ -32,6 +32,20 @@ module Angelo
|
|
32
32
|
|
33
33
|
NOT_FOUND = 'Not Found'
|
34
34
|
|
35
|
+
LOG_FORMAT = '%s - - "%s %s%s HTTP/%s" %d %s'
|
36
|
+
|
37
|
+
def self.log connection, request, socket, status, body_size = '-'
|
38
|
+
Celluloid::Logger.debug LOG_FORMAT % [
|
39
|
+
socket.nil? ? connection.remote_ip : socket.peeraddr(false)[3],
|
40
|
+
request.method,
|
41
|
+
request.path,
|
42
|
+
request.query_string.nil? ? nil : '?'+request.query_string,
|
43
|
+
request.version,
|
44
|
+
Symbol === status ? HTTP::Response::SYMBOL_TO_STATUS_CODE[status] : status,
|
45
|
+
body_size
|
46
|
+
]
|
47
|
+
end
|
48
|
+
|
35
49
|
end
|
36
50
|
|
37
51
|
require 'angelo/version'
|
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.0
|
4
|
+
version: 0.1.0
|
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-02-
|
11
|
+
date: 2014-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reel
|