Hi,
Recently I found a nasty bug caused by respond_to. It happens only if you are using a EC2 driver and want to show hardware profile. Because HWP have names like 'm1.small', respond_to interprets this like ID 'm1' and mimetype 'small'. Which of course cause exception.
Howto replicate this:
./deltacloud -i ec2 http://localhost:3001/api/hardware_profiles/m1.small
This little patch will fix this.
-- Michal
--- server/lib/sinatra/respond_to.rb | 29 +++++++++++++++++------------ 1 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/server/lib/sinatra/respond_to.rb b/server/lib/sinatra/respond_to.rb index c097e8e..bafcff7 100644 --- a/server/lib/sinatra/respond_to.rb +++ b/server/lib/sinatra/respond_to.rb @@ -45,19 +45,24 @@ module Sinatra next if self.class.development? && request.path_info =~ %r{/__sinatra__/.*?.png}
unless options.static? && options.public? && (request.get? || request.head?) && static_file?(request.path_info) - request.path_info.sub! %r{.([^./]+)$}, '' - - ext = nil - if request.xhr? && options.assume_xhr_is_js? - ext = :js - elsif ! $1.nil? - ext = $1 - elsif env['HTTP_ACCEPT'].nil? || env['HTTP_ACCEPT'].empty? - ext = options.default_content - end - if ext - @mime_types = [ Helpers::mime_type(ext) ] - format ext + rpi = request.path_info.sub(%r{.([^./]+)$}, '') + + if (not $1) or ($1 and TEXT_MIME_TYPES.include?($1.to_sym)) + + request.path_info=rpi + ext = nil + + if request.xhr? && options.assume_xhr_is_js? + ext = :js + elsif ! $1.nil? + ext = $1 + elsif env['HTTP_ACCEPT'].nil? || env['HTTP_ACCEPT'].empty? + ext = options.default_content + end + if ext + @mime_types = [ Helpers::mime_type(ext) ] + format ext + end end end end
On Fri, 2010-05-21 at 12:46 +0200, mfojtik@redhat.com wrote:
server/lib/sinatra/respond_to.rb | 29 +++++++++++++++++------------ 1 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/server/lib/sinatra/respond_to.rb b/server/lib/sinatra/respond_to.rb index c097e8e..bafcff7 100644 --- a/server/lib/sinatra/respond_to.rb +++ b/server/lib/sinatra/respond_to.rb @@ -45,19 +45,24 @@ module Sinatra next if self.class.development? && request.path_info =~ %r{/__sinatra__/.*?.png}
unless options.static? && options.public? && (request.get? || request.head?) && static_file?(request.path_info)
request.path_info.sub! %r{\.([^\./]+)$}, ''
ext = nil
if request.xhr? && options.assume_xhr_is_js?
ext = :js
elsif ! $1.nil?
ext = $1
elsif env['HTTP_ACCEPT'].nil? || env['HTTP_ACCEPT'].empty?
ext = options.default_content
end
if ext
@mime_types = [ Helpers::mime_type(ext) ]
format ext
rpi = request.path_info.sub(%r{\.([^\./]+)$}, '')
if (not $1) or ($1 and TEXT_MIME_TYPES.include?($1.to_sym))
It doesn't seem to cause trouble, but shouldn't the above check against Rack::Mime::MIME_TYPES, i.e. the list of all known extensions for mime types, not just the text ones ?
David
On 24/05/10 15:52 +0200, David Lutterkort wrote:
It doesn't seem to cause trouble, but shouldn't the above check against Rack::Mime::MIME_TYPES, i.e. the list of all known extensions for mime types, not just the text ones ?
Yes, I added a simple change before I pushed this to allow 'png' files for example. But checking against Rack::Mime::MIME_TYPES sounds better to me.
-- Michal
On 21/05/10 12:46 +0200, mfojtik@redhat.com wrote:
Hi,
Recently I found a nasty bug caused by respond_to. It happens only if you are using a EC2 driver and want to show hardware profile. Because HWP have names like 'm1.small', respond_to interprets this like ID 'm1' and mimetype 'small'. Which of course cause exception.
Howto replicate this:
./deltacloud -i ec2 http://localhost:3001/api/hardware_profiles/m1.small
This little patch will fix this.
Because Cucumber is green, pushed to master.
-- Michal
deltacloud-devel@lists.fedorahosted.org