Always set content_type in responder
This commit is contained in:
parent
61142c7cf6
commit
f3ceee9b28
|
@ -32,6 +32,10 @@ module Travis::Api::App::Responders
|
||||||
endpoint.headers
|
endpoint.headers
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def apply
|
||||||
|
endpoint.content_type content_type
|
||||||
|
end
|
||||||
|
|
||||||
def apply?
|
def apply?
|
||||||
resource && acceptable_format?
|
resource && acceptable_format?
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,6 +13,10 @@ module Travis::Api::App::Responders
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def content_type
|
||||||
|
'image/png'
|
||||||
|
end
|
||||||
|
|
||||||
def filename
|
def filename
|
||||||
"#{root}/public/images/result/#{result}.png"
|
"#{root}/public/images/result/#{result}.png"
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,11 +8,17 @@ class Travis::Api::App
|
||||||
end
|
end
|
||||||
|
|
||||||
def apply
|
def apply
|
||||||
|
super
|
||||||
|
|
||||||
halt result.to_json if result
|
halt result.to_json if result
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def content_type
|
||||||
|
'application/json;charset=utf-8'
|
||||||
|
end
|
||||||
|
|
||||||
def accepts_log?
|
def accepts_log?
|
||||||
return true unless resource.is_a?(Log)
|
return true unless resource.is_a?(Log)
|
||||||
|
|
||||||
|
|
|
@ -14,17 +14,22 @@ module Travis::Api::App::Responders
|
||||||
end
|
end
|
||||||
|
|
||||||
def apply
|
def apply
|
||||||
|
super
|
||||||
|
|
||||||
filename = resource.id
|
filename = resource.id
|
||||||
disposition = params[:attachment] ? 'attachment' : 'inline'
|
disposition = params[:attachment] ? 'attachment' : 'inline'
|
||||||
|
|
||||||
headers['Content-Disposition'] = %(#{disposition}; filename="#{filename}")
|
headers['Content-Disposition'] = %(#{disposition}; filename="#{filename}")
|
||||||
|
|
||||||
endpoint.content_type 'text/plain'
|
|
||||||
halt(params[:deansi] ? clear_ansi(resource.content) : resource.content)
|
halt(params[:deansi] ? clear_ansi(resource.content) : resource.content)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def content_type
|
||||||
|
'text/plain'
|
||||||
|
end
|
||||||
|
|
||||||
def clear_ansi(content)
|
def clear_ansi(content)
|
||||||
content.gsub(/\r\r/, "\r")
|
content.gsub(/\r\r/, "\r")
|
||||||
.gsub(/^.*\r(?!$)/, '')
|
.gsub(/^.*\r(?!$)/, '')
|
||||||
|
|
|
@ -20,11 +20,17 @@ module Travis::Api::App::Responders
|
||||||
end
|
end
|
||||||
|
|
||||||
def apply
|
def apply
|
||||||
|
super
|
||||||
|
|
||||||
halt TEMPLATE % data
|
halt TEMPLATE % data
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def content_type
|
||||||
|
'application/xml;charset=utf-8'
|
||||||
|
end
|
||||||
|
|
||||||
def data
|
def data
|
||||||
{
|
{
|
||||||
name: resource.slug,
|
name: resource.slug,
|
||||||
|
|
|
@ -6,7 +6,7 @@ module Travis::Api::App::Responders
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:request) { stub 'request', params: {} }
|
let(:request) { stub 'request', params: {} }
|
||||||
let(:endpoint) { stub 'endpoint', request: request }
|
let(:endpoint) { stub 'endpoint', request: request, content_type: nil }
|
||||||
let(:resource) { stub 'resource' }
|
let(:resource) { stub 'resource' }
|
||||||
let(:accept) { stub 'accept entry', version: '2', params: {} }
|
let(:accept) { stub 'accept entry', version: '2', params: {} }
|
||||||
let(:options) { { :accept => accept} }
|
let(:options) { { :accept => accept} }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user