merb-core 0.9.13 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +5 -3
- data/lib/merb-core.rb +84 -41
- data/lib/merb-core/bootloader.rb +71 -60
- data/lib/merb-core/config.rb +31 -17
- data/lib/merb-core/controller/abstract_controller.rb +35 -35
- data/lib/merb-core/controller/exceptions.rb +14 -9
- data/lib/merb-core/controller/merb_controller.rb +22 -20
- data/lib/merb-core/controller/mime.rb +5 -5
- data/lib/merb-core/controller/mixins/authentication.rb +11 -8
- data/lib/merb-core/controller/mixins/conditional_get.rb +7 -7
- data/lib/merb-core/controller/mixins/controller.rb +15 -15
- data/lib/merb-core/controller/mixins/render.rb +16 -16
- data/lib/merb-core/controller/mixins/responder.rb +23 -23
- data/lib/merb-core/controller/template.rb +17 -17
- data/lib/merb-core/core_ext/hash.rb +2 -2
- data/lib/merb-core/core_ext/kernel.rb +19 -18
- data/lib/merb-core/dispatch/cookies.rb +13 -0
- data/lib/merb-core/dispatch/default_exception/default_exception.rb +12 -1
- data/lib/merb-core/dispatch/dispatcher.rb +6 -5
- data/lib/merb-core/dispatch/request.rb +56 -52
- data/lib/merb-core/dispatch/request_parsers.rb +7 -7
- data/lib/merb-core/dispatch/router.rb +14 -14
- data/lib/merb-core/dispatch/router/behavior.rb +31 -31
- data/lib/merb-core/dispatch/router/cached_proc.rb +13 -1
- data/lib/merb-core/dispatch/router/resources.rb +9 -9
- data/lib/merb-core/dispatch/router/route.rb +60 -7
- data/lib/merb-core/dispatch/session.rb +21 -15
- data/lib/merb-core/dispatch/session/container.rb +10 -8
- data/lib/merb-core/dispatch/session/cookie.rb +12 -11
- data/lib/merb-core/dispatch/session/memcached.rb +4 -2
- data/lib/merb-core/dispatch/session/memory.rb +8 -6
- data/lib/merb-core/dispatch/session/store_container.rb +6 -5
- data/lib/merb-core/dispatch/worker.rb +28 -10
- data/lib/merb-core/gem_ext/erubis.rb +4 -2
- data/lib/merb-core/logger.rb +3 -22
- data/lib/merb-core/plugins.rb +5 -5
- data/lib/merb-core/rack.rb +1 -1
- data/lib/merb-core/rack/adapter.rb +5 -1
- data/lib/merb-core/rack/adapter/abstract.rb +15 -10
- data/lib/merb-core/rack/adapter/ebb.rb +4 -2
- data/lib/merb-core/rack/adapter/evented_mongrel.rb +2 -1
- data/lib/merb-core/rack/adapter/fcgi.rb +3 -1
- data/lib/merb-core/rack/adapter/irb.rb +10 -1
- data/lib/merb-core/rack/adapter/mongrel.rb +5 -2
- data/lib/merb-core/rack/adapter/runner.rb +3 -1
- data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +2 -1
- data/lib/merb-core/rack/adapter/thin.rb +4 -1
- data/lib/merb-core/rack/adapter/thin_turbo.rb +1 -0
- data/lib/merb-core/rack/adapter/webrick.rb +8 -34
- data/lib/merb-core/rack/application.rb +2 -2
- data/lib/merb-core/rack/handler/mongrel.rb +7 -0
- data/lib/merb-core/rack/helpers.rb +1 -1
- data/lib/merb-core/rack/middleware.rb +7 -1
- data/lib/merb-core/rack/middleware/conditional_get.rb +3 -0
- data/lib/merb-core/rack/middleware/content_length.rb +2 -0
- data/lib/merb-core/rack/middleware/path_prefix.rb +4 -0
- data/lib/merb-core/rack/middleware/profiler.rb +3 -1
- data/lib/merb-core/rack/middleware/static.rb +7 -1
- data/lib/merb-core/rack/middleware/tracer.rb +1 -0
- data/lib/merb-core/rack/stream_wrapper.rb +35 -30
- data/lib/merb-core/server.rb +17 -16
- data/lib/merb-core/tasks/gem_management.rb +1 -1
- data/lib/merb-core/tasks/merb.rb +3 -1
- data/lib/merb-core/tasks/merb_rake_helper.rb +1 -1
- data/lib/merb-core/test.rb +8 -8
- data/lib/merb-core/test/helpers.rb +1 -1
- data/lib/merb-core/test/helpers/cookie_jar.rb +16 -2
- data/lib/merb-core/test/helpers/mock_request_helper.rb +13 -13
- data/lib/merb-core/test/helpers/request_helper.rb +1 -1
- data/lib/merb-core/test/helpers/route_helper.rb +2 -2
- data/lib/merb-core/test/matchers.rb +3 -3
- data/lib/merb-core/test/matchers/request_matchers.rb +1 -1
- data/lib/merb-core/test/run_spec.rb +1 -1
- data/lib/merb-core/test/tasks/spectasks.rb +1 -1
- data/lib/merb-core/test/test_ext/hpricot.rb +1 -1
- data/lib/merb-core/test/test_ext/rspec.rb +2 -2
- data/lib/merb-core/test/test_ext/string.rb +1 -1
- data/lib/merb-core/version.rb +1 -1
- metadata +8 -22
- data/lib/merb-core/test/matchers/view_matchers.rb +0 -231
- data/lib/merb-core/test/webrat.rb +0 -37
- data/lib/merb-core/vendor/nokogiri/css.rb +0 -6
- data/lib/merb-core/vendor/nokogiri/css/generated_parser.rb +0 -653
- data/lib/merb-core/vendor/nokogiri/css/generated_tokenizer.rb +0 -159
- data/lib/merb-core/vendor/nokogiri/css/node.rb +0 -95
- data/lib/merb-core/vendor/nokogiri/css/parser.rb +0 -24
- data/lib/merb-core/vendor/nokogiri/css/parser.y +0 -198
- data/lib/merb-core/vendor/nokogiri/css/tokenizer.rb +0 -9
- data/lib/merb-core/vendor/nokogiri/css/tokenizer.rex +0 -63
- data/lib/merb-core/vendor/nokogiri/css/xpath_visitor.rb +0 -159
@@ -8,6 +8,7 @@ class Merb::Controller < Merb::AbstractController
|
|
8
8
|
cattr_accessor :_subclasses
|
9
9
|
self._subclasses = Set.new
|
10
10
|
|
11
|
+
# :api: private
|
11
12
|
def self.subclasses_list() _subclasses end
|
12
13
|
|
13
14
|
include Merb::ResponderMixin
|
@@ -19,7 +20,7 @@ class Merb::Controller < Merb::AbstractController
|
|
19
20
|
# klass<Merb::Controller>::
|
20
21
|
# The Merb::Controller inheriting from the base class.
|
21
22
|
#
|
22
|
-
#
|
23
|
+
# :api: private
|
23
24
|
def self.inherited(klass)
|
24
25
|
_subclasses << klass.to_s
|
25
26
|
super
|
@@ -35,7 +36,7 @@ class Merb::Controller < Merb::AbstractController
|
|
35
36
|
# Array[String]::
|
36
37
|
# An array of actions that should not be possible to dispatch to.
|
37
38
|
#
|
38
|
-
#
|
39
|
+
# :api: public
|
39
40
|
def self.hide_action(*names)
|
40
41
|
self._hidden_actions = self._hidden_actions | names.map { |n| n.to_s }
|
41
42
|
end
|
@@ -66,7 +67,7 @@ class Merb::Controller < Merb::AbstractController
|
|
66
67
|
# end
|
67
68
|
# end
|
68
69
|
#
|
69
|
-
#
|
70
|
+
# :api: public
|
70
71
|
def self.show_action(*names)
|
71
72
|
self._shown_actions = self._shown_actions | names.map {|n| n.to_s}
|
72
73
|
end
|
@@ -78,7 +79,7 @@ class Merb::Controller < Merb::AbstractController
|
|
78
79
|
# ==== Returns
|
79
80
|
# SimpleSet[String]:: A set of actions that should be callable.
|
80
81
|
#
|
81
|
-
#
|
82
|
+
# :api: public
|
82
83
|
def self.callable_actions
|
83
84
|
@callable_actions ||= Extlib::SimpleSet.new(_callable_methods)
|
84
85
|
end
|
@@ -91,7 +92,7 @@ class Merb::Controller < Merb::AbstractController
|
|
91
92
|
# ==== Returns
|
92
93
|
# Hash{Symbol => String}:: A new list of params, filtered as desired
|
93
94
|
#
|
94
|
-
#
|
95
|
+
# :api: plugin
|
95
96
|
# @overridable
|
96
97
|
def self._filter_params(params)
|
97
98
|
params
|
@@ -102,7 +103,7 @@ class Merb::Controller < Merb::AbstractController
|
|
102
103
|
# ==== Returns
|
103
104
|
# Array:: A list of method names that are also actions
|
104
105
|
#
|
105
|
-
#
|
106
|
+
# :api: private
|
106
107
|
def self._callable_methods
|
107
108
|
callables = []
|
108
109
|
klass = self
|
@@ -129,7 +130,7 @@ class Merb::Controller < Merb::AbstractController
|
|
129
130
|
# By default, this renders ":controller/:action.:type". To change this,
|
130
131
|
# override it in your application class or in individual controllers.
|
131
132
|
#
|
132
|
-
#
|
133
|
+
# :api: public
|
133
134
|
# @overridable
|
134
135
|
def _template_location(context, type, controller)
|
135
136
|
_conditionally_append_extension(controller ? "#{controller}/#{context}" : "#{context}", type)
|
@@ -147,7 +148,7 @@ class Merb::Controller < Merb::AbstractController
|
|
147
148
|
# type<~to_s>::
|
148
149
|
# The mime-type of the template that will be rendered. Defaults to nil.
|
149
150
|
#
|
150
|
-
#
|
151
|
+
# :api: public
|
151
152
|
def _absolute_template_location(template, type)
|
152
153
|
_conditionally_append_extension(template, type)
|
153
154
|
end
|
@@ -164,7 +165,7 @@ class Merb::Controller < Merb::AbstractController
|
|
164
165
|
# A hash of headers to start the controller with. These headers can be
|
165
166
|
# overridden later by the #headers method.
|
166
167
|
#
|
167
|
-
#
|
168
|
+
# :api: plugin
|
168
169
|
# @overridable
|
169
170
|
def initialize(request, status=200, headers={'Content-Type' => 'text/html; charset=utf-8'})
|
170
171
|
super()
|
@@ -182,7 +183,7 @@ class Merb::Controller < Merb::AbstractController
|
|
182
183
|
# ==== Raises
|
183
184
|
# ActionNotFound:: The requested action was not found in class.
|
184
185
|
#
|
185
|
-
#
|
186
|
+
# :api: plugin
|
186
187
|
def _dispatch(action=:index)
|
187
188
|
Merb.logger.info("Params: #{self.class._filter_params(request.params).inspect}")
|
188
189
|
start = Time.now
|
@@ -195,12 +196,13 @@ class Merb::Controller < Merb::AbstractController
|
|
195
196
|
self
|
196
197
|
end
|
197
198
|
|
199
|
+
# :api: public
|
198
200
|
attr_reader :request, :headers
|
199
201
|
|
200
202
|
# ==== Returns
|
201
203
|
# Fixnum:: The response status code
|
202
204
|
#
|
203
|
-
#
|
205
|
+
# :api: public
|
204
206
|
def status
|
205
207
|
@_status
|
206
208
|
end
|
@@ -210,7 +212,7 @@ class Merb::Controller < Merb::AbstractController
|
|
210
212
|
# ==== Parameters
|
211
213
|
# s<Fixnum, Symbol>:: A status-code or named http-status
|
212
214
|
#
|
213
|
-
#
|
215
|
+
# :api: public
|
214
216
|
def status=(s)
|
215
217
|
if s.is_a?(Symbol) && STATUS_CODES.key?(s)
|
216
218
|
@_status = STATUS_CODES[s]
|
@@ -224,7 +226,7 @@ class Merb::Controller < Merb::AbstractController
|
|
224
226
|
# ==== Returns
|
225
227
|
# Hash:: The parameters from the request object
|
226
228
|
#
|
227
|
-
#
|
229
|
+
# :api: public
|
228
230
|
def params() request.params end
|
229
231
|
|
230
232
|
# There are three possible ways to use this method. First, if you have a named route,
|
@@ -280,7 +282,7 @@ class Merb::Controller < Merb::AbstractController
|
|
280
282
|
#
|
281
283
|
# url(:articles, 2008, 10, "test_article")
|
282
284
|
#
|
283
|
-
#
|
285
|
+
# :api: public
|
284
286
|
def url(name, *args)
|
285
287
|
args << params
|
286
288
|
name = request.route if name == :this
|
@@ -315,7 +317,7 @@ class Merb::Controller < Merb::AbstractController
|
|
315
317
|
# resource(:users, :new) # => /users/new
|
316
318
|
# resource(:@user, :edit) # => /users/10/edit
|
317
319
|
#
|
318
|
-
#
|
320
|
+
# :api: public
|
319
321
|
def resource(*args)
|
320
322
|
args << params
|
321
323
|
Merb::Router.resource(*args)
|
@@ -329,7 +331,7 @@ class Merb::Controller < Merb::AbstractController
|
|
329
331
|
# This uses the same arguments as the url method, with added requirements
|
330
332
|
# of protocol and host options.
|
331
333
|
#
|
332
|
-
#
|
334
|
+
# :api: public
|
333
335
|
def absolute_url(*args)
|
334
336
|
options = extract_options_from_args!(args) || {}
|
335
337
|
options[:protocol] ||= request.protocol
|
@@ -344,7 +346,7 @@ class Merb::Controller < Merb::AbstractController
|
|
344
346
|
# Array[Integer, Hash, String]::
|
345
347
|
# The controller's status code, headers, and body
|
346
348
|
#
|
347
|
-
#
|
349
|
+
# :api: private
|
348
350
|
def rack_response
|
349
351
|
[status, headers, Merb::Rack::StreamWrapper.new(body)]
|
350
352
|
end
|
@@ -353,7 +355,7 @@ class Merb::Controller < Merb::AbstractController
|
|
353
355
|
# This controller will not be able to be routed to
|
354
356
|
# and is used for super classing only
|
355
357
|
#
|
356
|
-
#
|
358
|
+
# :api: public
|
357
359
|
def self.abstract!
|
358
360
|
@_abstract = true
|
359
361
|
end
|
@@ -364,7 +366,7 @@ class Merb::Controller < Merb::AbstractController
|
|
364
366
|
# Boolean
|
365
367
|
# true if the controller has been set as abstract
|
366
368
|
#
|
367
|
-
#
|
369
|
+
# :api: public
|
368
370
|
def self.abstract?
|
369
371
|
!!@_abstract
|
370
372
|
end
|
@@ -383,7 +385,7 @@ class Merb::Controller < Merb::AbstractController
|
|
383
385
|
# type<~to_s> ::
|
384
386
|
# The extension to append to the template path conditionally
|
385
387
|
#
|
386
|
-
#
|
388
|
+
# :api: private
|
387
389
|
def _conditionally_append_extension(template, type)
|
388
390
|
type && !template.match(/\.#{type.to_s.escape_regexp}$/) ? "#{template}.#{type}" : template
|
389
391
|
end
|
@@ -17,7 +17,7 @@ module Merb
|
|
17
17
|
# :default_quality # the scale factor used in describing content type preference
|
18
18
|
# :response_block # the block to be called with the controller when a request responds to this mime type
|
19
19
|
#
|
20
|
-
#
|
20
|
+
# :api: public
|
21
21
|
def available_mime_types
|
22
22
|
ResponderMixin::TYPES
|
23
23
|
end
|
@@ -26,7 +26,7 @@ module Merb
|
|
26
26
|
# Hash{String => Symbol}::
|
27
27
|
# A hash mapping Content-Type values to the mime type key of the appropriate entry in #available_mime_types
|
28
28
|
#
|
29
|
-
#
|
29
|
+
# :api: public
|
30
30
|
def available_accepts
|
31
31
|
ResponderMixin::MIMES
|
32
32
|
end
|
@@ -66,7 +66,7 @@ module Merb
|
|
66
66
|
# ==== Returns
|
67
67
|
# nil
|
68
68
|
#
|
69
|
-
#
|
69
|
+
# :api: public
|
70
70
|
def add_mime_type(key, transform_method, mimes, new_response_headers = {}, default_quality = 1, &block)
|
71
71
|
enforce!(key => Symbol, mimes => Array)
|
72
72
|
|
@@ -110,7 +110,7 @@ module Merb
|
|
110
110
|
# ==== Notes
|
111
111
|
# :all is the key for */*; It can't be removed.
|
112
112
|
#
|
113
|
-
#
|
113
|
+
# :api: public
|
114
114
|
def remove_mime_type(key)
|
115
115
|
return false if key == :all
|
116
116
|
ResponderMixin::TYPES.delete(key)
|
@@ -125,7 +125,7 @@ module Merb
|
|
125
125
|
# ==== Raises
|
126
126
|
# ArgumentError:: The requested mime type is not valid.
|
127
127
|
#
|
128
|
-
#
|
128
|
+
# :api: private
|
129
129
|
def mime_transform_method(key)
|
130
130
|
raise ArgumentError, ":#{key} is not a valid MIME-type" unless ResponderMixin::TYPES.key?(key)
|
131
131
|
ResponderMixin::TYPES[key][:transform_method]
|
@@ -75,7 +75,7 @@ module Merb::AuthenticationMixin
|
|
75
75
|
# end
|
76
76
|
#
|
77
77
|
#
|
78
|
-
#
|
78
|
+
# :api: public
|
79
79
|
def basic_authentication(realm = "Application", &authenticator)
|
80
80
|
@_basic_authentication ||= BasicAuthentication.new(self, realm, &authenticator)
|
81
81
|
end
|
@@ -84,7 +84,7 @@ module Merb::AuthenticationMixin
|
|
84
84
|
# So we can have access to the status codes
|
85
85
|
include Merb::ControllerExceptions
|
86
86
|
|
87
|
-
#
|
87
|
+
# :api: private
|
88
88
|
def initialize(controller, realm = "Application", &authenticator)
|
89
89
|
@controller = controller
|
90
90
|
@realm = realm
|
@@ -101,6 +101,9 @@ module Merb::AuthenticationMixin
|
|
101
101
|
#
|
102
102
|
# ==== Returns
|
103
103
|
# Object:: False if basic auth is not provided, otherwise the return value of the authenticator block.
|
104
|
+
#
|
105
|
+
# @overridable
|
106
|
+
# :api: public
|
104
107
|
def authenticate(&authenticator)
|
105
108
|
if @auth.provided? and @auth.basic?
|
106
109
|
authenticator.call(*@auth.credentials)
|
@@ -114,7 +117,7 @@ module Merb::AuthenticationMixin
|
|
114
117
|
# ==== Throws
|
115
118
|
# :halt with an "HTTP Basic: Access denied." message with no layout, and sets the status to Unauthorized.
|
116
119
|
#
|
117
|
-
#
|
120
|
+
# :api: public
|
118
121
|
def request
|
119
122
|
request!
|
120
123
|
throw :halt, @controller.render("HTTP Basic: Access denied.\n", :status => Unauthorized.status, :layout => false)
|
@@ -125,7 +128,7 @@ module Merb::AuthenticationMixin
|
|
125
128
|
# ==== Returns
|
126
129
|
# String:: Returns the empty string to provide a response body.
|
127
130
|
#
|
128
|
-
#
|
131
|
+
# :api: public
|
129
132
|
def request!
|
130
133
|
@controller.status = Unauthorized.status
|
131
134
|
@controller.headers['WWW-Authenticate'] = 'Basic realm="%s"' % @realm
|
@@ -135,7 +138,7 @@ module Merb::AuthenticationMixin
|
|
135
138
|
# ==== Returns
|
136
139
|
# Boolean:: Whether there has been any basic authentication credentials provided
|
137
140
|
#
|
138
|
-
#
|
141
|
+
# :api: public
|
139
142
|
def provided?
|
140
143
|
@auth.provided?
|
141
144
|
end
|
@@ -143,7 +146,7 @@ module Merb::AuthenticationMixin
|
|
143
146
|
# ==== Returns
|
144
147
|
# String:: The username provided in the request.
|
145
148
|
#
|
146
|
-
#
|
149
|
+
# :api: public
|
147
150
|
def username
|
148
151
|
provided? ? @auth.credentials.first : nil
|
149
152
|
end
|
@@ -151,14 +154,14 @@ module Merb::AuthenticationMixin
|
|
151
154
|
# ==== Returns
|
152
155
|
# String:: The password provided in the request.
|
153
156
|
#
|
154
|
-
#
|
157
|
+
# :api: public
|
155
158
|
def password
|
156
159
|
provided? ? @auth.credentials.last : nil
|
157
160
|
end
|
158
161
|
|
159
162
|
protected
|
160
163
|
|
161
|
-
#
|
164
|
+
# :api: private
|
162
165
|
def authenticate_or_request(&authenticator)
|
163
166
|
authenticate(&authenticator) || request
|
164
167
|
end
|
@@ -30,7 +30,7 @@ module Merb::ConditionalGetMixin
|
|
30
30
|
# value of ETag header enclosed in double quotes
|
31
31
|
# as required by the RFC
|
32
32
|
#
|
33
|
-
#
|
33
|
+
# :api: public
|
34
34
|
def etag=(tag)
|
35
35
|
headers[Merb::Const::ETAG] = %("#{tag}")
|
36
36
|
end
|
@@ -39,7 +39,7 @@ module Merb::ConditionalGetMixin
|
|
39
39
|
# <String>::
|
40
40
|
# Value of ETag response header or nil if it's not set.
|
41
41
|
#
|
42
|
-
#
|
42
|
+
# :api: public
|
43
43
|
def etag
|
44
44
|
headers[Merb::Const::ETAG]
|
45
45
|
end
|
@@ -49,7 +49,7 @@ module Merb::ConditionalGetMixin
|
|
49
49
|
# true if ETag response header equals If-None-Match request header,
|
50
50
|
# false otherwise
|
51
51
|
#
|
52
|
-
#
|
52
|
+
# :api: public
|
53
53
|
def etag_matches?(tag = self.etag)
|
54
54
|
tag == self.request.if_none_match
|
55
55
|
end
|
@@ -61,7 +61,7 @@ module Merb::ConditionalGetMixin
|
|
61
61
|
# resource modification timestamp converted into format
|
62
62
|
# required by the RFC
|
63
63
|
#
|
64
|
-
#
|
64
|
+
# :api: public
|
65
65
|
def last_modified=(time)
|
66
66
|
headers[Merb::Const::LAST_MODIFIED] = time.httpdate
|
67
67
|
end
|
@@ -70,7 +70,7 @@ module Merb::ConditionalGetMixin
|
|
70
70
|
# <String>::
|
71
71
|
# Value of Last-Modified response header or nil if it's not set.
|
72
72
|
#
|
73
|
-
#
|
73
|
+
# :api: public
|
74
74
|
def last_modified
|
75
75
|
Time.rfc2822(headers[Merb::Const::LAST_MODIFIED])
|
76
76
|
end
|
@@ -80,7 +80,7 @@ module Merb::ConditionalGetMixin
|
|
80
80
|
# true if Last-Modified response header is < than
|
81
81
|
# If-Modified-Since request header value, false otherwise.
|
82
82
|
#
|
83
|
-
#
|
83
|
+
# :api: public
|
84
84
|
def not_modified?(time = self.last_modified)
|
85
85
|
request.if_modified_since && time && time <= request.if_modified_since
|
86
86
|
end
|
@@ -90,7 +90,7 @@ module Merb::ConditionalGetMixin
|
|
90
90
|
# true if either ETag matches or entity is not modified,
|
91
91
|
# so request is fresh; false otherwise
|
92
92
|
#
|
93
|
-
#
|
93
|
+
# :api: public
|
94
94
|
def request_fresh?
|
95
95
|
etag_matches?(self.etag) || not_modified?(self.last_modified)
|
96
96
|
end
|
@@ -13,7 +13,7 @@ module Merb
|
|
13
13
|
# SomeBackgroundTask.run
|
14
14
|
# end
|
15
15
|
#
|
16
|
-
#
|
16
|
+
# :api: public
|
17
17
|
def run_later(&blk)
|
18
18
|
Merb::Dispatcher.work_queue << blk
|
19
19
|
end
|
@@ -46,7 +46,7 @@ module Merb
|
|
46
46
|
# end
|
47
47
|
# end
|
48
48
|
#
|
49
|
-
#
|
49
|
+
# :api: public
|
50
50
|
def render_chunked(&blk)
|
51
51
|
must_support_streaming!
|
52
52
|
headers['Transfer-Encoding'] = 'chunked'
|
@@ -65,7 +65,7 @@ module Merb
|
|
65
65
|
# ==== Parameters
|
66
66
|
# data<String>:: a chunk of data to return.
|
67
67
|
#
|
68
|
-
#
|
68
|
+
# :api: public
|
69
69
|
def send_chunk(data)
|
70
70
|
only_runs_on_mongrel!
|
71
71
|
@response.write('%x' % data.size + "\r\n")
|
@@ -82,7 +82,7 @@ module Merb
|
|
82
82
|
# A block that the server can call later, allowing Merb to release the
|
83
83
|
# thread lock and render another request.
|
84
84
|
#
|
85
|
-
#
|
85
|
+
# :api: public
|
86
86
|
def render_deferred(&blk)
|
87
87
|
Proc.new do |response|
|
88
88
|
response.write(blk.call)
|
@@ -100,7 +100,7 @@ module Merb
|
|
100
100
|
# Proc::
|
101
101
|
# A block that Mongrel can call after returning the string to the user.
|
102
102
|
#
|
103
|
-
#
|
103
|
+
# :api: public
|
104
104
|
def render_then_call(str, &blk)
|
105
105
|
Proc.new do |response|
|
106
106
|
response.write(str)
|
@@ -128,7 +128,7 @@ module Merb
|
|
128
128
|
# redirect("http://www.merbivore.com/")
|
129
129
|
# redirect("http://www.merbivore.com/", :permanent => true)
|
130
130
|
#
|
131
|
-
#
|
131
|
+
# :api: public
|
132
132
|
def redirect(url, opts = {})
|
133
133
|
default_redirect_options = { :message => nil, :permanent => false }
|
134
134
|
opts = default_redirect_options.merge(opts)
|
@@ -144,7 +144,7 @@ module Merb
|
|
144
144
|
|
145
145
|
# Retreives the redirect message either locally or from the request.
|
146
146
|
#
|
147
|
-
#
|
147
|
+
# :api: public
|
148
148
|
def message
|
149
149
|
@_message = defined?(@_message) ? @_message : request.message
|
150
150
|
end
|
@@ -166,7 +166,7 @@ module Merb
|
|
166
166
|
# ==== Returns
|
167
167
|
# IO:: An I/O stream for the file.
|
168
168
|
#
|
169
|
-
#
|
169
|
+
# :api: public
|
170
170
|
def send_file(file, opts={})
|
171
171
|
opts.update(Merb::Const::DEFAULT_SEND_FILE_OPTIONS.merge(opts))
|
172
172
|
disposition = opts[:disposition].dup || 'attachment'
|
@@ -199,7 +199,7 @@ module Merb
|
|
199
199
|
# The name to use for the file. Defaults to the filename of file.
|
200
200
|
# :type<String>:: The content type.
|
201
201
|
#
|
202
|
-
#
|
202
|
+
# :api: public
|
203
203
|
def send_data(data, opts={})
|
204
204
|
opts.update(Merb::Const::DEFAULT_SEND_FILE_OPTIONS.merge(opts))
|
205
205
|
disposition = opts[:disposition].dup || 'attachment'
|
@@ -235,7 +235,7 @@ module Merb
|
|
235
235
|
# end
|
236
236
|
# end
|
237
237
|
#
|
238
|
-
#
|
238
|
+
# :api: public
|
239
239
|
def stream_file(opts={}, &stream)
|
240
240
|
opts.update(Merb::Const::DEFAULT_SEND_FILE_OPTIONS.merge(opts))
|
241
241
|
disposition = opts[:disposition].dup || 'attachment'
|
@@ -277,7 +277,7 @@ module Merb
|
|
277
277
|
# ==== Return
|
278
278
|
# String:: precisely a single space.
|
279
279
|
#
|
280
|
-
#
|
280
|
+
# :api: public
|
281
281
|
def nginx_send_file(path, content_type = "")
|
282
282
|
# Let Nginx detect content type unless it is explicitly set
|
283
283
|
headers['Content-Type'] = content_type
|
@@ -297,7 +297,7 @@ module Merb
|
|
297
297
|
# value<~to_s>:: A value for the cookie.
|
298
298
|
# expires<~gmtime:~strftime, Hash>:: An expiration time for the cookie, or a hash of cookie options.
|
299
299
|
#
|
300
|
-
#
|
300
|
+
# :api: public
|
301
301
|
def set_cookie(name, value, expires)
|
302
302
|
options = expires.is_a?(Hash) ? expires : {:expires => expires}
|
303
303
|
cookies.set_cookie(name, value, options)
|
@@ -311,7 +311,7 @@ module Merb
|
|
311
311
|
# ==== Parameters
|
312
312
|
# name<~to_s>:: A name for the cookie to delete.
|
313
313
|
#
|
314
|
-
#
|
314
|
+
# :api: public
|
315
315
|
def delete_cookie(name)
|
316
316
|
set_cookie(name, nil, Merb::Const::COOKIE_EXPIRED_TIME)
|
317
317
|
end
|
@@ -324,7 +324,7 @@ module Merb
|
|
324
324
|
# ==== Returns
|
325
325
|
# String:: The escaped object.
|
326
326
|
#
|
327
|
-
#
|
327
|
+
# :api: public
|
328
328
|
def escape_xml(obj)
|
329
329
|
Erubis::XmlHelper.escape_xml(obj.to_s)
|
330
330
|
end
|
@@ -338,7 +338,7 @@ module Merb
|
|
338
338
|
# ==== Raises
|
339
339
|
# NotImplemented:: The Rack adapter is not mongrel.
|
340
340
|
#
|
341
|
-
#
|
341
|
+
# :api: private
|
342
342
|
def only_runs_on_mongrel!
|
343
343
|
unless Merb::Config[:log_stream] == 'mongrel'
|
344
344
|
raise(Merb::ControllerExceptions::NotImplemented, "Current Rack adapter is not mongrel. cannot support this feature")
|