mongrel2 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,14 @@
1
+ == v0.13.0 [2012-02-24] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ - Fix the ZMQ socket identifier used by Connection.
4
+ - Add missing slash in the control socket URI
5
+ - Add an argument so the helloworld handler can use another config DB
6
+ - Fix handling of NO CONTENT (204) responses.
7
+ * Don't set a Content-type header
8
+ * Omit the body even if there is one
9
+ * Set the content-length to 0
10
+
11
+
1
12
  == v0.12.0 [2012-02-17] Michael Granger <ged@FaerieMUD.org>
2
13
 
3
14
  - Add bodiless response predicate to Mongrel2::HTTPResponse.
@@ -20,12 +20,14 @@ class HelloWorldHandler < Mongrel2::Handler
20
20
 
21
21
  end # class HelloWorldHandler
22
22
 
23
+ configdb = ARGV.shift || 'examples.sqlite'
24
+
23
25
  # Log to a file instead of STDERR for a bit more speed.
24
- Mongrel2.log = Logger.new( 'hello-world.log' )
25
- Mongrel2.log.level = Logger::INFO
26
+ # Mongrel2.log = Logger.new( 'hello-world.log' )
27
+ Mongrel2.log.level = Logger::DEBUG
26
28
 
27
29
  # Point to the config database, which will cause the handler to use
28
30
  # its ID to look up its own socket info.
29
- Mongrel2::Config.configure( :configdb => 'examples.sqlite' )
31
+ Mongrel2::Config.configure( configdb: configdb )
30
32
  HelloWorldHandler.run( 'helloworld-handler' )
31
33
 
@@ -14,10 +14,10 @@ module Mongrel2
14
14
  abort "\n\n>>> Mongrel2 requires Ruby 1.9.2 or later. <<<\n\n" if RUBY_VERSION < '1.9.2'
15
15
 
16
16
  # Library version constant
17
- VERSION = '0.12.0'
17
+ VERSION = '0.13.0'
18
18
 
19
19
  # Version-control revision constant
20
- REVISION = %q$Revision: 7cd687a35c4c $
20
+ REVISION = %q$Revision: 612156a7bc00 $
21
21
 
22
22
 
23
23
  require 'mongrel2/logging'
@@ -46,7 +46,7 @@ class Mongrel2::Config::Server < Mongrel2::Config( :server )
46
46
 
47
47
  csock_path = Pathname( self.chroot ) + sock_path
48
48
  Mongrel2.log.debug " fully-qualified path is: %p" % [ csock_path ]
49
- csock_uri = "%s:/%s" % [ scheme, csock_path ]
49
+ csock_uri = "%s://%s" % [ scheme, csock_path ]
50
50
 
51
51
  Mongrel2.log.debug " control socket URI is: %p" % [ csock_uri ]
52
52
  return csock_uri
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
+ require 'socket'
3
4
  require 'zmq'
4
5
  require 'yajl'
6
+ require 'digest/sha1'
5
7
 
6
8
  require 'mongrel2' unless defined?( Mongrel2 )
7
9
  require 'mongrel2/mixins'
@@ -22,12 +24,14 @@ class Mongrel2::Connection
22
24
  ### will connect to a Mongrel2 server on the +sub_addr+ and +pub_addr+ (e.g.,
23
25
  ### 'tcp://127.0.0.1:9998').
24
26
  def initialize( app_id, sub_addr, pub_addr )
25
- @app_id = app_id
26
- @sub_addr = sub_addr
27
- @pub_addr = pub_addr
27
+ @app_id = app_id
28
+ @sub_addr = sub_addr
29
+ @pub_addr = pub_addr
28
30
 
29
31
  @request_sock = @response_sock = nil
30
- @closed = false
32
+
33
+ @identifier = make_identifier( app_id )
34
+ @closed = false
31
35
  end
32
36
 
33
37
 
@@ -43,9 +47,12 @@ class Mongrel2::Connection
43
47
  public
44
48
  ######
45
49
 
