module ActionDispatch::Http::URL

def protocol

req.protocol # => "https://"
req = Request.new 'HTTP_HOST' => 'example.com', 'HTTPS' => 'on'

req.protocol # => "http://"
req = Request.new 'HTTP_HOST' => 'example.com'

end
include ActionDispatch::Http::URL
class Request < Rack::Request

Returns 'https://' if this is an SSL request and 'http://' otherwise.
def protocol
  @protocol ||= ssl? ? 'https://' : 'http://'
end