Class: Rack::AddPdfHeadersForIe

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-add-pdf-headers-for-ie.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ AddPdfHeadersForIe

Returns a new instance of AddPdfHeadersForIe.



5
6
7
# File 'lib/rack-add-pdf-headers-for-ie.rb', line 5

def initialize( app )
  @app = app
end

Instance Method Details

#add_headersObject



29
30
31
32
33
34
# File 'lib/rack-add-pdf-headers-for-ie.rb', line 29

def add_headers
  @headers['Content-Description'] = 'File Transfer'
  @headers['Content-Transfer-Encoding'] = 'binary'
  @headers['Expires'] = '0'
  @headers['Pragma'] = 'public'
end

#call(env) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/rack-add-pdf-headers-for-ie.rb', line 9

def call( env )
  @status, @headers, @body = @app.call( env )
  user_agent = env['HTTP_USER_AGENT']
  url_scheme = env['rack.url_scheme']
  add_headers if is_pdf? and is_ie?(user_agent) and is_ssl?(url_scheme)
  [@status, @headers, @body]
end

#is_ie?(user_agent) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/rack-add-pdf-headers-for-ie.rb', line 25

def is_ie?(user_agent)
  user_agent =~ (/MSIE \d/)
end

#is_pdf?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/rack-add-pdf-headers-for-ie.rb', line 17

def is_pdf?
  @headers['Content-Type'] =~ /pdf/
end

#is_ssl?(url_scheme) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/rack-add-pdf-headers-for-ie.rb', line 21

def is_ssl?(url_scheme)
  url_scheme == 'https'
end