46
- # The application's UUID that identifies it to Mongrel2
50
+ # The application's identifier string that associates it with its route
47
51
  attr_reader :app_id
48
52
 
53
+ # The ZMQ socket identity used by this connection
54
+ attr_reader :identifier
55
+
49
56
  # The connection's subscription (request) socket address
50
57
  attr_reader :sub_addr
51
58
 
@@ -58,16 +65,16 @@ class Mongrel2::Connection
58
65
  ctx = Mongrel2.zmq_context
59
66
  self.log.debug "0mq Context is: %p" % [ ctx ]
60
67
 
61
- self.log.info "Connecting PULL request socket (%s)" % [ @sub_addr ]
68
+ self.log.info "Connecting PULL request socket (%s)" % [ self.sub_addr ]
62
69
  @request_sock = ctx.socket( ZMQ::PULL )
63
70
  @request_sock.setsockopt( ZMQ::LINGER, 0 )
64
- @request_sock.connect( @sub_addr )
71
+ @request_sock.connect( self.sub_addr )
65
72
 
66
- self.log.info "Connecting PUB response socket (%s)" % [ @pub_addr ]
73
+ self.log.info "Connecting PUB response socket (%s)" % [ self.pub_addr ]
67
74
  @response_sock = ctx.socket( ZMQ::PUB )
68
- @response_sock.setsockopt( ZMQ::IDENTITY, @app_id )
75
+ @response_sock.setsockopt( ZMQ::IDENTITY, self.identifier )
69
76
  @response_sock.setsockopt( ZMQ::LINGER, 0 )
70
- @response_sock.connect( @pub_addr )
77
+ @response_sock.connect( self.pub_addr )
71
78
  end
72
79
 
73
80
 
@@ -114,7 +121,7 @@ class Mongrel2::Connection
114
121
  buf = header + ' ' + data
115
122
  self.log.debug "Sending response (PUB): %p" % [ buf ]
116
123
  self.response_sock.send( buf )
117
- self.log.debug " done with send."
124
+ self.log.debug " done with send (%d bytes)" % [ buf.bytesize ]
118
125
  end
119
126
 
120
127
 
@@ -214,6 +221,23 @@ class Mongrel2::Connection
214
221
  raise Mongrel2::ConnectionError, "operation on closed Connection" if self.closed?
215
222
  end
216
223
 
224
+
225
+ #######
226
+ private
227
+ #######
228
+
229
+ ### Make a unique identifier for this connection's socket based on the +app_id+
230
+ ### and some other stuff.
231
+ def make_identifier( app_id )
232
+ identifier = Digest::SHA1.new
233
+ identifier << app_id
234
+ identifier << Socket.gethostname
235
+ identifier << Process.pid.to_s
236
+ identifier << Time.now.to_s
237
+
238
+ return identifier.hexdigest
239
+ end
240
+
217
241
  end # class Mongrel2::Connection
218
242
 
219
243
  # vim: set nosta noet ts=4 sw=4:
@@ -59,7 +59,7 @@ class Mongrel2::HTTPResponse < Mongrel2::Response
59
59
  return [
60
60
  self.status_line,
61
61
  self.header_data,
62
- self.body
62
+ self.bodiless? ? '' : self.body
63
63
  ].join( "\r\n" )
64
64
  end
65
65
 
@@ -99,6 +99,7 @@ class Mongrel2::HTTPResponse < Mongrel2::Response
99
99
  return self.status_category == 1
100
100
  end
101
101
 
102
+
102
103
  ### Return true if response is in the 2XX range
103
104
  def status_is_successful?
104
105
  return self.status_category == 2
@@ -160,7 +161,12 @@ class Mongrel2::HTTPResponse < Mongrel2::Response
160
161
 
161
162
  headers[:date] ||= Time.now.httpdate
162
163
  headers[:content_length] ||= self.get_content_length
163
- headers[:content_type] ||= DEFAULT_CONTENT_TYPE.dup
164
+
165
+ if self.bodiless?
166
+ headers.delete( :content_type )
167
+ else
168
+ headers[:content_type] ||= DEFAULT_CONTENT_TYPE.dup
169
+ end
164
170
 
