rack-mongrel2 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,9 +1,28 @@
1
1
  = rack-mongrel2
2
2
 
3
- Description goes here.
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.0
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
@@ -0,0 +1,6 @@
1
+ $: << File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
2
+
3
+ require 'rack/handler/mongrel2'
4
+ require 'app'
5
+
6
+ Rack::Handler::Mongrel2.run Sinatra::Application
@@ -6,8 +6,8 @@ module Mongrel2
6
6
  class Connection
7
7
  CTX = ZMQ::Context.new(1)
8
8
 
9
- def initialize(ident, sub, pub, block = true)
10
- @ident, @sub, @pub, @block = ident, sub, pub, block
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, ident)
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
- @reqs.close rescue nil
32
- @resp.close rescue nil
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
@@ -1,3 +1,5 @@
1
+ require 'yajl'
2
+
1
3
  module Mongrel2
2
4
  class Request
3
5
  attr_reader :headers, :body, :uuid, :conn_id
@@ -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
- trap('SIGINT') do
20
- running = false
21
- conn.close
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
@@ -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.0"
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-23}
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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
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-23 00:00:00 -06:00
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