6

Is there a way to pass request information, such as HOST header value, on to app.get?

My application requires that a particular host is present, so when I call it normally like this:

app.get("foo")

Specifically, I want to override the

request.env["HTTP_HOST"]

value.

tia

Geremy
  • 2,415
  • 1
  • 23
  • 27

2 Answers2

8

As per this answer:

The method docs for .get are here: http://api.rubyonrails.org/classes/ActionDispatch/Integration/RequestHelpers.html#method-i-get

You can do something like:

  app.get('/foo', nil, {'HTTP_HOST' => "bar.com"})
Community
  • 1
  • 1
William Denniss
  • 16,089
  • 7
  • 81
  • 124
  • 1
    And of course you don't need to know the path if you know the route: `app.get(app.foo_path, nil, {'HTTP_HOST' => "bar.com"})` – clozach Aug 26 '13 at 20:46
  • Thanks for the answer. I'm wondering how the docs are helpful here though, as the `{'HTTP_HOST' => "bar.com"}` part is literally undocumented. At least `**args` isn't helpful to me. – Linus Sep 07 '18 at 07:40
0

I'm not sure this help... I've seen code like the following:

app.call({
  "HTTP_HOST"=>"...",
  "SCRIPT_NAME" => "",
  "PATH_INFO"=>"/lala/#{lala_id}/",
  "QUERY_STRING" => "",
  "SERVER_NAME" => "",
  "SERVER_PORT" => "80",
  "REQUEST_METHOD"=>"GET",
  "rack.input" => StringIO.new
})

You might be able to still use .get and just pass HTTP_HOST as an option like above?

Robin
  • 21,667
  • 10
  • 62
  • 85