4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RackTestドライバを使ったCapybaraでのHTTPリクエストのヘッダ情報を覗く

Posted at

CapybaraRackTestドライバの設定中でテスト対象のappをやりとりしているので、ここで渡すappを弄るとヘッダを覗くことが出来る。(envはヘッダそのものではないがその情報を含んでいる)

original = Capybara.drivers[:rack_test]
Capybara.register_driver :rack_test do |app|
  spied_app = lambda { |env| p env; app[env].tap { |status, header| p [status, header] } }
  original[spied_app]
end

以下のような出力になる(一部省略)

{"rack.version"=>[1, 3], "rack.multithread"=>true, "rack.multiprocess"=>true, "rack.run_once"=>false, ..., "REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/", "rack.url_scheme"=>"https", "HTTPS"=>"on", "SCRIPT_NAME"=>"", "CONTENT_LENGTH"=>"0", "rack.test"=>true, "REMOTE_ADDR"=>"127.0.0.1", "HTTP_REFERER"=>"https://hoge.fuga.jp", "HTTP_HOST"=>"hoge.fuga.jp", "HTTP_COOKIE"=>""}

[302, {"Content-Length"=>"74", "Location"=>"https://hoge.fuga.jp/", "Cache-Control"=>"no-cache", "Set-Cookie"=>"_session_key=....; domain=.fuga.jp; path=/; expires=Sun, 17 Jul 2016 04:14:29 -0000; HttpOnly", "Vary"=>"Origin"}]
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?