Skip to content

Commit

Permalink
Set HttpOnly for cookies using :http_only
Browse files Browse the repository at this point in the history
  • Loading branch information
gshutler committed Jul 3, 2013
1 parent df7e1e2 commit 65d3894
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rack/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def set_cookie_header!(header, key, value)
expires = "; expires=" +
rfc2822(value[:expires].clone.gmtime) if value[:expires]
secure = "; secure" if value[:secure]
httponly = "; HttpOnly" if value[:httponly]
httponly = "; HttpOnly" if (value.key?(:httponly) ? value[:httponly] : value[:http_only])
value = value[:value]
end
value = [value] unless Array === value
Expand Down
12 changes: 12 additions & 0 deletions test/spec_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@
response["Set-Cookie"].should.equal "foo=bar; HttpOnly"
end

it "can set http only cookies with :http_only" do
response = Rack::Response.new
response.set_cookie "foo", {:value => "bar", :http_only => true}
response["Set-Cookie"].should.equal "foo=bar; HttpOnly"
end

it "can set prefers :httponly for http only cookie setting when :httponly and :http_only provided" do
response = Rack::Response.new
response.set_cookie "foo", {:value => "bar", :httponly => false, :http_only => true}
response["Set-Cookie"].should.equal "foo=bar"
end

it "can delete cookies" do
response = Rack::Response.new
response.set_cookie "foo", "bar"
Expand Down

0 comments on commit 65d3894

Please sign in to comment.