165
171
  return headers
166
172
  end
@@ -170,7 +176,9 @@ class Mongrel2::HTTPResponse < Mongrel2::Response
170
176
  ### one, or using #seek and #tell if it implements those. If neither of those are
171
177
  ### possible, an exception is raised.
172
178
  def get_content_length
173
- if self.body.respond_to?( :bytesize )
179
+ if self.bodiless?
180
+ return 0
181
+ elsif self.body.respond_to?( :bytesize )
174
182
  return self.body.bytesize
175
183
  elsif self.body.respond_to?( :seek ) && self.body.respond_to?( :tell )
176
184
  starting_pos = self.body.tell
@@ -83,13 +83,13 @@ describe Mongrel2::Config::Server do
83
83
 
84
84
  it "knows where its control socket is if there's no setting for control_port" do
85
85
  Mongrel2::Config::Setting.dataset.truncate
86
- @server.control_socket_uri.should == 'ipc://usr/local/www/run/control'
86
+ @server.control_socket_uri.should == 'ipc:///usr/local/www/run/control'
87
87
  end
88
88
 
89
89
  it "knows where its control socket is if there is a setting for control_port" do
90
90
  Mongrel2::Config::Setting.dataset.truncate
91
91
  Mongrel2::Config::Setting.create( key: 'control_port', value: 'ipc://var/run/control.sock' )
92
- @server.control_socket_uri.should == 'ipc://usr/local/www/var/run/control.sock'
92
+ @server.control_socket_uri.should == 'ipc:///usr/local/www/var/run/control.sock'
93
93
  end
94
94
 
95
95
  it "can create a Mongrel2::Control for its control port" do
@@ -61,7 +61,7 @@ describe Mongrel2::Connection do
61
61
 
62
62
  @ctx.should_receive( :socket ).with( ZMQ::PUB ).and_return( response_sock )
63
63
  response_sock.should_receive( :setsockopt ).with( ZMQ::LINGER, 0 )
64
- response_sock.should_receive( :setsockopt ).with( ZMQ::IDENTITY, TEST_UUID )
64
+ response_sock.should_receive( :setsockopt ).with( ZMQ::IDENTITY, /^[[:xdigit:]]{40}$/ )
65
65
  response_sock.should_receive( :connect ).with( TEST_RECV_SPEC )
66
66
 
67
67
  @conn.request_sock.should == request_sock
@@ -52,6 +52,14 @@ describe Mongrel2::HTTPResponse do
52
52
  @response.status_line.should == 'HTTP/1.1 204 No Content'
53
53
  end
54
54
 
55
+ it "returns an empty response if its status is set to NO_CONTENT" do
56
+ @response.puts "The response body"
57
+ @response.status = HTTP::NO_CONTENT
58
+ @response.header_data.should =~ /Content-length: 0/i
59
+ @response.header_data.should_not =~ /Content-type/i
60
+ @response.to_s.should_not =~ /The response body/i
61
+ end
62
+
55
63
  it "sets Date, Content-type, and Content-length headers automatically if they haven't been set" do
56
64
  @response << "Some stuff."
57
65
 
@@ -216,6 +224,11 @@ describe Mongrel2::HTTPResponse do
216
224
  end
217
225
 
218
226
 
227
+ it "returns a body length of 0 if it's a bodiless reponse" do
228
+ @response.status = HTTP::NO_CONTENT
229
+ @response.get_content_length.should == 0
230
+ end
231
+
219
232
  it "raises a descriptive error message if it can't get the body's length" do
220
233
  @response.body = Object.new
221
234
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongrel2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -36,11 +36,11 @@ cert_chain:
36
36
  YUhDS0xaZFNLai9SSHVUT3QrZ2JsUmV4OEZBaDhOZUEKY21saFhlNDZwWk5K
