mongrel2 0.0.2 → 0.1.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.1.0 [2011-11-14] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ Memoize Mongrel2::Request#response, and add Mongrel2::Request.response_class to
4
+ allow for easy overriding of the response type.
5
+
6
+
7
+ == v0.0.2 [2011-11-13] Michael Granger <ged@FaerieMUD.org>
8
+
9
+ Added a shim to work around lack of ZMQ::Error in zmq-2.1.3.
10
+
11
+
1
12
  == v0.0.1 [2011-09-12] Michael Granger <ged@FaerieMUD.org>
2
13
 
3
14
  Initial release.
data/Rakefile CHANGED
@@ -46,28 +46,10 @@ ENV['VERSION'] ||= hoespec.spec.version.to_s
46
46
  # Ensure the specs pass before checking in
47
47
  task 'hg:precheckin' => :spec
48
48
 
49
- ### Make the ChangeLog update if the repo has changed since it was last built
50
- file '.hg/branch'
51
- file 'ChangeLog' => '.hg/branch' do |task|
52
- $stderr.puts "Updating the changelog..."
53
- abort "Can't create the ChangeLog without hoe-mercurial (gem install hoe-mercurial)" unless
54
- defined?( MercurialHelpers )
55
-
56
- content = MercurialHelpers.make_changelog()
57
- File.open( task.name, 'w', 0644 ) do |fh|
58
- fh.print( content )
59
- end
60
- end
61
49
 
62
50
  # Rebuild the ChangeLog immediately before release
63
51
  task :prerelease => 'ChangeLog'
64
52
 
65
- if Rake::Task.task_defined?( '.gemtest' )
66
- Rake::Task['.gemtest'].clear
67
- task '.gemtest' do
68
- $stderr.puts "Not including a .gemtest until I'm confident the test suite is idempotent."
69
- end
70
- end
71
53
 
72
54
  desc "Build a coverage report"
73
55
  task :coverage do
@@ -22,10 +22,10 @@ module Mongrel2
22
22
  abort "\n\n>>> Mongrel2 requires Ruby 1.9.2 or later. <<<\n\n" if RUBY_VERSION < '1.9.2'
23
23
 
24
24
  # Library version constant
25
- VERSION = '0.0.2'
25
+ VERSION = '0.1.0'
26
26
 
27
27
  # Version-control revision constant
28
- REVISION = %q$Revision: c39289ec700e $
28
+ REVISION = %q$Revision: da03e18009f8 $
29
29
 
30
30
 
31
31
  require 'mongrel2/logging'
@@ -16,9 +16,9 @@ class Mongrel2::HTTPRequest < Mongrel2::Request
16
16
  register_request_type( self, *HANDLED_HTTP_METHODS )
17
17
 
18
18
 
19
- ### Create a Mongrel2::HTTPResponse that corresponds to the receiver.
20
- def response
21
- return Mongrel2::HTTPResponse.from_request( self )
19
+ ### Override the type of response returned by this request type.
20
+ def self::response_class
21
+ return Mongrel2::HTTPResponse
22
22
  end
23
23
 
24
24
 
@@ -19,6 +19,35 @@ class Mongrel2::Request
19
19
  class << self; attr_reader :request_types; end
20
20
 
21
21
 
22
+ ### Parse the given +raw_request+ from a Mongrel2 server and return an appropriate
23
+ ### request object.
24
+ def self::parse( raw_request )
25
+ sender, conn_id, path, rest = raw_request.split( ' ', 4 )
26
+ Mongrel2.log.debug "Parsing request for %p from %s:%s (rest: %p)" %
27
+ [ path, sender, conn_id, rest ]
28
+
29
+ # Extract the headers and the body, ignore the rest
30
+ headers, rest = TNetstring.parse( rest )
31
+ body, _ = TNetstring.parse( rest )
32
+
33
+ # Headers will be a JSON String when not using the TNetString protocol
34
+ if headers.is_a?( String )
35
+ Mongrel2.log.debug " parsing old-style headers"
36
+ headers = Yajl::Parser.parse( headers )
37
+ end
38
+
39
+ # This isn't supposed to happen, but guard against it anyway
40
+ headers['METHOD'] =~ /^(\w+)$/ or
41
+ raise Mongrel2::UnhandledMethodError, headers['METHOD']
42
+ req_method = $1.untaint.to_sym
43
+ Mongrel2.log.debug "Request method is: %p" % [ req_method ]
44
+ concrete_class = self.subclass_for_method( req_method )
45
+
46
+ return concrete_class.new( sender, conn_id, path, headers, body, raw_request )
47
+ end
48
+
49
+
50
+
22
51
  ### Register the specified +subclass+ as the class to instantiate when the +METHOD+
23
52
  ### header is one of the specified +req_methods+. This method exists for frameworks
24
53
  ### which wish to provide their own Request types.
@@ -63,35 +92,17 @@ class Mongrel2::Request
63
92
  end
