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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19662f6ad2cd2af07d8468c0db06e79cace30ad6
4
- data.tar.gz: e9f0dea09b6fdd129d627893024722dbce7a9836
3
+ metadata.gz: 55ec6c0b7ba672c2c75bf6c18ea54e465dba68aa
4
+ data.tar.gz: 60d95a47a93e1509782c9967c0fc42f0e5d0b7e0
5
5
  SHA512:
6
- metadata.gz: 878aefb22125a90079c96e8647ccb607eb96033ab6f898482c07210561ed5abb4e82c5af9e4fa34aa06306d1f39dd87f683e48a30b81df7d61d85e28dba1d9d3
7
- data.tar.gz: a7982735780dd4bd941c4a4a13d42857eaacfc95731c4b8c4aef19a0b36350221e41a1fd606356eb009dc2d43c425f97388327a2c979781b0350ad1bba3f343c
6
+ metadata.gz: 1bd103e7497922c6bf8489577f3f87d5bcbf046abf4524731b6c9c98c68f3791ca0dee51ed42232bd166d2c99ef9fc40d7f26fa1f8e6d19bbd62d4ffd9dee271
7
+ data.tar.gz: 3a33ada93accc65b7843d6c910e075932b5f556fede208eea01405d10361f458976199c0cd8086fb3048330f4eda8c4553435773f66a8df12c1cb35ad2785f11
@@ -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
- responder = fetch mustermann
49
- responder.mustermann = mustermann
54
+ if mustermann
55
+ responder = fetch mustermann
56
+ responder.mustermann = mustermann
57
+ end
50
58
  responder
51
59
  end
52
60
  end
@@ -17,6 +17,7 @@ module Angelo
17
17
  def handle_request
18
18
  begin
19
19
  if @response_handler
20
+ Angelo.log @connection, @request, @websocket, :switching_protocols
20
21
  @bound_response_handler ||= @response_handler.bind @base
21
22
  @bound_response_handler[@websocket]
22
23
  else
@@ -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
- @connection.respond :internal_server_error, headers, error_message(_error)
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
- if request.websocket?
17
- debug "got websocket request..."
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
@@ -1,3 +1,3 @@
1
1
  module Angelo
2
- VERSION = '0.0.9'
2
+ VERSION = '0.1.0'
3
3
  end
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'
@@ -49,6 +49,12 @@ if RUBY_VERSION =~ /^2\./
49
49
  end
50
50
  end
51
51
 
52
+ it '404s correctly for not found routes' do
53
+ path = '/bad/monkey'
54
+ get path
55
+ last_response.status.should eq 404
56
+ end
57
+
52
58
  end
53
59
 
54
60
  describe 'tilt/erb integration' do
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.9
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-20 00:00:00.000000000 Z
11
+ date: 2014-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reel