summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-10-11 07:37:55 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-10-11 07:37:55 +0000
commita209adb0e00e2a335333c1cb696d5807a47072c6 (patch)
treec276b9384f0afda8312f30a4bd8435bdc8ef9cea
parent47372190dc5982739ae568534dfb01b178a08af8 (diff)
httputil: try to guess content-type from extension if it's not defined
-rw-r--r--lib/rbot/core/utils/httputil.rb16
1 files changed, 16 insertions, 0 deletions
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