37
37
  Z1dLYnhaYWg4NWpJang5NWhSOHZPSStOQU01aUg5a09xSzEzRHJ4YWNUS1Bo
38
38
  cWo1UGp3RgotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
39
- date: 2012-02-18 00:00:00.000000000 Z
39
+ date: 2012-02-25 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: nokogiri
43
- requirement: &70186557497160 !ruby/object:Gem::Requirement
43
+ requirement: &70146044712400 !ruby/object:Gem::Requirement
44
44
  none: false
45
45
  requirements:
46
46
  - - ~>
@@ -48,10 +48,10 @@ dependencies:
48
48
  version: '1.5'
49
49
  type: :runtime
50
50
  prerelease: false
51
- version_requirements: *70186557497160
51
+ version_requirements: *70146044712400
52
52
  - !ruby/object:Gem::Dependency
53
53
  name: sequel
54
- requirement: &70186557496640 !ruby/object:Gem::Requirement
54
+ requirement: &70146044711880 !ruby/object:Gem::Requirement
55
55
  none: false
56
56
  requirements:
57
57
  - - ~>
@@ -59,10 +59,10 @@ dependencies:
59
59
  version: '3.31'
60
60
  type: :runtime
61
61
  prerelease: false
62
- version_requirements: *70186557496640
62
+ version_requirements: *70146044711880
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: amalgalite
65
- requirement: &70186557496120 !ruby/object:Gem::Requirement
65
+ requirement: &70146044711420 !ruby/object:Gem::Requirement
66
66
  none: false
67
67
  requirements:
68
68
  - - ~>
@@ -70,10 +70,10 @@ dependencies:
70
70
  version: '1.1'
71
71
  type: :runtime
72
72
  prerelease: false
73
- version_requirements: *70186557496120
73
+ version_requirements: *70146044711420
74
74
  - !ruby/object:Gem::Dependency
75
75
  name: tnetstring
76
- requirement: &70186557495600 !ruby/object:Gem::Requirement
76
+ requirement: &70146044710880 !ruby/object:Gem::Requirement
77
77
  none: false
78
78
  requirements:
79
79
  - - ~>
@@ -81,10 +81,10 @@ dependencies:
81
81
  version: '0.3'
82
82
  type: :runtime
83
83
  prerelease: false
84
- version_requirements: *70186557495600
84
+ version_requirements: *70146044710880
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: yajl-ruby
87
- requirement: &70186557495180 !ruby/object:Gem::Requirement
87
+ requirement: &70146044710460 !ruby/object:Gem::Requirement
88
88
  none: false
89
89
  requirements:
90
90
  - - ~>
@@ -92,10 +92,10 @@ dependencies:
92
92
  version: '1.0'
93
93
  type: :runtime
94
94
  prerelease: false
95
- version_requirements: *70186557495180
95
+ version_requirements: *70146044710460
96
96
  - !ruby/object:Gem::Dependency
97
97
  name: trollop
98
- requirement: &70186557494640 !ruby/object:Gem::Requirement
98
+ requirement: &70146044709900 !ruby/object:Gem::Requirement
99
99
  none: false
100
100
  requirements:
101
101
  - - ~>
@@ -103,10 +103,10 @@ dependencies:
103
103
  version: '1.16'
104
104
  type: :runtime
105
105
  prerelease: false
106
- version_requirements: *70186557494640
106
+ version_requirements: *70146044709900
107
107
  - !ruby/object:Gem::Dependency
108
108
  name: sysexits
109
- requirement: &70186557494140 !ruby/object:Gem::Requirement
109
+ requirement: &70146044709400 !ruby/object:Gem::Requirement
110
110
  none: false
111
111
  requirements:
112
112
  - - ~>
@@ -114,10 +114,10 @@ dependencies:
114
114
  version: '1.0'
115
115
  type: :runtime
116
116
  prerelease: false
117
- version_requirements: *70186557494140
117
+ version_requirements: *70146044709400
118
118
  - !ruby/object:Gem::Dependency
119
119
  name: zmq
