A summary of data about the Ruby ecosystem.

https://github.com/sparklemotion/http-cookie

A Ruby library to handle HTTP cookies in a way both compliant with RFCs and compatible with today's major browsers
https://github.com/sparklemotion/http-cookie

Keywords from Contributors

rubocop activejob activerecord mvc rubygems rspec code-formatter static-code-analysis libxml2 libxslt

Last synced: about 22 hours ago
JSON representation

Repository metadata

A Ruby library to handle HTTP cookies in a way both compliant with RFCs and compatible with today's major browsers

README.md

Gem Version

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.

The following is an incomplete list of its features:

  • Its behavior is highly compatible with that of today's major web
    browsers.

  • It is based on and conforms to RFC 6265 (the latest standard for the
    HTTP cookie mechanism) to a high extent, with real world conventions
    deeply in mind.

  • It takes eTLD (effective TLD, also known as "Public Suffix") into
    account just as major browsers do, to reject cookies with an eTLD
    domain like "org", "co.jp", or "appspot.com". This feature is
    brought to you by the
    domain_name gem.

  • The number of cookies and the size are properly capped so that a
    cookie store does not get flooded.

  • It supports the legacy Netscape cookies.txt format for
    serialization, maximizing the interoperability with other
    implementations.

  • It supports the cookies.sqlite format adopted by Mozilla Firefox for
    backend store database which can be shared among multiple program
    instances.

  • It is relatively easy to add a new serialization format or a backend
    store because of its modular API.

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 1
########################

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

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

# Store received cookies, where uri is the origin of this header
header["Set-Cookie"].each { |value|
  jar.parse(value, uri)
}

# ...

# Set the Cookie header value, where uri is the destination URI
header["Cookie"] = HTTP::Cookie.cookie_value(jar.cookies(uri))

# Save to a file
jar.save(filename)


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

# Initialize a cookie jar using a Mozilla compatible SQLite3 backend
jar = HTTP::CookieJar.new(store: :mozilla, filename: 'cookies.sqlite')

# There is no need for load & save in this backend.

# Store received cookies, where uri is the origin of this header
header["Set-Cookie"].each { |value|
  jar.parse(value, uri)
}

# ...

# Set the Cookie header value, where uri is the destination URI
header["Cookie"] = HTTP::Cookie.cookie_value(jar.cookies(uri))


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

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

# Add it to the Set-Cookie response header
header['Set-Cookie'] = cookie1.set_cookie_value

# Generate a host-only cookie
cookie2 = HTTP::Cookie.new("aid", "a12345", origin: my_url,
                                            path: '/',
                                            max_age: 7*86400)

# Add it to the Set-Cookie response header
header['Set-Cookie'] = cookie2.set_cookie_value

Incompatibilities with Mechanize::Cookie/CookieJar

There are several incompatibilities between
Mechanize::Cookie/CookieJar and HTTP::Cookie/CookieJar. Below
is how to rewrite existing code written for Mechanize::Cookie with
equivalent using HTTP::Cookie:

  • Mechanize::Cookie.parse

    The parameter order changed in HTTP::Cookie.parse.

      # before
      cookies1 = Mechanize::Cookie.parse(uri, set_cookie1)
      cookies2 = Mechanize::Cookie.parse(uri, set_cookie2, log)
    
      # after
      cookies1 = HTTP::Cookie.parse(set_cookie1, uri_or_url)
      cookies2 = HTTP::Cookie.parse(set_cookie2, uri_or_url, logger: log)
      # or you can directly store parsed cookies in your jar
      jar.parse(set_cookie1, uri_or_url)
      jar.parse(set_cookie1, uri_or_url, logger: log)
    
  • Mechanize::Cookie#version, #version=

    There is no longer a sense of version in the HTTP cookie
    specification. The only version number ever defined was zero, and
    there will be no other version defined since the version attribute
    has been removed in RFC 6265.

  • Mechanize::Cookie#comment, #comment=

    Ditto. The comment attribute has been removed in RFC 6265.

  • Mechanize::Cookie#set_domain

    This method was unintentionally made public. Simply use
    HTTP::Cookie#domain=.

      # before
      cookie.set_domain(domain)
    
      # after
      cookie.domain = domain
    
  • Mechanize::CookieJar#add, #add!

    Always use HTTP::CookieJar#add.

      # before
      jar.add!(cookie1)
      jar.add(uri, cookie2)
    
      # after
      jar.add(cookie1)
      cookie2.origin = uri; jar.add(cookie2)  # or specify origin in parse() or new()
    
  • Mechanize::CookieJar#clear!

    Use HTTP::Cookiejar#clear.

      # before
      jar.clear!
    
      # after
      jar.clear
    
  • Mechanize::CookieJar#save_as

    Use HTTP::CookieJar#save.

      # before
      jar.save_as(file)
    
      # after
      jar.save(file)
    
  • Mechanize::CookieJar#jar

    There is no direct access to the internal hash in HTTP::CookieJar
    since it has introduced an abstract store layer. If you want to
    tweak the internals of the hash store, try creating a new store
    class referring to the default store class
    HTTP::CookieJar::HashStore.

    If you desperately need it you can access it by
    jar.store.instance_variable_get(:@jar), but there is no
    guarantee that it will remain available in the future.

