ajp-rails 0.0.4 → 0.1.0
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/NEWS.en +4 -1
- data/NEWS.ja +4 -1
- data/ajp-rails.gemspec +2 -2
- data/lib/ajp-rails/rails-wrapper.rb +112 -38
- metadata +3 -3
data/NEWS.en
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
= NEWS
|
2
|
+
== 0.1.0 (2006-01-31)
|
3
|
+
* The `first' release.
|
4
|
+
* Reviewed at "Rails Meeting Tokyo"
|
2
5
|
== 0.0.4 (2006-01-27)
|
3
6
|
* The `0.4th' release
|
4
7
|
* Daemonizing support.
|
@@ -7,6 +10,6 @@
|
|
7
10
|
* Sticky session support.
|
8
11
|
== 0.0.2 (2006-01-24)
|
9
12
|
Status: unstable
|
10
|
-
* The `0th' release to be reviewed by "2nd Rails Meeting
|
13
|
+
* The `0th' release to be reviewed by "2nd Rails Meeting Tokyo".
|
11
14
|
* The first release -- v.0.1.0 -- will be done by the end of Jan, 2006.
|
12
15
|
This will be include the result of the review.
|
data/NEWS.ja
CHANGED
data/ajp-rails.gemspec
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "ajp-rails"
|
3
|
-
spec.version = "0.0
|
3
|
+
spec.version = "0.1.0"
|
4
4
|
spec.required_ruby_version = ">= 1.8.3"
|
5
|
-
spec.add_dependency('ruby-ajp', '>= 0.2.
|
5
|
+
spec.add_dependency('ruby-ajp', '>= 0.2.1')
|
6
6
|
spec.add_dependency('rails', '>= 0.14')
|
7
7
|
spec.summary = "Ruby on Rails Runner, which uses AJP(Apache JServ Protocol) to cooperate with a HTTPd, instead of CGI or FastCGI"
|
8
8
|
spec.author = "Yugui"
|
@@ -50,6 +50,8 @@
|
|
50
50
|
#++
|
51
51
|
|
52
52
|
require 'forwardable'
|
53
|
+
require 'cgi'
|
54
|
+
require 'action_controller/cgi_ext/raw_post_data_fix'
|
53
55
|
require 'action_controller/cgi_ext/cgi_methods'
|
54
56
|
|
55
57
|
class Net::AJP13::Request
|
@@ -68,21 +70,81 @@ class Net::AJP13::Request
|
|
68
70
|
attr_reader :output_cookies
|
69
71
|
end
|
70
72
|
|
73
|
+
|
71
74
|
# Wraps Net::AJP13::Request to adapt it to request object in rails.
|
72
75
|
class AjpRailsRequest < ActionController::AbstractRequest
|
76
|
+
AJP_PACKET_EMBED_VARIABLES = [
|
77
|
+
'remote_addr', 'remote_host', 'server_name', 'server_port'
|
78
|
+
]
|
79
|
+
|
80
|
+
# Modifies implementation for AjpRailsRequest
|
81
|
+
QueryExtension = CGI::QueryExtension.dup
|
82
|
+
module QueryExtension #:nodoc: all
|
83
|
+
private
|
84
|
+
|
85
|
+
def read_params_from_post
|
86
|
+
content = raw_post
|
87
|
+
content.chop! if content[-1] == 0
|
88
|
+
content
|
89
|
+
end
|
90
|
+
def read_params_from_query
|
91
|
+
query_string || ''
|
92
|
+
end
|
93
|
+
|
94
|
+
#--
|
95
|
+
# Uses AjpRails's own implementation
|
96
|
+
#++
|
97
|
+
remove_method :server_software, :query_string, :cookies, :host,
|
98
|
+
*AJP_PACKET_EMBED_VARIABLES
|
99
|
+
end
|
100
|
+
|
73
101
|
DEFAULT_SESSION_OPTIONS = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.merge('session_key' => 'JSESSIONID')
|
74
102
|
|
75
103
|
extend Forwardable
|
76
104
|
|
105
|
+
#--
|
106
|
+
# methods for CGI::QueryExtension
|
107
|
+
#++
|
108
|
+
def stdinput
|
109
|
+
if @req.body_stream
|
110
|
+
@req.body_stream
|
111
|
+
elsif @req.body
|
112
|
+
StringIO.new(@req.body)
|
113
|
+
else
|
114
|
+
nil
|
115
|
+
end
|
116
|
+
end
|
117
|
+
private :stdinput
|
118
|
+
|
119
|
+
#
|
120
|
+
# +ajp_request+:: Net::AJP13::Request object to wrap
|
121
|
+
# +session_options+:: Options to manage sessions. It is compatible for CGI::SEssion.new's options.
|
122
|
+
# +server_environments+::
|
77
123
|
def initialize(ajp_request, session_options, server_environments)
|
78
124
|
@req = ajp_request
|
79
125
|
@session_options = session_options
|
80
126
|
@server_environments = server_environments
|
81
127
|
@session_options['session_path'] ||= @server_environments['APP_LOCATION']
|
82
128
|
|
83
|
-
|
84
|
-
|
85
|
-
|
129
|
+
# simulates environment hash.
|
130
|
+
@env = self.class.instance_method(:environment).bind(self)
|
131
|
+
# Object#method is overridden by AbstractRequest#method
|
132
|
+
class << @env
|
133
|
+
def include?(key) !call(key).nil? end
|
134
|
+
alias :key? :include?
|
135
|
+
end
|
136
|
+
|
137
|
+
extend QueryExtension
|
138
|
+
initialize_query
|
139
|
+
|
140
|
+
@cookies = nil
|
141
|
+
fix_cookies
|
142
|
+
end
|
143
|
+
|
144
|
+
# removes jvm-route suffix from session id.
|
145
|
+
def fix_cookies
|
146
|
+
if balance_id = @server_environments['LOAD_BALANCE_ID'] and cookies = @req.cookies['JSESSIONID']
|
147
|
+
cookies.each do |value|
|
86
148
|
case value
|
87
149
|
when String
|
88
150
|
value.gsub!(/\.#{Regexp.escape(balance_id)}\Z/, '')
|
@@ -93,33 +155,56 @@ class AjpRailsRequest < ActionController::AbstractRequest
|
|
93
155
|
end
|
94
156
|
end
|
95
157
|
end
|
96
|
-
|
97
|
-
# simulates environment hash.
|
98
|
-
@env = self.class.instance_method(:environment).bind(self)
|
99
|
-
# Object#method is overridden by AbstractRequest#method
|
100
|
-
|
101
|
-
class << @env
|
102
|
-
def include?(key) !call(key).nil? end
|
103
|
-
alias :key? :include?
|
104
|
-
end
|
105
158
|
end
|
106
|
-
|
159
|
+
private :fix_cookies
|
107
160
|
|
161
|
+
# option values for session management. The interface is compatible for
|
162
|
+
# CGI::Session.new's second argument
|
108
163
|
attr_accessor :session_options
|
109
164
|
|
110
|
-
|
111
|
-
|
112
|
-
|
165
|
+
# CGI#env compatible interface for ActionController::AbstractRequest
|
166
|
+
attr_reader :env #:nodoc:
|
167
|
+
alias :env_table :env
|
168
|
+
private :env_table
|
113
169
|
|
114
|
-
|
115
|
-
|
116
|
-
|
170
|
+
# The implementation of #env
|
171
|
+
def environment(name) #:nodoc:
|
172
|
+
case name.downcase
|
173
|
+
when /^\Ahttp_(\w+)\Z/o
|
117
174
|
name = $1.tr('_', '-')
|
118
175
|
@req[name]
|
176
|
+
when AJP_PACKET_EMBED_VARIABLES.include?(name)
|
177
|
+
@req.send(name)
|
178
|
+
when 'query_string'
|
179
|
+
self.query_string
|
180
|
+
when 'server_protocol'
|
181
|
+
@req.protocol
|
182
|
+
when 'request_method'
|
183
|
+
@req.method
|
119
184
|
else
|
120
|
-
@req[name] or @server_environments[name]
|
185
|
+
@req[name.tr('_', '-')] or @server_environments[name]
|
121
186
|
end
|
122
187
|
end
|
188
|
+
private :environment
|
189
|
+
|
190
|
+
|
191
|
+
def server_software
|
192
|
+
val = @req.get_attributes('server_software')
|
193
|
+
val and val[0] and /([A-Za-z]+)/ =~ val[0] and $1.downcase
|
194
|
+
end
|
195
|
+
|
196
|
+
def query_string
|
197
|
+
val = @req.get_attributes('query_string')
|
198
|
+
val and val[0]
|
199
|
+
end
|
200
|
+
|
201
|
+
def_delegators :@req,
|
202
|
+
:ssl?, :cookies, :cookes=, *AJP_PACKET_EMBED_VARIABLES
|
203
|
+
|
204
|
+
# HTTP method name as a Symbol
|
205
|
+
def method
|
206
|
+
@req.method.downcase.to_sym
|
207
|
+
end
|
123
208
|
|
124
209
|
def raw_post
|
125
210
|
if @req.body
|
@@ -151,32 +236,17 @@ class AjpRailsRequest < ActionController::AbstractRequest
|
|
151
236
|
end
|
152
237
|
end
|
153
238
|
|
154
|
-
|
155
|
-
|
156
|
-
def server_software
|
157
|
-
val = @req.get_attributes('server_software')
|
158
|
-
val and val[0] and /([A-Za-z]+)/ =~ val[0] and $1.downcase
|
159
|
-
end
|
160
|
-
|
161
|
-
def query_string
|
162
|
-
val = @req.get_attributes('query_string')
|
163
|
-
val and val[0]
|
164
|
-
end
|
165
|
-
|
239
|
+
# Overrides blank implementation in AbstractRequest
|
166
240
|
def query_parameters
|
167
241
|
(qs = self.query_string).blank? ? {} : CGIMethods.parse_query_parameters(qs)
|
168
242
|
end
|
169
243
|
|
170
|
-
|
171
|
-
@post_params ||= CGI.parse(raw_post)
|
172
|
-
@post_params
|
173
|
-
end
|
174
|
-
|
244
|
+
# Overrides blank implementation in AbstractRequest
|
175
245
|
def request_parameters
|
176
246
|
if formatted_post?
|
177
247
|
CGIMethods.parse_formatted_request_parameters(post_format, raw_post)
|
178
248
|
else
|
179
|
-
CGIMethods.parse_request_parameters(self.
|
249
|
+
CGIMethods.parse_request_parameters(self.params)
|
180
250
|
end
|
181
251
|
end
|
182
252
|
|
@@ -188,6 +258,8 @@ class AjpRailsRequest < ActionController::AbstractRequest
|
|
188
258
|
(@req['host'] and @req['host'].split(':').first) ||
|
189
259
|
''
|
190
260
|
end
|
261
|
+
|
262
|
+
# Overrides AbstractRequest's one
|
191
263
|
def port
|
192
264
|
@req['x-forwarded-host'] ? standard_port : (port_from_http_host || @req.server_port)
|
193
265
|
end
|
@@ -196,6 +268,7 @@ class AjpRailsRequest < ActionController::AbstractRequest
|
|
196
268
|
$1.to_i if @req['host'] && /:(\d+)$/ =~ @req['host']
|
197
269
|
end
|
198
270
|
|
271
|
+
# Overrides blank implementation in AbstractRequest
|
199
272
|
def session
|
200
273
|
unless @session
|
201
274
|
if @session_options == false
|
@@ -214,6 +287,7 @@ class AjpRailsRequest < ActionController::AbstractRequest
|
|
214
287
|
@session
|
215
288
|
end
|
216
289
|
|
290
|
+
# Overrides blank implementation in AbstractRequest
|
217
291
|
def reset_session
|
218
292
|
@session.delete if CGI::Session === @session
|
219
293
|
@session = new_session
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ajp-rails
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0
|
7
|
-
date: 2006-01
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2006-02-01 00:00:00 +09:00
|
8
8
|
summary: Ruby on Rails Runner, which uses AJP(Apache JServ Protocol) to cooperate with a HTTPd, instead of CGI or FastCGI
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -64,7 +64,7 @@ dependencies:
|
|
64
64
|
requirements:
|
65
65
|
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: 0.2.
|
67
|
+
version: 0.2.1
|
68
68
|
version:
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rails
|