instance method send_file_headers!

Ruby on Rails 3.2.22.5

Since v3.1.12 Private

Available in: v3.1.12 v3.2.22.5 v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

send_file_headers!(options)

No documentation comment.

Parameters

options req
Source
# File actionpack/lib/action_controller/metal/data_streaming.rb, line 136
      def send_file_headers!(options)
        type_provided = options.has_key?(:type)

        options.update(DEFAULT_SEND_FILE_OPTIONS.merge(options))
        [:type, :disposition].each do |arg|
          raise ArgumentError, ":#{arg} option required" if options[arg].nil?
        end

        disposition = options[:disposition].to_s
        disposition += %(; filename="#{options[:filename]}") if options[:filename]

        content_type = options[:type]

        if content_type.is_a?(Symbol)
          extension = Mime[content_type]
          raise ArgumentError, "Unknown MIME type #{options[:type]}" unless extension
          self.content_type = extension
        else
          if !type_provided && options[:filename]
            # If type wasn't provided, try guessing from file extension.
            content_type = Mime::Type.lookup_by_extension(File.extname(options[:filename]).downcase.tr('.','')) || content_type
          end
          self.content_type = content_type
        end

        headers.merge!(
          'Content-Disposition'       => disposition,
          'Content-Transfer-Encoding' => 'binary'
        )

        response.sending_file = true

        # Fix a problem with IE 6.0 on opening downloaded files:
        # If Cache-Control: no-cache is set (which Rails does by default),
        # IE removes the file it just downloaded from its cache immediately
        # after it displays the "open/save" dialog, which means that if you
        # hit "open" the file isn't there anymore when the application that
        # is called for handling the download is run, so let's workaround that
        response.cache_control[:public] ||= false
      end

Defined in actionpack/lib/action_controller/metal/data_streaming.rb line 136 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionController::DataStreaming

Type at least 2 characters to search.

↑↓ navigate · open · esc close