120
- requirement: &70186557493620 !ruby/object:Gem::Requirement
120
+ requirement: &70146044708880 !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements:
123
123
  - - ~>
@@ -125,10 +125,10 @@ dependencies:
125
125
  version: 2.1.4
126
126
  type: :runtime
127
127
  prerelease: false
128
- version_requirements: *70186557493620
128
+ version_requirements: *70146044708880
129
129
  - !ruby/object:Gem::Dependency
130
130
  name: hoe-mercurial
131
- requirement: &70186557493100 !ruby/object:Gem::Requirement
131
+ requirement: &70146044708360 !ruby/object:Gem::Requirement
132
132
  none: false
133
133
  requirements:
134
134
  - - ~>
@@ -136,10 +136,10 @@ dependencies:
136
136
  version: 1.3.1
137
137
  type: :development
138
138
  prerelease: false
139
- version_requirements: *70186557493100
139
+ version_requirements: *70146044708360
140
140
  - !ruby/object:Gem::Dependency
141
141
  name: hoe-highline
142
- requirement: &70186557492580 !ruby/object:Gem::Requirement
142
+ requirement: &70146044707840 !ruby/object:Gem::Requirement
143
143
  none: false
144
144
  requirements:
145
145
  - - ~>
@@ -147,10 +147,10 @@ dependencies:
147
147
  version: 0.0.1
148
148
  type: :development
149
149
  prerelease: false
150
- version_requirements: *70186557492580
150
+ version_requirements: *70146044707840
151
151
  - !ruby/object:Gem::Dependency
152
152
  name: configurability
153
- requirement: &70186557491940 !ruby/object:Gem::Requirement
153
+ requirement: &70146044707080 !ruby/object:Gem::Requirement
154
154
  none: false
155
155
  requirements:
156
156
  - - ~>
@@ -158,10 +158,10 @@ dependencies:
158
158
  version: '1.0'
159
159
  type: :development
160
160
  prerelease: false
161
- version_requirements: *70186557491940
161
+ version_requirements: *70146044707080
162
162
  - !ruby/object:Gem::Dependency
163
163
  name: rspec
164
- requirement: &70186557490880 !ruby/object:Gem::Requirement
164
+ requirement: &70146044706060 !ruby/object:Gem::Requirement
165
165
  none: false
166
166
  requirements:
167
167
  - - ~>
@@ -169,10 +169,10 @@ dependencies:
169
169
  version: '2.8'
170
170
  type: :development
171
171
  prerelease: false
172
- version_requirements: *70186557490880
172
+ version_requirements: *70146044706060
173
173
  - !ruby/object:Gem::Dependency
174
174
  name: rdoc
175
- requirement: &70186557506660 !ruby/object:Gem::Requirement
175
+ requirement: &70146044773520 !ruby/object:Gem::Requirement
176
176
  none: false
177
177
  requirements:
178
178
  - - ~>
@@ -180,10 +180,10 @@ dependencies:
180
180
  version: '3.10'
181
181
  type: :development
182
182
  prerelease: false
183
- version_requirements: *70186557506660
183
+ version_requirements: *70146044773520
184
184
  - !ruby/object:Gem::Dependency
185
185
  name: hoe
186
- requirement: &70186557506040 !ruby/object:Gem::Requirement
186
+ requirement: &70146044773000 !ruby/object:Gem::Requirement
187
187
  none: false
188
188
  requirements:
189
189
  - - ~>
@@ -191,7 +191,7 @@ dependencies:
191
191
  version: '2.13'
192
192
  type: :development
193
193
  prerelease: false
194
- version_requirements: *70186557506040
194
+ version_requirements: *70146044773000
195
195
  description: ! "Ruby-Mongrel2 is a complete Ruby (1.9-only) connector for \nMongrel2[http://mongrel2.org/].\n\nThis
196
196
  library includes configuration-database ORM classes, a Ruby\nimplementation of the
197
197
  'm2sh' tool, a configuration DSL for generating config\ndatabases in pure Ruby,
metadata.gz.sig CHANGED
Binary file