rack-mongrel2 0.1.0 → 0.1.1
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/README.rdoc +21 -2
- data/VERSION +1 -1
- data/example/mongrel2.conf +26 -0
- data/example/sinatra/app.rb +24 -0
- data/example/sinatra/config.ru +6 -0
- data/lib/mongrel2/connection.rb +5 -5
- data/lib/mongrel2/request.rb +2 -0
- data/lib/rack/handler/mongrel2.rb +8 -5
- data/rack-mongrel2.gemspec +5 -3
- metadata +7 -5
- data/lib/rack-mongrel2.rb +0 -0
data/README.rdoc
CHANGED
@@ -1,9 +1,28 @@
|
|
1
1
|
= rack-mongrel2
|
2
2
|
|
3
|
-
|
3
|
+
The only Mongrel2 Rack handler you'll ever need.
|
4
|
+
|
5
|
+
I wrote this because I wanted to learn Mongrel2, and I didn't like what was out there. I copy-pasted a lot of code from Colin Curtin's m2r project (http://github.com/perplexes/m2r), but I also changed and reorganized it into what I believe is a good setup for a proper rubygem. I used the ruby zmq library instead of the ffi version, so we'll see how that works out.
|
6
|
+
|
7
|
+
== How to use
|
8
|
+
|
9
|
+
1. Get mongrel2 installed (http://mongrel2.org/wiki?name=GettingStarted)
|
10
|
+
2. Get your config for mongrel2 setup (see example directory)
|
11
|
+
3. Add it to your Gemfile
|
12
|
+
|
13
|
+
gem 'rack-mongrel2', '~> 0.1.0', :require => nil
|
14
|
+
|
15
|
+
4. Run Mongrel2
|
16
|
+
5. Run your rails application
|
17
|
+
|
18
|
+
RACK_MONGREL2_UUID=<my uuid> rails s Mongrel2
|
19
|
+
|
20
|
+
6. Profit!
|
21
|
+
|
22
|
+
I'll write a better blog post soon...
|
4
23
|
|
5
24
|
== Note on Patches/Pull Requests
|
6
|
-
|
25
|
+
|
7
26
|
* Fork the project.
|
8
27
|
* Make your feature addition or bug fix.
|
9
28
|
* Add tests for it. This is important so I don't break it in a
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -0,0 +1,26 @@
|
|
1
|
+
darkblog2 = Host(name='localhost', routes={
|
2
|
+
'/': Handler(send_spec='tcp://127.0.0.1:9997',
|
3
|
+
send_ident='9539ED88-1B33-4D19-A9F9-283E5BF11AC7',
|
4
|
+
recv_spec='tcp://127.0.0.1:9996',
|
5
|
+
recv_ident='')
|
6
|
+
})
|
7
|
+
|
8
|
+
main = Server(
|
9
|
+
uuid='94601E4B-A770-4B7D-930D-CE3A484B5280',
|
10
|
+
chroot='.',
|
11
|
+
access_log='/logs/mongrel2_access.log',
|
12
|
+
error_log='/logs/mongrel2_error.log',
|
13
|
+
pid_file='/tmp/pids/mongrel2.pid',
|
14
|
+
default_host='localhost',
|
15
|
+
name='main',
|
16
|
+
port=8080,
|
17
|
+
hosts=[darkblog2]
|
18
|
+
)
|
19
|
+
|
20
|
+
|
21
|
+
settings = {
|
22
|
+
'zeromq.threads': 1,
|
23
|
+
'control_port': 'ipc://tmp/mongrel2_control'
|
24
|
+
}
|
25
|
+
|
26
|
+
servers = [main]
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'yajl/json_gem'
|
3
|
+
|
4
|
+
get '*' do
|
5
|
+
items = request.env.map do |k,v|
|
6
|
+
"<li><strong>#{k}</strong>: #{v}</li>\n"
|
7
|
+
end
|
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.to_json}
|
21
|
+
</body>
|
22
|
+
</html>
|
23
|
+
}
|
24
|
+
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(
|
10
|
-
@
|
9
|
+
def initialize(uuid, sub, pub, block = true)
|
10
|
+
@uuid, @sub, @pub, @block = uuid, sub, pub, block
|
11
11
|
|
12
12
|
# Connect to receive requests
|
13
13
|
@reqs = CTX.socket(ZMQ::UPSTREAM)
|
@@ -16,7 +16,7 @@ module Mongrel2
|
|
16
16
|
# Connect to send responses
|
17
17
|
@resp = CTX.socket(ZMQ::PUB)
|
18
18
|
@resp.connect(pub)
|
19
|
-
@resp.setsockopt(ZMQ::IDENTITY,
|
19
|
+
@resp.setsockopt(ZMQ::IDENTITY, uuid)
|
20
20
|
end
|
21
21
|
|
22
22
|
def recv
|
@@ -28,8 +28,8 @@ module Mongrel2
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def close
|
31
|
-
|
32
|
-
|
31
|
+
# I think I should be able to just close the context
|
32
|
+
CTX.close rescue nil
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
data/lib/mongrel2/request.rb
CHANGED
@@ -16,9 +16,12 @@ module Rack
|
|
16
16
|
conn = ::Mongrel2::Connection.new(options[:uuid], options[:recv], options[:send])
|
17
17
|
|
18
18
|
running = true
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
|
20
|
+
# This doesn't work at all for some reason
|
21
|
+
%w(INT TERM).each do |sig|
|
22
|
+
trap(sig) do
|
23
|
+
running = false
|
24
|
+
end
|
22
25
|
end
|
23
26
|
|
24
27
|
while running
|
@@ -39,13 +42,13 @@ module Rack
|
|
39
42
|
'REQUEST_METHOD' => req.headers['METHOD'],
|
40
43
|
'SCRIPT_NAME' => script_name,
|
41
44
|
'PATH_INFO' => req.headers['PATH'].gsub(script_name, ''),
|
42
|
-
'QUERY_STRING' => req.headers['QUERY']
|
45
|
+
'QUERY_STRING' => req.headers['QUERY'] || ''
|
43
46
|
}
|
44
47
|
|
45
48
|
env['SERVER_NAME'], env['SERVER_PORT'] = req.headers['host'].split(':', 2)
|
46
49
|
req.headers.each do |key, val|
|
47
50
|
unless key =~ /content_(type|length)/i
|
48
|
-
key = "HTTP_#{key.upcase}"
|
51
|
+
key = "HTTP_#{key.upcase.gsub('-', '_')}"
|
49
52
|
end
|
50
53
|
env[key] = val
|
51
54
|
end
|
data/rack-mongrel2.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rack-mongrel2}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Daniel Huckstep"]
|
12
|
-
s.date = %q{2010-10-
|
12
|
+
s.date = %q{2010-10-24}
|
13
13
|
s.description = %q{A Rack handler for the Mongrel2 web server, by Zed Shaw. http://mongrel2.org/}
|
14
14
|
s.email = %q{darkhelmet@darkhelmetlive.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,10 +26,12 @@ Gem::Specification.new do |s|
|
|
26
26
|
"README.rdoc",
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
|
+
"example/mongrel2.conf",
|
30
|
+
"example/sinatra/app.rb",
|
31
|
+
"example/sinatra/config.ru",
|
29
32
|
"lib/mongrel2/connection.rb",
|
30
33
|
"lib/mongrel2/request.rb",
|
31
34
|
"lib/mongrel2/response.rb",
|
32
|
-
"lib/rack-mongrel2.rb",
|
33
35
|
"lib/rack/handler/mongrel2.rb",
|
34
36
|
"rack-mongrel2.gemspec",
|
35
37
|
"spec/rack-mongrel2_spec.rb",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-mongrel2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel Huckstep
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-24 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -117,10 +117,12 @@ files:
|
|
117
117
|
- README.rdoc
|
118
118
|
- Rakefile
|
119
119
|
- VERSION
|
120
|
+
- example/mongrel2.conf
|
121
|
+
- example/sinatra/app.rb
|
122
|
+
- example/sinatra/config.ru
|
120
123
|
- lib/mongrel2/connection.rb
|
121
124
|
- lib/mongrel2/request.rb
|
122
125
|
- lib/mongrel2/response.rb
|
123
|
-
- lib/rack-mongrel2.rb
|
124
126
|
- lib/rack/handler/mongrel2.rb
|
125
127
|
- rack-mongrel2.gemspec
|
126
128
|
- spec/rack-mongrel2_spec.rb
|
data/lib/rack-mongrel2.rb
DELETED
File without changes
|