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
67 def redirect_http_to_https
68   return if ssl?
69 
70   opts = roda_class.opts[:redirect_http_to_https]
71 
72   res = response
73 
74   if body = opts[:body]
75     res.write(body)
76   end
77 
78   if headers = opts[:headers]
79     res.headers.merge!(headers)
80   end
81 
82   path = if prefix = opts[:prefix]
83     prefix + fullpath
84   else
85     "https://#{host}#{opts[:port_string]}#{fullpath}"
86   end
87 
88   unless status = opts[:status_map][@env['REQUEST_METHOD']]
89     raise RodaError, "redirect_http_to_https :status_map provided does not support #{@env['REQUEST_METHOD']}"
90   end
91 
92   redirect(path, status)
93 end