Class: UzuUzu::Response
Class Method Summary
collapse
Instance Method Summary
collapse
#action, #application, #controller, #h, #helper, #instance_variable_map, #logger, #query, #query_string, #request, #response, #route, #service, #session, #u
Class Method Details
13
14
15
|
# File 'lib/uzuuzu-core/response.rb', line 13
def self.current
Thread.current[:response]
end
|
Instance Method Details
#etag(value, kind = :strong) ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/uzuuzu-core/response.rb', line 114
def etag(value, kind=:strong)
raise ::TypeError, ":strong or :weak expected" if ![:strong,:weak].include?(kind)
value = '"%s"' % value
value = 'W/' + value if kind == :weak
@header['ETag'] = value
if etags = request.env['HTTP_IF_NONE_MATCH']
etags = etags.split(/\s*,\s*/)
if etags.include?(value) || etags.include?('*')
@status = 304
throw :finish
end
end
end
|
#last_modified(time) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/uzuuzu-core/response.rb', line 97
def last_modified(time)
return unless time
if time.respond_to?(:to_time)
time = time.to_time
else
time = ::Time.parse(time.to_s)
end
@header['Last-Modified'] = time.httpdate
if ::Time.httpdate(request.env['HTTP_IF_MODIFIED_SINCE']).to_i >= time.to_i
@status = 304
throw :finish
end
end
|
#mime_type(mime) ⇒ Object
30
31
32
|
# File 'lib/uzuuzu-core/response.rb', line 30
def mime_type(mime)
@header["Content-Type"] = rack_mime_type(mime) || mime if mime
end
|
#not_found(code = 404, options = {}) ⇒ Object
72
73
74
|
# File 'lib/uzuuzu-core/response.rb', line 72
def not_found(code=404, options={})
server_error(code, options)
end
|
#rack_mime_type(type, value = nil) ⇒ Object
20
21
22
23
24
25
|
# File 'lib/uzuuzu-core/response.rb', line 20
def rack_mime_type(type, value=nil)
return type if type.nil? || type.to_s.include?('/')
type = ".#{type}" unless type.to_s[0] == ?.
return Rack::Mime.mime_type(type, nil) if value.nil?
Rack::Mime::MIME_TYPES[type] = value
end
|
#redirect(uri, options = {}) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/uzuuzu-core/response.rb', line 79
def redirect(uri, options={})
if not uri =~ /^https?:\/\//
abs_uri = "#{request.scheme}://#{request.host}"
if request.scheme == 'https' && request.port != 443 ||
request.scheme == 'http' && request.port != 80
abs_uri << ":#{request.port}"
end
uri = (abs_uri << uri)
end
uri << query_string(options)
super(uri)
throw :finish
end
|
#respond(string, mime = nil, status = 200) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/uzuuzu-core/response.rb', line 37
def respond(string, mime=nil, status=200)
@status = 200
mime_type(mime)
write string
throw :finish
end
|
#respond_to ⇒ Object
47
48
49
50
51
52
|
# File 'lib/uzuuzu-core/response.rb', line 47
def respond_to
return unless block_given?
@status = 200
contents = yield(request.wish)
respond(contents, request.wish) if contents and successful?
end
|
#send_binary ⇒ Object
58
59
60
|
# File 'lib/uzuuzu-core/response.rb', line 58
def send_binary()
end
|
#send_file ⇒ Object
54
55
56
|
# File 'lib/uzuuzu-core/response.rb', line 54
def send_file()
end
|
#server_error(code = 500, options = {}) ⇒ Object
65
66
67
|
# File 'lib/uzuuzu-core/response.rb', line 65
def server_error(code=500, options={})
redirect "/error/#{code}"
end
|