module Roda::RodaPlugins::RedirectHttpToHttps::RequestMethods

  1. lib/roda/plugins/redirect_http_to_https.rb

Methods

Public Instance

  1. redirect_http_to_https

Public Instance methods

redirect_http_to_https()

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.

[show source]
   # File lib/roda/plugins/redirect_http_to_https.rb
70 def redirect_http_to_https
71   return if ssl?
72 
73   opts = roda_class.redirect_http_to_https_opts
74 
75   res = response
76 
77   if body = opts[:body]
78     res.write(body)
79   end
80 
81   if headers = opts[:headers]
82     res.headers.merge!(headers)
83   end
84 
85   path = if prefix = opts[:prefix]
86     prefix + fullpath
87   else
88     "https://#{host}#{opts[:port_string]}#{fullpath}"
89   end
90 
91   unless status = opts[:status_map][@env['REQUEST_METHOD']]
92     raise RodaError, "redirect_http_to_https :status_map provided does not support #{@env['REQUEST_METHOD']}"
93   end
94 
95   redirect(path, status)
96 end