64
93
 
65
94
 
66
- ### Parse the given +raw_request+ from a Mongrel2 server and return an appropriate
67
- ### request object.
68
- def self::parse( raw_request )
69
- sender, conn_id, path, rest = raw_request.split( ' ', 4 )
70
- Mongrel2.log.debug "Parsing request for %p from %s:%s (rest: %p)" %
71
- [ path, sender, conn_id, rest ]
72
-
73
- # Extract the headers and the body, ignore the rest
74
- headers, rest = TNetstring.parse( rest )
75
- body, _ = TNetstring.parse( rest )
76
-
77
- # Headers will be a JSON String when not using the TNetString protocol
78
- if headers.is_a?( String )
79
- Mongrel2.log.debug " parsing old-style headers"
80
- headers = Yajl::Parser.parse( headers )
81
- end
82
-
83
- # This isn't supposed to happen, but guard against it anyway
84
- headers['METHOD'] =~ /^(\w+)$/ or
85
- raise Mongrel2::UnhandledMethodError, headers['METHOD']
86
- req_method = $1.untaint.to_sym
87
- Mongrel2.log.debug "Request method is: %p" % [ req_method ]
88
- concrete_class = self.subclass_for_method( req_method )
89
-
90
- return concrete_class.new( sender, conn_id, path, headers, body, raw_request )
95
+ ### Return the Mongrel2::Response class that corresponds with the receiver.
96
+ def self::response_class
97
+ return Mongrel2::Response
91
98
  end
92
99
 
93
100
 
94
101
 
102
+ #################################################################
103
+ ### I N S T A N C E M E T H O D S
104
+ #################################################################
105
+
95
106
  ### Create a new Request object with the given +sender_id+, +conn_id+, +path+, +headers+,
96
107
  ### and +body+. The optional +nil+ is for the raw request content, which can be useful
97
108
  ### later for debugging.
@@ -101,8 +112,9 @@ class Mongrel2::Request
101
112
  @path = path
102
113
  @headers = Mongrel2::Table.new( headers )
103
114
  @body = body
104
-
105
115
  @raw = raw
116
+
117
+ @response = nil
106
118
  end
107
119
 
108
120
 
@@ -132,11 +144,13 @@ class Mongrel2::Request
132
144
 
133
145
  ### Create a Mongrel2::Response that will respond to the same server/connection as
134
146
  ### the receiver. If you wish your specialized Request class to have a corresponding
135
- ### response type, you can override this method to achieve that.
147
+ ### response type, you can override the Mongrel2::Request.response_class method
148
+ ### to achieve that.
136
149
  def response
137
- return Mongrel2::Response.from_request( self )
150
+ return @response ||= self.class.response_class.from_request( self )
138
151
  end
139
152
 
153
+
140
154
  ### Return +true+ if the request is a special 'disconnect' notification from Mongrel2.
141
155
  def is_disconnect?
142
156
  return false
@@ -84,6 +84,10 @@ describe Mongrel2::Request do
84
84
  }.to raise_error( Mongrel2::UnhandledMethodError, /!DIVULGE/ )
85
85
  end
86
86
 
87
+ it "knows what kind of response it should return" do
88
+ Mongrel2::Request.response_class.should == Mongrel2::Response
89
+ end
90
+
87
91
 
88
92
  describe "instances" do
89
93
 
@@ -99,6 +103,10 @@ describe Mongrel2::Request do
99
103
  result.conn_id.should == @req.conn_id
100
104
  end
101
105
 
106
+ it "remembers its response if it's already made one" do
107
+ @req.response.should equal( @req.response )
108
+ end
109
+
102
110
  end
103
111
 
104
112
 
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.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -48,11 +48,11 @@ cert_chain:
48
48
  -----END CERTIFICATE-----
49
49
 
50
50
  '
51
- date: 2011-09-13 00:00:00.000000000Z
51
+ date: 2011-09-14 00:00:00.000000000Z
52
52
  dependencies:
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: nokogiri
55
- requirement: &70185768624780 !ruby/object:Gem::Requirement
55
+ requirement: &2164717460 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
58
  - - ~>
@@ -60,10 +60,10 @@ dependencies:
60
60
  version: '1.5'
61
61
  type: :runtime
62
62
  prerelease: false
63
- version_requirements: *70185768624780
63
+ version_requirements: *2164717460
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: sequel
66
- requirement: &70185768624200 !ruby/object:Gem::Requirement
66
+ requirement: &2164715720 !ruby/object:Gem::Requirement
67
67
  none: false
68
68
  requirements:
69
69
  - - ~>
@@ -71,10 +71,10 @@ dependencies:
71
71
  version: '3.26'
72
72
  type: :runtime
73
73
  prerelease: false
74
- version_requirements: *70185768624200
74
+ version_requirements: *2164715720
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: amalgalite
77
- requirement: &70185768623640 !ruby/object:Gem::Requirement
77
+ requirement: &2164713820 !ruby/object:Gem::Requirement
78
78
  none: false
