Module: Roda::RodaPlugins::RedirectHttpToHttps::RequestMethods

Defined in:
lib/roda/plugins/redirect_http_to_https.rb

Instance Method Summary collapse

Instance Method Details

#redirect_http_to_httpsObject

Redirect HTTP requests to HTTPS. While this doesn’t secure the current request, it makes it more likely that the browser will submit future requests securely via HTTPS.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/roda/plugins/redirect_http_to_https.rb', line 67

def redirect_http_to_https
  return if ssl?

  opts = roda_class.opts[:redirect_http_to_https]

  res = response

  if body = opts[:body]
    res.write(body)
  end

  if headers = opts[:headers]
    res.headers.merge!(headers)
  end

  path = if prefix = opts[:prefix]
    prefix + fullpath
  else
    "https://#{host}#{opts[:port_string]}#{fullpath}"
  end

  unless status = opts[:status_map][@env['REQUEST_METHOD']]
    raise RodaError, "redirect_http_to_https :status_map provided does not support #{@env['REQUEST_METHOD']}"
  end

  redirect(path, status)
end