Skip to content

Instantly share code, notes, and snippets.

@cmar
Created March 13, 2012 14:10
Show Gist options
  • Save cmar/2029000 to your computer and use it in GitHub Desktop.
Save cmar/2029000 to your computer and use it in GitHub Desktop.
Spree::BaseController.class_eval do
ENV['DEFAULT_HTTPS_HOST'] = 'spreeworks.dev'
ENV['DEFAULT_HTTP_HOST'] = 'spreebeta.dev'
protected
def https_redirect_url
redirect_url_with_session('https', "#{ENV['RAILS_CACHE_ID']}.#{ENV['DEFAULT_HTTPS_HOST']}")
end
def http_redirect_url
redirect_url_with_session('http', "#{ENV['RAILS_CACHE_ID']}.#{ENV['DEFAULT_HTTP_HOST']}")
end
def redirect_url_with_session(scheme, host)
uri = URI(request.url)
uri.scheme = scheme
uri.host = host
query = uri.query ? uri.query.split('&') : []
query << Rack::Middleware::SessionInjector.generate_handshake_parameter(request, uri.host)
uri.query = query.join('&')
uri.to_s
end
def ensure_proper_protocol
return true if ssl_allowed?
if ssl_required? && !request.ssl? && ssl_supported?
redirect_to https_redirect_url
flash.keep
elsif request.ssl? && !ssl_required?
redirect_to http_redirect_url
flash.keep
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment