Class: ActionDispatch::Http::ContentDisposition

Inherits:
Object
  • Object
show all
Defined in:
lib/action_dispatch/http/content_disposition.rb

Overview

:nodoc:

Constant Summary collapse

TRADITIONAL_ESCAPED_CHAR =
/[^ A-Za-z0-9!\#$+.^_`|~-]/
RFC_5987_ESCAPED_CHAR =
/[^A-Za-z0-9!\#$&+.^_`|~-]/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(disposition:, filename:) ⇒ ContentDisposition

Returns a new instance of ContentDisposition.



14
15
16
17
# File 'lib/action_dispatch/http/content_disposition.rb', line 14

def initialize(disposition:, filename:)
  @disposition = disposition
  @filename = filename
end

Instance Attribute Details

#dispositionObject (readonly)

Returns the value of attribute disposition.



12
13
14
# File 'lib/action_dispatch/http/content_disposition.rb', line 12

def disposition
  @disposition
end

#filenameObject (readonly)

Returns the value of attribute filename.



12
13
14
# File 'lib/action_dispatch/http/content_disposition.rb', line 12

def filename
  @filename
end

Class Method Details

.format(disposition:, filename:) ⇒ Object



8
9
10
# File 'lib/action_dispatch/http/content_disposition.rb', line 8

def self.format(disposition:, filename:)
  new(disposition: disposition, filename: filename).to_s
end

Instance Method Details

#ascii_filenameObject



21
22
23
# File 'lib/action_dispatch/http/content_disposition.rb', line 21

def ascii_filename
  'filename="' + percent_escape(I18n.transliterate(filename), TRADITIONAL_ESCAPED_CHAR) + '"'
end

#to_sObject



31
32
33
34
35
36
37
# File 'lib/action_dispatch/http/content_disposition.rb', line 31

def to_s
  if filename
    "#{disposition}; #{ascii_filename}; #{utf8_filename}"
  else
    "#{disposition}"
  end
end

#utf8_filenameObject



27
28
29
# File 'lib/action_dispatch/http/content_disposition.rb', line 27

def utf8_filename
  "filename*=UTF-8''" + percent_escape(filename, RFC_5987_ESCAPED_CHAR)
end