carnivore-http 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # v0.1.4
2
+ * Include custom `connect` to start source
3
+ * Pull query from body if found
4
+ * Fix worker size argument access
5
+ * Cleanup point matching implementation
6
+
1
7
  # v0.1.2
2
8
  * Include query parameters
3
9
  * Start basic test coverage
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- carnivore-http (0.1.1)
4
+ carnivore-http (0.1.3)
5
5
  blockenspiel
6
6
  carnivore (>= 0.1.8)
7
7
  reel
@@ -26,11 +26,9 @@ GEM
26
26
  http (0.5.0)
27
27
  http_parser.rb
28
28
  http_parser.rb (0.6.0.beta.2)
29
- http_parser.rb (0.6.0.beta.2-java)
30
29
  mixlib-config (2.0.0)
31
30
  multi_json (1.8.2)
32
31
  nio4r (0.5.0)
33
- nio4r (0.5.0-java)
34
32
  reel (0.4.0)
35
33
  celluloid (>= 0.15.1)
36
34
  celluloid-io (>= 0.15.0)
@@ -76,7 +76,7 @@ module Carnivore
76
76
  callbacks.each do |name|
77
77
  c_name = callback_name(name)
78
78
  debug "Dispatching #{msg} to callback<#{name} (#{c_name})>"
79
- Celluloid::Actor[c_name].async.call(msg)
79
+ callback_supervisor[c_name].async.call(msg)
80
80
  end
81
81
  con.respond(:ok, 'So long, and thanks for all the fish!') if args[:auto_respond]
82
82
  rescue => e
@@ -56,6 +56,10 @@ module Carnivore
56
56
  set_points
57
57
  end
58
58
 
59
+ def connect
60
+ async.process
61
+ end
62
+
59
63
  def process(*process_args)
60
64
  srv = Reel::Server.supervise(args[:bind], args[:port]) do |con|
61
65
  con.each_request do |req|
@@ -64,7 +68,7 @@ module Carnivore
64
68
  :request => req,
65
69
  :body => req.body.to_s,
66
70
  :connection => con,
67
- :query => parse_query_string(req.query_string)
71
+ :query => parse_query_string(req.query_string).merge(parse_query_string(req.body.to_s))
68
72
  )
69
73
  unless(@points.deliver(msg))
70
74
  con.respond(:ok, 'So long, and thanks for all the fish!')
@@ -34,7 +34,7 @@ module Carnivore
34
34
  include Celluloid::Logger
35
35
  include Blockenspiel::DSL
36
36
 
37
- attr_reader :static, :regex, :only, :except
37
+ attr_reader :static, :regex, :only, :except, :endpoint_supervisor
38
38
 
39
39
  def initialize(args)
40
40
  @only = args[:only]
@@ -42,7 +42,7 @@ module Carnivore
42
42
  @static = {}
43
43
  @regex = {}
44
44
  @callback_names = {}
45
- @endpoint_supervisor = Celluloid::SupervisionGroup.run!
45
+ @endpoint_supervisor = Carnivore::Supervisor.create!.last
46
46
  load_endpoints!
47
47
  end
48
48
 
@@ -63,14 +63,14 @@ module Carnivore
63
63
  def static_points(msg, type, path)
64
64
  if(static[type])
65
65
  match = static[type].keys.detect do |point|
66
- path.sub(%r{/$}, '') == point
66
+ !path.scan(/^#{Regexp.escape(point)}\/?(\?|$)/).empty?
67
67
  end
68
68
  if(match)
69
69
  if(static[type][match][:async])
70
- Celluloid::Actor[callback_name(match, type)].async.execute(msg)
70
+ endpoint_supervisor[callback_name(match, type)].async.execute(msg)
71
71
  true
72
72
  else
73
- Celluloid::Actor[callback_name(match, type)].execute(msg)
73
+ endpoint_supervisor[callback_name(match, type)].execute(msg)
74
74
  true
75
75
  end
76
76
  end
@@ -80,16 +80,18 @@ module Carnivore
80
80
  def regex_points(msg, type, path)
81
81
  if(regex[type])
82
82
  match = regex[type].keys.map do |point|
83
- unless((res = path.scan(/^#{point}$/)).empty?)
84
- [point, res.first.is_a?(Array) ? res.first : []]
83
+ unless((res = path.scan(/^(#{point})(\?|$)/)).empty?)
84
+ res = res.first
85
+ res.pop # remove empty EOS match
86
+ [point, res]
85
87
  end
86
88
  end.compact.first
87
89
  if(match && !match.empty?)
88
90
  if(regex[type][match.first][:async])
89
- Celluloid::Actor[callback_name(match.first, type)].async.execute(*([msg] + match.last))
91
+ endpoint_supervisor[callback_name(match.first, type)].async.execute(*([msg] + match.last))
90
92
  true
91
93
  else
92
- Celluloid::Actor[callback_name(match.first, type)].execute(*([msg] + match.last))
94
+ endpoint_supervisor[callback_name(match.first, type)].execute(*([msg] + match.last))
93
95
  true
94
96
  end
95
97
  end
@@ -114,12 +116,12 @@ module Carnivore
114
116
  static[request_type][regexp_or_string.sub(%r{/$}, '')] = args
115
117
  end
116
118
  if(args[:workers] && args[:workers].to_i > 1)
117
- @endpoint_supervisor.pool(Endpoint,
118
- as: callback_name(regexp_or_string, request_type), size: args[:workers.to_i],
119
+ endpoint_supervisor.pool(Endpoint,
120
+ as: callback_name(regexp_or_string, request_type), size: args[:workers].to_i,
119
121
  args: [request_type, regexp_or_string, block]
120
122
  )
121
123
  else
122
- @endpoint_supervisor.supervise_as(
124
+ endpoint_supervisor.supervise_as(
123
125
  callback_name(regexp_or_string, request_type), Endpoint, request_type, regexp_or_string, block
124
126
  )
125
127
  end
@@ -2,6 +2,6 @@ module Carnivore
2
2
  module Http
3
3
  class Version < Gem::Version
4
4
  end
5
- VERSION = Version.new('0.1.2')
5
+ VERSION = Version.new('0.1.4')
6
6
  end
7
7
  end
data/test/specs/http.rb CHANGED
@@ -17,7 +17,7 @@ describe 'Carnivore::Source::Http' do
17
17
  )
18
18
  t = Thread.new{ Carnivore.start! }
19
19
  source_wait
20
- Celluloid::Actor[:http_source].wont_be_nil
20
+ Carnivore::Supervisor.supervisor[:http_source].wont_be_nil
21
21
  t.terminate
22
22
  end
23
23
 
@@ -46,11 +46,11 @@ describe 'Carnivore::Source::Http' do
46
46
 
47
47
  describe 'message transmissions' do
48
48
  it 'should accept message transmits' do
49
- Celluloid::Actor[:http_source].transmit('test message')
49
+ Carnivore::Supervisor.supervisor[:http_source].transmit('test message')
50
50
  end
51
51
 
52
52
  it 'should receive messages' do
53
- Celluloid::Actor[:http_source].transmit('test message 2')
53
+ Carnivore::Supervisor.supervisor[:http_source].transmit('test message 2')
54
54
  source_wait
55
55
  MessageStore.messages.pop.must_equal 'test message 2'
56
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carnivore-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-06 00:00:00.000000000 Z
12
+ date: 2014-01-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: carnivore