I need to get some absolute redirects working -- basically I set callback hooks to external services, but I want these hooks to use my configured CNAME''s. I''m trying to find a way so that my app doesn''t have to know about these CNAME''s. So I''m looking at the request in the controller to try and get the base URL where I''m running. To test, I''m using localtunnel. I have found what I''m looking for in 3 places, and I''m wondering if one is better than another or if one is more reliably set than another. request.env["SERVER_NAME"] request.host request.env["HTTP_HOST"] All three of these have the value I''m looking for (e.g. "3eym.localtunnel.com") . Is there any difference between them? Should I favor one over another? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/C3S2bsSAWicJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> I need to get some absolute redirects working -- basically I set callback hooks to external services, but I want these hooks to use my configured CNAME''s. I''m trying to find a way so that my app doesn''t have to know about these CNAME''s. So I''m looking at the request in the controller to try and get the base URL where I''m running. > > To test, I''m using localtunnel. I have found what I''m looking for in 3 places, and I''m wondering if one is better than another or if one is more reliably set than another. > > request.env["SERVER_NAME"] > request.host > request.env["HTTP_HOST"] > > All three of these have the value I''m looking for (e.g. "3eym.localtunnel.com") . Is there any difference between them? Should I favor one over another?I''d use request.host... That calls raw_host_with_port (and trims the port). raw_host_with_port looks like this: def raw_host_with_port if forwarded = env["HTTP_X_FORWARDED_HOST"] forwarded.split(/,\s?/).last else env[''HTTP_HOST''] || "#{env[''SERVER_NAME''] || env[''SERVER_ADDR'']}:#{env[''SERVER_PORT'']}" end end So does some extra checking for you... https://github.com/rails/rails/blob/5f67cfeda116f2b932ef72781420aa37e62437ca/actionpack/lib/action_dispatch/http/url.rb#L92 -philip -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
thank you -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/RkN-PDbt95AJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.