79
79
  requirements:
80
80
  - - ~>
@@ -82,10 +82,10 @@ dependencies:
82
82
  version: '1.1'
83
83
  type: :runtime
84
84
  prerelease: false
85
- version_requirements: *70185768623640
85
+ version_requirements: *2164713820
86
86
  - !ruby/object:Gem::Dependency
87
87
  name: tnetstring
88
- requirement: &70185768623060 !ruby/object:Gem::Requirement
88
+ requirement: &2164710820 !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
91
  - - ~>
@@ -93,10 +93,10 @@ dependencies:
93
93
  version: '0.3'
94
94
  type: :runtime
95
95
  prerelease: false
96
- version_requirements: *70185768623060
96
+ version_requirements: *2164710820
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: yajl-ruby
99
- requirement: &70185768622520 !ruby/object:Gem::Requirement
99
+ requirement: &2164709340 !ruby/object:Gem::Requirement
100
100
  none: false
101
101
  requirements:
102
102
  - - ~>
@@ -104,10 +104,10 @@ dependencies:
104
104
  version: '0.8'
105
105
  type: :runtime
106
106
  prerelease: false
107
- version_requirements: *70185768622520
107
+ version_requirements: *2164709340
108
108
  - !ruby/object:Gem::Dependency
109
109
  name: zmq
110
- requirement: &70185768621940 !ruby/object:Gem::Requirement
110
+ requirement: &2164707660 !ruby/object:Gem::Requirement
111
111
  none: false
112
112
  requirements:
113
113
  - - ~>
@@ -115,21 +115,21 @@ dependencies:
115
115
  version: 2.1.3
116
116
  type: :runtime
117
117
  prerelease: false
118
- version_requirements: *70185768621940
118
+ version_requirements: *2164707660
119
119
  - !ruby/object:Gem::Dependency
120
120
  name: hoe-mercurial
121
- requirement: &70185768621380 !ruby/object:Gem::Requirement
121
+ requirement: &2164704600 !ruby/object:Gem::Requirement
122
122
  none: false
123
123
  requirements:
124
124
  - - ~>
125
125
  - !ruby/object:Gem::Version
126
- version: 1.2.2
126
+ version: 1.2.1
127
127
  type: :development
128
128
  prerelease: false
129
- version_requirements: *70185768621380
129
+ version_requirements: *2164704600
130
130
  - !ruby/object:Gem::Dependency
131
131
  name: hoe-highline
132
- requirement: &70185768620760 !ruby/object:Gem::Requirement
132
+ requirement: &2164701340 !ruby/object:Gem::Requirement
133
133
  none: false
134
134
  requirements:
135
135
  - - ~>
@@ -137,10 +137,10 @@ dependencies:
137
137
  version: 0.0.1
138
138
  type: :development
139
139
  prerelease: false
140
- version_requirements: *70185768620760
140
+ version_requirements: *2164701340
141
141
  - !ruby/object:Gem::Dependency
142
142
  name: configurability
143
- requirement: &70185768620240 !ruby/object:Gem::Requirement
143
+ requirement: &2164697700 !ruby/object:Gem::Requirement
144
144
  none: false
145
145
  requirements:
146
146
  - - ~>
@@ -148,10 +148,10 @@ dependencies:
148
148
  version: '1.0'
149
149
  type: :development
150
150
  prerelease: false
151
- version_requirements: *70185768620240
151
+ version_requirements: *2164697700
152
152
  - !ruby/object:Gem::Dependency
153
153
  name: rspec
154
- requirement: &70185768619780 !ruby/object:Gem::Requirement
154
+ requirement: &2164694360 !ruby/object:Gem::Requirement
155
155
  none: false
156
156
  requirements:
157
157
  - - ~>
@@ -159,18 +159,18 @@ dependencies:
159
159
  version: '2.4'
160
160
  type: :development
161
161
  prerelease: false
162
- version_requirements: *70185768619780
162
+ version_requirements: *2164694360
163
163
  - !ruby/object:Gem::Dependency
164
164
  name: hoe
165
- requirement: &70185768619220 !ruby/object:Gem::Requirement
165
+ requirement: &2164685760 !ruby/object:Gem::Requirement
166
166
  none: false
167
167
  requirements:
168
168
  - - ~>
169
169
  - !ruby/object:Gem::Version
170
- version: '2.12'
170
+ version: '2.11'
171
171
  type: :development
172
172
  prerelease: false
173
- version_requirements: *70185768619220
173
+ version_requirements: *2164685760
174
174
  description: ! "A complete Ruby connector for Mongrel2[http://mongrel2.org/].\n\nThis
175
175
  library includes configuration-database ORM classes, a Ruby\nimplementation of the
176
176
  'm2sh' tool, a configuration DSL for generating config\ndatabases in pure Ruby,
metadata.gz.sig CHANGED
Binary file