]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
httputil: try to guess content-type from extension if it's not defined
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 11 Oct 2007 07:37:55 +0000 (07:37 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 11 Oct 2007 07:37:55 +0000 (07:37 +0000)
lib/rbot/core/utils/httputil.rb

index 3b12a9768d5af693d67c4e85cd54cb7a775e1bd1..d9b88839716d2a20f87611637ca7c50a454e1a89 100644 (file)
@@ -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