HTTP::Cookie/CookieJar raises runtime errors to help migration, so
after replacing the class names, try running your test code once to
find out how to fix your code base.

File formats

The YAML serialization format has changed, and HTTP::CookieJar#load
cannot import what is written in a YAML file saved by
Mechanize::CookieJar#save_as. HTTP::CookieJar#load will not raise an
exception if an incompatible YAML file is given, but the content is
silently ignored.

Note that there is (obviously) no forward compatibillity with this.
Trying to load a YAML file saved by HTTP::CookieJar with
Mechanize::CookieJar will fail in runtime error.

On the other hand, there has been (and will ever be) no change in the
cookies.txt format, so use it instead if compatibility is significant.

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

Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 2 days ago

Total Commits: 322
Total Committers: 14
Avg Commits per committer: 23.0
Development Distribution Score (DDS): 0.087

Commits in past year: 5
Committers in past year: 3
Avg Commits per committer in past year: 1.667
Development Distribution Score (DDS) in past year: 0.4

Name Email Commits
Akinori MUSHA k****u@i****g 294
Mike Dalessio m****o@g****m 12
Mike Morearty m****e@m****m 2
Luke Hill 2****l 2
Christian Schmidt g****b@c****k 2
André Laszlo a****e@l****u 2
wrzasa w****a@r****l 1
sergioro 2****9 1
Yuri Zubov y****v@c****o 1
Per Lundberg p****g@e****m 1
Pavel Lobashov S****N@g****m 1
Lee Jarvis l****s@g****m 1
Dan Duvall d****n@m****o 1
ore o****e@d****l 1

Committer domains:


Issue and Pull Request metadata

Last synced: 13 days ago

Total issues: 24
Total pull requests: 39
Average time to close issues: over 2 years
Average time to close pull requests: about 2 years
Total issue authors: 23
Total pull request authors: 24
Average comments per issue: 1.96
Average comments per pull request: 1.36
Merged pull request: 19
Bot issues: 0
Bot pull requests: 0

Past year issues: 1
Past year pull requests: 4
Past year average time to close issues: N/A
Past year average time to close pull requests: about 1 month
Past year issue authors: 1
Past year pull request authors: 2
Past year average comments per issue: 0.0
Past year average comments per pull request: 1.5
Past year merged pull request: 3
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/sparklemotion/http-cookie

Top Issue Authors

  • perlun (2)
  • ShockwaveNN (1)
  • JasonBarnabe (1)
  • mzachh (1)
  • luke-hill (1)
  • maia (1)
  • jesseclark (1)
  • uksa (1)
  • tarcieri (1)
  • mtasaka (1)
  • elliotcm (1)
  • jondavid-schober-sp (1)
  • bastelfreak (1)
  • midnight-wonderer (1)
  • headius (1)

Top Pull Request Authors

  • flavorjones (6)
  • luke-hill (3)
  • olleolleolle (3)
  • wrzasa (2)
  • perlun (2)
  • petergoldstein (2)
  • sergioro9 (2)
  • vakuum (2)
  • JasonBarnabe (2)
  • scottleedavis (1)
  • ShockwaveNN (1)
  • marxarelli (1)
  • knu (1)
  • yuri-zubov (1)
  • igoriuz (1)

Top Issue Labels

Top Pull Request Labels


Package metadata

gem.coop: http-cookie

HTTP::Cookie is a Ruby library to handle HTTP Cookies based on RFC 6265. It has with security, standards compliance and compatibility in mind, to behave just the same as today's major web browsers. It has builtin support for the legacy cookies.txt and the latest cookies.sqlite formats of Mozilla Firefox, and its modular API makes it easy to add support for a new backend store.

  • Homepage: https://github.com/sparklemotion/http-cookie
  • Documentation: http://www.rubydoc.info/gems/http-cookie/
  • Licenses: MIT
  • Latest release: 1.1.0 (published 5 months ago)
  • Last Synced: 2026-02-28T19:31:01.145Z (3 days ago)
  • Versions: 27
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 615,741,996 Total
  • Docker Downloads: 1,918,062,106
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 0.022%
    • Downloads: 0.034%
    • Docker downloads count: 0.056%
  • Maintainers (2)
rubygems.org: http-cookie

