From a209adb0e00e2a335333c1cb696d5807a47072c6 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Thu, 11 Oct 2007 07:37:55 +0000 Subject: httputil: try to guess content-type from extension if it's not defined --- lib/rbot/core/utils/httputil.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/rbot/core/utils/httputil.rb b/lib/rbot/core/utils/httputil.rb index 3b12a976..d9b88839 100644 --- a/lib/rbot/core/utils/httputil.rb +++ b/lib/rbot/core/utils/httputil.rb @@ -404,6 +404,22 @@ class HttpUtil undef_method :body alias :body :cooked_body end + unless resp['content-type'] + debug "No content type, guessing" + resp['content-type'] = + case resp['x-rbot-location'] + when /.html?$/i + 'text/html' + when /.xml$/i + 'application/xml' + when /.xhtml$/i + 'application/xml+xhtml' + when /.(gif|png|jpe?g|jp2|tiff?)$/i + "image/#{$1.sub(/^jpg$/,'jpeg').sub(/^tif$/,'tiff')}" + else + 'application/octetstream' + end + end if block_given? yield(resp) else -- cgit v1.2.3