rack-mongrel2 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gemspec
3
+ gemspec
4
+
5
+ # For development
6
+ gem 'yajl-ruby', '~> 0.7.8', :require => 'yajl'
7
+ gem 'zmq', '~> 2.0.9'
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Daniel Huckstep
1
+ Copyright (c) 2009, 2010 Daniel Huckstep
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -24,7 +24,7 @@ Check out the blog post too: http://blog.darkhax.com/2010/10/26/deploying-your-r
24
24
 
25
25
  ## Thanks!
26
26
 
27
- * Kevin Williams for PULL, specs, and other things.
27
+ * [Kevin Williams](https://github.com/kevwil) for PULL, specs, and other things.
28
28
 
29
29
  ## Note on Patches/Pull Requests
30
30
 
data/Rakefile CHANGED
@@ -43,13 +43,12 @@ end
43
43
  #
44
44
  #############################################################################
45
45
 
46
- task :default => :test
46
+ task :default => :spec
47
47
 
48
- require 'rake/testtask'
49
- Rake::TestTask.new(:test) do |test|
50
- test.libs << 'lib' << 'test'
51
- test.pattern = 'test/**/test_*.rb'
52
- test.verbose = true
48
+ require 'rspec/core/rake_task'
49
+ RSpec::Core::RakeTask.new(:spec) do |t|
50
+ t.ruby_opts = ['-Ilib', '-Ispec']
51
+ t.pattern = 'spec/**/*_spec.rb'
53
52
  end
54
53
 
55
54
  desc "Open an irb session preloaded with this library"
@@ -63,25 +62,15 @@ end
63
62
  #
64
63
  #############################################################################
65
64
 
66
- require 'rspec/core/rake_task'
67
- RSpec::Core::RakeTask.new(:spec) do |t|
68
- t.ruby_opts = ['-Ilib', '-Ispec']
69
- t.pattern = 'spec/**/*_spec.rb'
70
- end
71
-
72
- RSpec::Core::RakeTask.new(:rcov) do |t|
73
- t.ruby_opts = ['-Ilib', '-Ispec']
74
- t.pattern = 'spec/**/*_spec.rb'
75
- t.rcov = true
65
+ begin
66
+ require 'yard'
67
+ YARD::Rake::YardocTask.new
68
+ rescue LoadError
69
+ task :yardoc do
70
+ abort 'YARD is not available. In order to run yardoc, you must: `gem i yard`'
71
+ end
76
72
  end
77
73
 
78
- # task :spec => :check_dependencies
79
-
80
- task :default => :spec
81
-
82
- require 'yard'
83
- YARD::Rake::YardocTask.new
84
-
85
74
  #############################################################################
86
75
  #
87
76
  # Packaging tasks
@@ -1,24 +1,7 @@
1
1
  require 'sinatra'
2
+ require 'yajl/json_gem'
2
3
 
3
4
  get '*' do
4
- 'Hello, World!'
5
- # items = request.env.map do |k,v|
6
- # "<li><strong>#{k}</strong>: #{v}</li>"
7
- # end.join("\n")
8
- # %Q{
9
- # <html>
10
- # <head>
11
- # <title>Sinatra Mongrel2 Test</title>
12
- # </head>
13
- # <body>
14
- # <h1>env</h1>
15
- # <ul>
16
- # #{items}
17
- # </ul>
18
- # <hr />
19
- # <h1>Params</h1>
20
- # #{params}
21
- # </body>
22
- # </html>
23
- # }
5
+ sleep(5)
6
+ request.env.to_json
24
7
  end
data/lib/mongrel2.rb CHANGED
@@ -4,11 +4,11 @@ rescue LoadError
4
4
  begin
5
5
  require 'json'
6
6
  rescue LoadError
7
- raise "You need either the yajl or json gems present in order to parse JSON!"
7
+ raise "You need either the yajl-ruby or json gems present in order to parse JSON!"
8
8
  end
9
9
  end
10
10
 
11
11
  module Mongrel2
12
12
  JSON = Object.const_defined?('Yajl') ? ::Yajl::Parser : ::JSON
13
- VERSION = '0.2.1'
13
+ VERSION = '0.2.2'
14
14
  end
@@ -6,8 +6,8 @@ module Mongrel2
6
6
  class Connection
7
7
  CTX = ZMQ::Context.new(1)
8
8
 
9
- def initialize(uuid, sub, pub, block = true)
10
- @uuid, @sub, @pub, @block = uuid, sub, pub, block
9
+ def initialize(uuid, sub, pub)
10
+ @uuid, @sub, @pub = uuid, sub, pub
11
11
 
12
12
  # Connect to receive requests
13
13
  @reqs = CTX.socket(ZMQ::PULL)
@@ -20,12 +20,14 @@ module Mongrel2
20
20
  end
21
21
 
22
22
  def recv
23
- msg = @reqs.recv_string(@block ? 0 : ZMQ::NOBLOCK)
23
+ msg = @reqs.recv_string(0)
24
24
  msg.nil? ? nil : Request.parse(msg)
25
25
  end
26
26
 
27
27
  def reply(req, body, status = 200, headers = {})
28
- Response.new(@resp).send_http(req, body, status, headers)
28
+ resp = Response.new(@resp)
29
+ resp.send_http(req, body, status, headers)
30
+ resp.close if req.close?
29
31
  end
30
32
 
31
33
  def close
@@ -32,5 +32,9 @@ module Mongrel2
32
32
  def disconnect?
33
33
  headers['METHOD'] == 'JSON' && @data['type'] == 'disconnect'
34
34
  end
35
+
36
+ def close?
37
+ headers['connection'] == 'close' || headers['VERSION'] == 'HTTP/1.0'
38
+ end
35
39
  end
36
40
  end
@@ -50,9 +50,9 @@ module Mongrel2
50
50
  def send_http(req, body, status, headers)
51
51
  send_resp(req.uuid, req.conn_id, build_http_response(body, status, headers))
52
52
  end
53
-
53
+
54
54
  def close(req)
55
- send_resp(req.uuid, req.conn_id, "")
55
+ send_resp(req.uuid, req.conn_id, '')
56
56
  end
57
57
 
58
58
  private
@@ -9,29 +9,27 @@ module Rack
9
9
  options = {
10
10
  :recv => 'tcp://127.0.0.1:9997' || ENV['RACK_MONGREL2_RECV'],
11
11
  :send => 'tcp://127.0.0.1:9996' || ENV['RACK_MONGREL2_SEND'],
12
- :uuid => ENV['RACK_MONGREL2_UUID'],
13
- :block => ENV['RACK_MONGREL2_NONBLOCK'].to_s.match(/1|t(?:rue)?|y(?:es)/i).nil?
12
+ :uuid => ENV['RACK_MONGREL2_UUID']
14
13
  }.merge(options)
15
14
 
16
15
  raise ArgumentError.new('Must specify an :uuid or set RACK_MONGREL2_UUID') if options[:uuid].nil?
17
16
 
18
- conn = ::Mongrel2::Connection.new(options[:uuid], options[:recv], options[:send], options[:block])
17
+ conn = ::Mongrel2::Connection.new(options[:uuid], options[:recv], options[:send])
19
18
 
20
19
  running = true
21
20
 
22
- # This doesn't work at all until zmq fixes their shit
23
- # %w(INT TERM KILL).each do |sig|
24
- # trap(sig) do
25
- # conn.close
26
- # running = false
27
- # end
28
- # end
21
+ # This doesn't work at all until zmq fixes their shit (in 2.1.x I think), but trap it now anyway.
22
+ %w(INT TERM KILL).each do |sig|
23
+ trap(sig) do
24
+ conn.close
25
+ running = false
26
+ end
27
+ end
29
28
 
30
29
  while running
31
- req = conn.recv
32
- sleep(1) and next if req.nil? && options[:block]
30
+ req = conn.recv rescue nil
33
31
  next if req.nil? || req.disconnect?
34
- return if !running
32
+ break if !running
35
33
 
36
34
  script_name = ENV['RACK_RELATIVE_URL_ROOT'] || req.headers['PATTERN'].split('(', 2).first.gsub(/\/$/, '')
37
35
  env = {
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'rack-mongrel2'
16
- s.version = '0.2.1'
17
- s.date = '2010-11-28'
16
+ s.version = '0.2.2'
17
+ s.date = '2010-12-31'
18
18
  s.rubyforge_project = 'rack-mongrel2'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -40,14 +40,14 @@ Gem::Specification.new do |s|
40
40
 
41
41
  ## List your runtime dependencies here. Runtime dependencies are those
42
42
  ## that are needed for an end user to actually USE your code.
43
- s.add_dependency('ffi', ['~> 0.6.3'])
44
- s.add_dependency('ffi-rzmq', ['~> 0.6.0'])
43
+ s.add_dependency('ffi', ['~> 1.0.0'])
44
+ s.add_dependency('ffi-rzmq', ['~> 0.7.0'])
45
45
 
46
46
  ## List your development dependencies here. Development dependencies are
47
47
  ## those that are only needed during development
48
- s.add_development_dependency('rspec', ['~> 2.2.0'])
49
- s.add_development_dependency('fuubar', ['~> 0.0.2'])
50
- s.add_development_dependency('yard', ['~> 0.6.3'])
48
+ s.add_development_dependency('rspec', ['~> 2.3.0'])
49
+ s.add_development_dependency('fuubar', ['~> 0.0.3'])
50
+ s.add_development_dependency('yard', ['~> 0.6.4'])
51
51
 
52
52
  ## Leave this section as-is. It will be automatically generated from the
53
53
  ## contents of your Git repository via the gemspec task. DO NOT REMOVE
@@ -71,7 +71,6 @@ Gem::Specification.new do |s|
71
71
  rack-mongrel2.gemspec
72
72
  spec/request_spec.rb
73
73
  spec/response_spec.rb
74
- spec/spec.opts
75
74
  spec/spec_helper.rb
76
75
  ]
77
76
  # = MANIFEST =
data/spec/request_spec.rb CHANGED
@@ -1,46 +1,47 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'mongrel2/request'
2
3
 
3
- describe "Mongrel2::Request" do
4
-
5
- it "should parse a netstring and ignore the contents of the netstring as well as the trailing comma" do
6
- netstring = "9:aoeu:snth,"
4
+ describe Mongrel2::Request do
5
+ it 'should parse a netstring and ignore the contents of the netstring as well as the trailing comma' do
6
+ netstring = '9:aoeu:snth,'
7
7
  result = Mongrel2::Request.parse_netstring(netstring)
8
8
  result.length.should == 2
9
9
  result[0].length.should == 9
10
- result[0].should eql("aoeu:snth")
10
+ result[0].should eql('aoeu:snth')
11
11
  end
12
-
13
- it "should parse a netstring made up of multiple netstrings" do
14
- netstring = "9:aoeu:snth,16:aeou snth qwerty,"
12
+
13
+ it 'should parse a netstring made up of multiple netstrings' do
14
+ netstring = '9:aoeu:snth,16:aeou snth qwerty,'
15
15
  result = Mongrel2::Request.parse_netstring(netstring)
16
16
  result.length.should == 2
17
17
  result[0].length.should == 9
18
- result[0].should eql("aoeu:snth")
18
+ result[0].should eql('aoeu:snth')
19
19
  result[1].length.should == 20
20
- result[1].should eql("16:aeou snth qwerty,")
20
+ result[1].should eql('16:aeou snth qwerty,')
21
21
  end
22
-
23
- it "should fail if the netstring does not end in a comma" do
24
- expect{Mongrel2::Request.parse_netstring("3:foo")}.to raise_error(NameError)
22
+
23
+ it 'should fail if the netstring does not end in a comma' do
24
+ expect { Mongrel2::Request.parse_netstring('3:foo') }.to raise_error(NameError)
25
25
  end
26
-
26
+
27
27
  it "should parse a Mongrel2 message and have all parts populated" do
28
- netstring = "UUID CON PATH 232:{\"PATH\":\"/\",\"user-agent\":\"curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3\",\"host\":\"localhost:6767\",\"accept\":\"*/*\",\"x-forwarded-for\":\"::1\",\"METHOD\":\"GET\",\"VERSION\":\"HTTP/1.1\",\"URI\":\"/\",\"PATTERN\":\"/\"},0:,"
28
+ netstring = "UUID CON PATH 253:{\"PATH\":\"/\",\"user-agent\":\"curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3\",\"host\":\"localhost:6767\",\"accept\":\"*/*\",\"connection\":\"close\",\"x-forwarded-for\":\"::1\",\"METHOD\":\"GET\",\"VERSION\":\"HTTP/1.1\",\"URI\":\"/\",\"PATTERN\":\"/\"},0:,"
29
29
  r = Mongrel2::Request.parse(netstring)
30
30
  r.should_not be_nil
31
- r.uuid.should eql("UUID")
32
- r.conn_id.should eql("CON")
33
- r.path.should eql("PATH")
31
+ r.uuid.should eql('UUID')
32
+ r.conn_id.should eql('CON')
33
+ r.path.should eql('PATH')
34
34
  r.body.length.should == 0
35
- r.headers.length.should == 9
36
- r.headers["PATH"].should eql("/")
37
- r.headers["user-agent"].should eql("curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3")
38
- r.headers["host"].should eql("localhost:6767")
39
- r.headers["accept"].should eql("*/*")
40
- r.headers["x-forwarded-for"].should eql("::1")
41
- r.headers["METHOD"].should eql("GET")
42
- r.headers["VERSION"].should eql("HTTP/1.1")
43
- r.headers["URI"].should eql("/")
44
- r.headers["PATTERN"].should eql("/")
35
+ r.headers.length.should == 10
36
+ r.headers['PATH'].should eql('/')
37
+ r.headers['user-agent'].should eql('curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3')
38
+ r.headers['host'].should eql('localhost:6767')
39
+ r.headers['accept'].should eql('*/*')
40
+ r.headers['x-forwarded-for'].should eql('::1')
41
+ r.headers['METHOD'].should eql('GET')
42
+ r.headers['VERSION'].should eql('HTTP/1.1')
43
+ r.headers['URI'].should eql('/')
44
+ r.headers['PATTERN'].should eql('/')
45
+ r.close?.should be_true
45
46
  end
46
47
  end
@@ -1,30 +1,30 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'mongrel2/response'
2
3
 
3
- describe "Mongrel2::Response" do
4
+ describe Mongrel2::Response do
4
5
  before(:each) do
5
6
  @req = double()
6
7
  @resp = double()
7
8
  @response = Mongrel2::Response.new(@resp)
8
9
  end
9
-
10
- it "should build the HTTP request format" do
11
- @req.should_receive(:uuid) {"UUID"}
12
- @req.should_receive(:conn_id) {"CONN_ID"}
13
-
10
+
11
+ it 'should build the HTTP request format' do
12
+ @req.should_receive(:uuid) { 'UUID' }
13
+ @req.should_receive(:conn_id) { 'CONN_ID' }
14
+
14
15
  httpreq = "UUID 7:CONN_ID, HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\nBoo!"
15
16
  @resp.should_receive(:send_string).with(httpreq)
16
-
17
- @response.send_http(@req, "Boo!", 200, {})
17
+
18
+ @response.send_http(@req, 'Boo!', 200, {})
18
19
  end
19
-
20
- it "should send a blank response to close the response" do
21
- @req.should_receive(:uuid) {"UUID"}
22
- @req.should_receive(:conn_id) {"CONN_ID"}
23
-
24
- httpreq = "UUID 7:CONN_ID, "
20
+
21
+ it 'should send a blank response to close the response' do
22
+ @req.should_receive(:uuid) { 'UUID' }
23
+ @req.should_receive(:conn_id) { 'CONN_ID' }
24
+
25
+ httpreq = 'UUID 7:CONN_ID, '
25
26
  @resp.should_receive(:send_string).with(httpreq)
26
-
27
+
27
28
  @response.close(@req)
28
29
  end
29
-
30
30
  end
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,3 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'mongrel2'
4
- require 'mongrel2/connection'
5
- require 'mongrel2/request'
6
- require 'mongrel2/response'
7
- require 'rspec'
8
- require 'rspec/autorun'
9
-
10
- RSpec.configure do |config|
11
-
12
- end
3
+ require 'rspec'
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-mongrel2
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 19
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
8
  - 2
8
- - 1
9
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
10
11
  platform: ruby
11
12
  authors:
12
13
  - Daniel Huckstep
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-11-28 00:00:00 -07:00
18
+ date: 2010-12-31 00:00:00 -07:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,11 +26,12 @@ dependencies:
25
26
  requirements:
26
27
  - - ~>
27
28
  - !ruby/object:Gem::Version
29
+ hash: 23
28
30
  segments:
31
+ - 1
29
32
  - 0
30
- - 6
31
- - 3
32
- version: 0.6.3
33
+ - 0
34
+ version: 1.0.0
33
35
  type: :runtime
34
36
  version_requirements: *id001
35
37
  - !ruby/object:Gem::Dependency
@@ -40,11 +42,12 @@ dependencies:
40
42
  requirements:
41
43
  - - ~>
42
44
  - !ruby/object:Gem::Version
45
+ hash: 3
43
46
  segments:
44
47
  - 0
45
- - 6
48
+ - 7
46
49
  - 0
47
- version: 0.6.0
50
+ version: 0.7.0
48
51
  type: :runtime
49
52
  version_requirements: *id002
50
53
  - !ruby/object:Gem::Dependency
@@ -55,11 +58,12 @@ dependencies:
55
58
  requirements:
56
59
  - - ~>
57
60
  - !ruby/object:Gem::Version
61
+ hash: 3
58
62
  segments:
59
63
  - 2
60
- - 2
64
+ - 3
61
65
  - 0
62
- version: 2.2.0
66
+ version: 2.3.0
63
67
  type: :development
64
68
  version_requirements: *id003
65
69
  - !ruby/object:Gem::Dependency
@@ -70,11 +74,12 @@ dependencies:
70
74
  requirements:
71
75
  - - ~>
72
76
  - !ruby/object:Gem::Version
77
+ hash: 25
73
78
  segments:
74
79
  - 0
75
80
  - 0
76
- - 2
77
- version: 0.0.2
81
+ - 3
82
+ version: 0.0.3
78
83
  type: :development
79
84
  version_requirements: *id004
80
85
  - !ruby/object:Gem::Dependency
@@ -85,11 +90,12 @@ dependencies:
85
90
  requirements:
86
91
  - - ~>
87
92
  - !ruby/object:Gem::Version
93
+ hash: 15
88
94
  segments:
89
95
  - 0
90
96
  - 6
91
- - 3
92
- version: 0.6.3
97
+ - 4
98
+ version: 0.6.4
93
99
  type: :development
94
100
  version_requirements: *id005
95
101
  description: A Rack handler for the Mongrel2 web server, by Zed Shaw. http://mongrel2.org/
@@ -119,7 +125,6 @@ files:
119
125
  - rack-mongrel2.gemspec
120
126
  - spec/request_spec.rb
121
127
  - spec/response_spec.rb
122
- - spec/spec.opts
123
128
  - spec/spec_helper.rb
124
129
  has_rdoc: true
125
130
  homepage: http://github.com/darkhelmet/rack-mongrel2
@@ -135,6 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
140
  requirements:
136
141
  - - ">="
137
142
  - !ruby/object:Gem::Version
143
+ hash: 3
138
144
  segments:
139
145
  - 0
140
146
  version: "0"
@@ -143,13 +149,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
149
  requirements:
144
150
  - - ">="
145
151
  - !ruby/object:Gem::Version
152
+ hash: 3
146
153
  segments:
147
154
  - 0
148
155
  version: "0"
149
156
  requirements: []
150
157
 
151
158
  rubyforge_project: rack-mongrel2
152
- rubygems_version: 1.3.7
159
+ rubygems_version: 1.4.1
153
160
  signing_key:
154
161
  specification_version: 2
155
162
  summary: The only Mongrel2 Rack handler you'll ever need.
data/spec/spec.opts DELETED
@@ -1,2 +0,0 @@
1
- --format Fuubar
2
- --color