Class: Rack::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/secure_only/request.rb

Overview

The secure_only extension add some convenience methods to determine if the request is a http or a https request

Instance Method Summary collapse

Instance Method Details

#forwarded_protoString

Returns the value of the HTTP_X_FORWARDED_PROTO header.

Returns:

  • (String)

    the value of the HTTP_X_FORWARDED_PROTO header



34
35
36
# File 'lib/rack/secure_only/request.rb', line 34

def forwarded_proto
  @env['HTTP_X_FORWARDED_PROTO']
end

#http?(use_forwarded_proto = true) ⇒ Boolean

Returns true if the current url scheme is http and the HTTP_X_FORWARDED_PROTO header is not set to https

Returns:

  • (Boolean)


13
14
15
16
17
18
19
# File 'lib/rack/secure_only/request.rb', line 13

def http?(use_forwarded_proto=true)
  if use_forwarded_proto
    scheme == 'http' && forwarded_proto != 'https'
  else
    scheme == 'http'
  end
end

#https?(use_forwarded_proto = true) ⇒ Boolean

Returns true if the current url scheme is https or the HTTP_X_FORWARDED_PROTO header is set to https

Returns:

  • (Boolean)


24
25
26
27
28
29
30
# File 'lib/rack/secure_only/request.rb', line 24

def https?(use_forwarded_proto=true)
  if use_forwarded_proto
    scheme == 'https' || forwarded_proto == 'https'
  else
    scheme == 'https'
  end
end