Method: Jets::Controller::Redirection#ensure_protocol
- Defined in:
- lib/jets/controller/redirection.rb
#ensure_protocol(url) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jets/controller/redirection.rb', line 34 def ensure_protocol(url) return url if url.starts_with?('http') # annoying but the request payload is different with localhost/rack vs # api gateway # check out: # spec/fixtures/dumps/api_gateway/posts/create.json # spec/fixtures/dumps/rack/posts/create.json protocol = if actual_host.include?("amazonaws.com") # API Gateway headers["x-forwarded-proto"] elsif headers["origin"] # Rack / localhost URI.parse(headers["origin"]).scheme else "http" # fallback. Capybara / Selenium tests end raise "Invalid protocol #{protocol}" unless protocol.starts_with?('http') "#{protocol}://#{url}" end |