HTTP::Cookie is a Ruby library to handle HTTP Cookies based on RFC 6265. It has with security, standards compliance and compatibility in mind, to behave just the same as today's major web browsers. It has builtin support for the legacy cookies.txt and the latest cookies.sqlite formats of Mozilla Firefox, and its modular API makes it easy to add support for a new backend store.

  • Homepage: https://github.com/sparklemotion/http-cookie
  • Documentation: http://www.rubydoc.info/gems/http-cookie/
  • Licenses: MIT
  • Latest release: 1.1.0 (published 5 months ago)
  • Last Synced: 2026-02-28T20:43:11.525Z (3 days ago)
  • Versions: 27
  • Dependent Packages: 62
  • Dependent Repositories: 89,575
  • Downloads: 615,746,685 Total
  • Docker Downloads: 1,918,062,106
  • Rankings:
    • Downloads: 0.035%
    • Docker downloads count: 0.067%
    • Dependent repos count: 0.127%
    • Dependent packages count: 0.453%
    • Average: 1.621%
    • Forks count: 3.767%
    • Stargazers count: 5.279%
  • Maintainers (2)
proxy.golang.org: github.com/sparklemotion/http-cookie

  • Homepage:
  • Documentation: https://pkg.go.dev/github.com/sparklemotion/http-cookie#section-documentation
  • Licenses: mit
  • Latest release: v1.1.0 (published 5 months ago)
  • Last Synced: 2026-02-28T20:43:12.322Z (3 days ago)
  • Versions: 16
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Forks count: 3.517%
    • Stargazers count: 4.58%
    • Average: 7.109%
    • Dependent packages count: 9.56%
    • Dependent repos count: 10.779%
ubuntu-24.04: ruby-http-cookie

  • Homepage: https://github.com/sparklemotion/http-cookie
  • Licenses:
  • Latest release: 1.0.5-1 (published 25 days ago)
  • Last Synced: 2026-02-06T15:21:38.417Z (25 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
debian-10: ruby-http-cookie

  • Homepage: https://github.com/sparklemotion/http-cookie
  • Documentation: https://packages.debian.org/buster/ruby-http-cookie
  • Licenses:
  • Latest release: 1.0.3-1 (published 20 days ago)
  • Last Synced: 2026-02-13T04:22:14.463Z (19 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-23.04: ruby-http-cookie

  • Homepage: https://github.com/sparklemotion/http-cookie
  • Licenses:
  • Latest release: 1.0.5-1 (published 21 days ago)
  • Last Synced: 2026-02-11T06:41:16.053Z (21 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-20.04: ruby-http-cookie

  • Homepage: https://github.com/sparklemotion/http-cookie
  • Licenses:
  • Latest release: 1.0.3-1 (published 18 days ago)
  • Last Synced: 2026-02-13T07:15:09.251Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
debian-11: ruby-http-cookie

  • Homepage: https://github.com/sparklemotion/http-cookie
  • Documentation: https://packages.debian.org/bullseye/ruby-http-cookie
  • Licenses:
  • Latest release: 1.0.3-1 (published 21 days ago)
  • Last Synced: 2026-02-13T08:21:21.644Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-23.10: ruby-http-cookie

  • Homepage: https://github.com/sparklemotion/http-cookie
  • Licenses:
  • Latest release: 1.0.5-1 (published 18 days ago)
  • Last Synced: 2026-02-13T18:22:51.692Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-22.04: ruby-http-cookie

  • Homepage: https://github.com/sparklemotion/http-cookie
  • Licenses:
  • Latest release: 1.0.3-1 (published 18 days ago)
  • Last Synced: 2026-02-13T13:18:40.583Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
debian-12: ruby-http-cookie

  • Homepage: https://github.com/sparklemotion/http-cookie
  • Documentation: https://packages.debian.org/bookworm/ruby-http-cookie
  • Licenses:
  • Latest release: 1.0.5-1 (published 19 days ago)
  • Last Synced: 2026-02-12T23:32:24.513Z (19 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
ubuntu-24.10: ruby-http-cookie

  • Homepage: https://github.com/sparklemotion/http-cookie
  • Licenses:
  • Latest release: 1.0.5-1 (published 22 days ago)
  • Last Synced: 2026-02-09T16:43:47.242Z (22 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
debian-13: ruby-http-cookie

  • Homepage: https://github.com/sparklemotion/http-cookie
  • Documentation: https://packages.debian.org/trixie/ruby-http-cookie
  • Licenses: mit
  • Latest release: 1.0.5-1 (published 19 days ago)
  • Last Synced: 2026-02-13T13:16:23.776Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%

Dependencies

http-cookie.gemspec rubygems
  • bundler >= 1.2.0 development
  • simplecov >= 0 development
  • domain_name ~> 0.5
.github/workflows/ci.yml actions
  • actions/checkout v2 composite
  • ruby/setup-ruby v1 composite

Score: 29.955024695736682