Permalink
Browse files

Request#user_agent

  • Loading branch information...
josh committed Dec 21, 2009
1 parent e1b3b3d commit e2a1a644efda64614e2b5cab3a4ff89e5fc6d642
Showing with 13 additions and 0 deletions.
  1. +3 −0 lib/rack/request.rb
  2. +10 −0 test/spec_rack_request.rb
View
@@ -178,6 +178,9 @@ def referer
end
alias referrer referer
+ def user_agent
+ @env['HTTP_USER_AGENT']
+ end
def cookies
return {} unless @env["HTTP_COOKIE"]
View
@@ -152,6 +152,16 @@
req.referer.should.equal "/"
end
+ specify "user agent should be extracted correct" do
+ req = Rack::Request.new \
+ Rack::MockRequest.env_for("/", "HTTP_USER_AGENT" => "Mozilla/4.0 (compatible)")
+ req.user_agent.should.equal "Mozilla/4.0 (compatible)"
+
+ req = Rack::Request.new \
+ Rack::MockRequest.env_for("/")
+ req.user_agent.should.equal nil
+ end
+
specify "can cache, but invalidates the cache" do
req = Rack::Request.new \
Rack::MockRequest.env_for("/?foo=quux", :input => "foo=bar&quux=bla")

0 comments on commit e2a1a64

Please sign in to comment.