No description
Find a file
2013-03-15 04:20:59 +09:00
lib Implement HTTP::CookieJar#empty? without an argument. 2013-03-15 04:20:59 +09:00
test Implement HTTP::CookieJar#empty? without an argument. 2013-03-15 04:20:59 +09:00
.gitignore Import cookie related stuff from Mechanize. 2012-10-14 18:52:52 +09:00
Gemfile Import cookie related stuff from Mechanize. 2012-10-14 18:52:52 +09:00
http-cookie.gemspec Enable code coverage. 2012-11-06 01:12:29 +09:00
LICENSE.txt Import cookie related stuff from Mechanize. 2012-10-14 18:52:52 +09:00
Rakefile Enable code coverage. 2012-11-06 01:12:29 +09:00
README.md Add HTTP::Cookie#set_cookie_value, and alias #cookie_value to #to_s. 2013-03-15 04:20:59 +09:00

HTTP::Cookie

HTTP::Cookie is a ruby library to handle HTTP cookies in a way both compliant with RFCs and compatible with today's major browsers.

It was originally a part of the Mechanize library, separated as an independent library in the hope of serving as a common component that is reusable from any HTTP related piece of software.

Installation

Add this line to your application's Gemfile:

gem 'http-cookie'

And then execute:

$ bundle

Or install it yourself as:

$ gem install http-cookie

Usage

########################
# Client side example
########################

# Initialize a cookie jar
jar = HTTP::CookieJar.new

# Load from a file
jar.load(filename) if File.exist?(filename)

# Store received cookies
HTTP::Cookie.parse(set_cookie_header_value, origin: uri) { |cookie|
  jar << cookie
}

# Get the value for the Cookie field of a request header
cookie_header_value = jar.cookies(uri).join(', ')

# Save to a file
jar.save(filename)


########################
# Server side example
########################

# Generate a cookie
cookies = HTTP::Cookie.new("uid", "a12345", domain: 'example.org',
                                            for_domain: true,
                                            path: '/',
                                            max_age: 7*86400)

# Get the value for the Set-Cookie field of a response header
set_cookie_header_value = cookies.set_cookie_value(my_url)

To-Do list

  • Print kind error messages to make migration from Mechanize::Cookie easier

  • Make serializers pluggable/autoloadable and prepare a binary friendly API

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request