Class: Jets::Controller::Response
- Inherits:
-
Rack::Response
- Object
- Rack::Response
- Jets::Controller::Response
show all
- Includes:
- ActionDispatch::Http::Cache::Response, ActionDispatch::Http::FilterRedirect, Compat::Response, MonitorMixin
- Defined in:
- lib/jets/controller/response.rb
Overview
Defined Under Namespace
Modules: Compat
Constant Summary
collapse
- NO_CONTENT_CODES =
[100, 101, 102, 103, 204, 205, 304]
Compat::Response::CONTENT_TYPE, Compat::Response::CONTENT_TYPE_PARSER, Compat::Response::NullContentTypeHeader
Instance Attribute Summary collapse
Instance Method Summary
collapse
#charset, #charset=, #parse_content_type, #parsed_content_type_header, #set_content_type
Constructor Details
Returns a new instance of Response.
21
22
23
24
|
# File 'lib/jets/controller/response.rb', line 21
def initialize(*)
super
prepare_cache_control!
end
|
Instance Attribute Details
#request ⇒ Object
Returns the value of attribute request.
19
20
21
|
# File 'lib/jets/controller/response.rb', line 19
def request
@request
end
|
Instance Method Details
#assign_default_content_type_and_charset! ⇒ Object
73
74
75
76
77
78
79
|
# File 'lib/jets/controller/response.rb', line 73
def assign_default_content_type_and_charset!
return if media_type
ct =
set_content_type(ct.mime_type || Mime[:html].to_s,
ct.charset || self.class.default_charset)
end
|
#before_committed ⇒ Object
66
67
68
69
70
71
|
# File 'lib/jets/controller/response.rb', line 66
def before_committed
assign_default_content_type_and_charset!
merge_and_normalize_cache_control!(@cache_control)
handle_conditional_get!
handle_no_content!
end
|
#body=(body) ⇒ Object
What Rack::Response#initialize does.
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/jets/controller/response.rb', line 27
def body=(body)
if body.nil?
@body = []
@buffered = true
@length = 0
elsif body.respond_to?(:to_str)
@body = [body]
@buffered = true
@length = body.to_str.bytesize
else
@body = body
@buffered = false
@length = 0
end
@body
end
|
#commit! ⇒ Object
59
60
61
62
63
64
|
# File 'lib/jets/controller/response.rb', line 59
def commit!
synchronize do
before_committed
@committed = true
end
end
|
#committed? ⇒ Boolean
54
|
# File 'lib/jets/controller/response.rb', line 54
def committed?; synchronize { @committed }; end
|
#each ⇒ Object
96
97
98
|
# File 'lib/jets/controller/response.rb', line 96
def each
block_given? ? super : enum_for(:each)
end
|
#finish ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/jets/controller/response.rb', line 100
def finish
result = body
if drop_content_info?
.delete "Content-Length"
.delete "Content-Type"
end
if drop_body?
close
result = []
end
if calculate_content_length?
["Content-Length"] = body.inject(0) { |l, p| l + p.bytesize }.to_s
end
[status.to_i, , result]
end
|
#handle_no_content! ⇒ Object
81
82
83
84
85
|
# File 'lib/jets/controller/response.rb', line 81
def handle_no_content!
if NO_CONTENT_CODES.include?(@status)
.delete "Content-Length"
end
end
|
125
126
127
|
# File 'lib/jets/controller/response.rb', line 125
def media_type
["Content-Type"]
end
|
#rack_response(status, header) ⇒ Object
88
89
90
91
92
93
94
|
# File 'lib/jets/controller/response.rb', line 88
def rack_response(status, )
if NO_CONTENT_CODES.include?(status)
[status, , []]
else
[status, , body]
end
end
|
#sending? ⇒ Boolean
sending? and send? are for compatibility but not used for Jets
56
|
# File 'lib/jets/controller/response.rb', line 56
def sending?; synchronize { @sending }; end
|
#sent? ⇒ Boolean
57
|
# File 'lib/jets/controller/response.rb', line 57
def sent?; synchronize { @sent }; end
|
#status=(status) ⇒ Object
Sets the HTTP status code.
45
46
47
|
# File 'lib/jets/controller/response.rb', line 45
def status=(status)
@status = Rack::Utils.status_code(status)
end
|
#to_a ⇒ Object
49
50
51
52
|
# File 'lib/jets/controller/response.rb', line 49
def to_a
commit!
rack_response status, .to_hash
end
|