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@googlegroups.com.
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.

Search Discussions

  • Philip Hallstrom at Feb 10, 2012 at 7:18 pm

    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@googlegroups.com.
    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.
  • John Hinnegan at Feb 10, 2012 at 11:23 pm
    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@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 10, '12 at 6:01p
activeFeb 10, '12 at 11:23p
posts3
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

John Hinnegan: 2 posts Philip Hallstrom: 1 post

People

Translate

site design / logo © 2022 Grokbase