rack-mongrel2 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -1
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/Rakefile +12 -23
- data/example/sinatra/app.rb +3 -20
- data/lib/mongrel2.rb +2 -2
- data/lib/mongrel2/connection.rb +6 -4
- data/lib/mongrel2/request.rb +4 -0
- data/lib/mongrel2/response.rb +2 -2
- data/lib/rack/handler/mongrel2.rb +11 -13
- data/rack-mongrel2.gemspec +7 -8
- data/spec/request_spec.rb +29 -28
- data/spec/response_spec.rb +16 -16
- data/spec/spec_helper.rb +1 -10
- metadata +24 -17
- data/spec/spec.opts +0 -2
data/Gemfile
CHANGED
data/LICENSE
CHANGED
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 => :
|
46
|
+
task :default => :spec
|
47
47
|
|
48
|
-
require '
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
data/example/sinatra/app.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
require 'sinatra'
|
2
|
+
require 'yajl/json_gem'
|
2
3
|
|
3
4
|
get '*' do
|
4
|
-
|
5
|
-
|
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.
|
13
|
+
VERSION = '0.2.2'
|
14
14
|
end
|
data/lib/mongrel2/connection.rb
CHANGED
@@ -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
|
10
|
-
@uuid, @sub, @pub
|
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(
|
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)
|
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
|
data/lib/mongrel2/request.rb
CHANGED
data/lib/mongrel2/response.rb
CHANGED
@@ -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]
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
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 = {
|
data/rack-mongrel2.gemspec
CHANGED
@@ -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.
|
17
|
-
s.date = '2010-
|
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.
|
44
|
-
s.add_dependency('ffi-rzmq', ['~> 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.
|
49
|
-
s.add_development_dependency('fuubar', ['~> 0.0.
|
50
|
-
s.add_development_dependency('yard', ['~> 0.6.
|
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
|
4
|
-
|
5
|
-
|
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(
|
10
|
+
result[0].should eql('aoeu:snth')
|
11
11
|
end
|
12
|
-
|
13
|
-
it
|
14
|
-
netstring =
|
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(
|
18
|
+
result[0].should eql('aoeu:snth')
|
19
19
|
result[1].length.should == 20
|
20
|
-
result[1].should eql(
|
20
|
+
result[1].should eql('16:aeou snth qwerty,')
|
21
21
|
end
|
22
|
-
|
23
|
-
it
|
24
|
-
expect{Mongrel2::Request.parse_netstring(
|
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
|
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(
|
32
|
-
r.conn_id.should eql(
|
33
|
-
r.path.should eql(
|
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 ==
|
36
|
-
r.headers[
|
37
|
-
r.headers[
|
38
|
-
r.headers[
|
39
|
-
r.headers[
|
40
|
-
r.headers[
|
41
|
-
r.headers[
|
42
|
-
r.headers[
|
43
|
-
r.headers[
|
44
|
-
r.headers[
|
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
|
data/spec/response_spec.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'mongrel2/response'
|
2
3
|
|
3
|
-
describe
|
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
|
11
|
-
@req.should_receive(:uuid) {
|
12
|
-
@req.should_receive(: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,
|
17
|
+
|
18
|
+
@response.send_http(@req, 'Boo!', 200, {})
|
18
19
|
end
|
19
|
-
|
20
|
-
it
|
21
|
-
@req.should_receive(:uuid) {
|
22
|
-
@req.should_receive(:conn_id) {
|
23
|
-
|
24
|
-
httpreq =
|
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 '
|
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
|
-
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
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-
|
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
|
-
-
|
31
|
-
|
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
|
-
-
|
48
|
+
- 7
|
46
49
|
- 0
|
47
|
-
version: 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
|
-
-
|
64
|
+
- 3
|
61
65
|
- 0
|
62
|
-
version: 2.
|
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
|
-
-
|
77
|
-
version: 0.0.
|
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
|
-
-
|
92
|
-
version: 0.6.
|
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.
|
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