New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headers are not preserved on redirect #464

Closed
simonbaird opened this Issue Aug 23, 2011 · 6 comments

Comments

Projects
None yet
2 participants
@simonbaird

simonbaird commented Aug 23, 2011

I'm doing something like this to simulate an authenticated (kerberos) user:

page.driver.browser.options[:headers]['HTTP_X_REMOTE_USER'] = username

It works fine unless I visit a url with a redirect. Then the header is lost and I'm no longer authed.

I wrote a failing test that illustrates the problem. See here:

simonbaird@cdc7ad7

I'm not sure how to fix this, but I'd give it a try given a small amount of encouragement...

Ps, anyone know a way to work around this issue?

@simonbaird

This comment has been minimized.

Show comment
Hide comment
@simonbaird

simonbaird Aug 23, 2011

Maybe implement a follow_redirect! method instead of using the rack method?

simonbaird commented Aug 23, 2011

Maybe implement a follow_redirect! method instead of using the rack method?

@simonbaird

This comment has been minimized.

Show comment
Hide comment
@simonbaird

simonbaird Aug 23, 2011

Maybe this is really a bug in rack-test...

simonbaird commented Aug 23, 2011

Maybe this is really a bug in rack-test...

@jnicklas

This comment has been minimized.

Show comment
Hide comment
@jnicklas

jnicklas Aug 26, 2011

Collaborator

you're really not supposed to set headers this way. The Rack-Test driver has a headers option which you can use. Like this:

Capybara.register_driver :rack_test do |app|
  Capybara::RackTest::Driver.new(app, :headers => { 'Foo' => 'Bar' })
end

however, that actually might have the same issue. Try it out and let me know how it goes.

Collaborator

jnicklas commented Aug 26, 2011

you're really not supposed to set headers this way. The Rack-Test driver has a headers option which you can use. Like this:

Capybara.register_driver :rack_test do |app|
  Capybara::RackTest::Driver.new(app, :headers => { 'Foo' => 'Bar' })
end

however, that actually might have the same issue. Try it out and let me know how it goes.

@jnicklas

This comment has been minimized.

Show comment
Hide comment
@jnicklas

jnicklas Aug 26, 2011

Collaborator

Ahh, never mind my comment, just understood why you're doing what you're doing. This does indeed appear to be a bug.

Collaborator

jnicklas commented Aug 26, 2011

Ahh, never mind my comment, just understood why you're doing what you're doing. This does indeed appear to be a bug.

@jnicklas jnicklas closed this in 33b1a27 Aug 30, 2011

@simonbaird

This comment has been minimized.

Show comment
Hide comment
@simonbaird

simonbaird Aug 31, 2011

Great stuff. Thanks very much.

simonbaird commented Aug 31, 2011

Great stuff. Thanks very much.

@simonbaird

This comment has been minimized.

Show comment
Hide comment
@simonbaird

simonbaird Aug 31, 2011

Here's a workaround for anyone waiting for the updated gem.

module Capybara::DSL
  # Work around for problem fixed here:
  # https://github.com/jnicklas/capybara/issues/464
  def visit_with_redir_header_fix(path)
    # This will follow redirects (but not preserve headers)
    visit_without_redir_header_fix(path)
    # Now visit again and the headers will be used correctly
    visit_without_redir_header_fix(current_url)
  end
  alias_method_chain :visit, :redir_header_fix
end

Disclaimer: This is not pretty. Since you will be visiting everything twice there might be some unintended side-effects. Use at your own risk, etc.

simonbaird commented Aug 31, 2011

Here's a workaround for anyone waiting for the updated gem.

module Capybara::DSL
  # Work around for problem fixed here:
  # https://github.com/jnicklas/capybara/issues/464
  def visit_with_redir_header_fix(path)
    # This will follow redirects (but not preserve headers)
    visit_without_redir_header_fix(path)
    # Now visit again and the headers will be used correctly
    visit_without_redir_header_fix(current_url)
  end
  alias_method_chain :visit, :redir_header_fix
end

Disclaimer: This is not pretty. Since you will be visiting everything twice there might be some unintended side-effects. Use at your own risk, etc.

radar added a commit to reinteractive/capybara that referenced this issue Nov 1, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment