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