cookiejar2 0.3.5 → 0.3.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cookiejar2.gemspec +14 -0
- metadata +13 -93
- data/.circleci/config.yml +0 -15
- data/.gitignore +0 -8
- data/.rspec +0 -2
- data/.travis.yml +0 -17
- data/Gemfile +0 -2
- data/LICENSE +0 -10
- data/README.markdown +0 -37
- data/Rakefile +0 -30
- data/_config.yml +0 -1
- data/contributors.json +0 -14
- data/cookiejar.gemspec +0 -28
- data/lib/cookiejar/cookie.rb +0 -257
- data/lib/cookiejar/cookie_validation.rb +0 -410
- data/lib/cookiejar/jar.rb +0 -314
- data/lib/cookiejar/version.rb +0 -4
- data/lib/cookiejar.rb +0 -3
- data/spec/cookie_spec.rb +0 -176
- data/spec/cookie_validation_spec.rb +0 -236
- data/spec/jar_spec.rb +0 -232
- data/spec/spec_helper.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 763e84f15f66c3d6d168061930916e0b862976b855e0adbf60a8074c9f473f7a
|
4
|
+
data.tar.gz: b17c757f1c2abd3243ee07a830e9d5fb85acc325902642df82626c73dc5c8e88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f5545a86f6f32a65e61c8d37008e68b1ef2128ff1e20b97cfc3f3c7f4e4d672de020ab6d4d518c87148c16ebfa4ea1fd24db307c927df1fd82f482e810b9001
|
7
|
+
data.tar.gz: 4dd4b54705c4a81b9e2805c983758021503115c178c3fd20bf7aade4ed2072dd2a72a5d860b429a8c55e8f702e5c2c0e85de085477953067bad7a018ecd86f81
|
data/cookiejar2.gemspec
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "cookiejar2"
|
5
|
+
s.version = "0.3.5.2"
|
6
|
+
s.authors = ["David Waite", "Dorian Marié"]
|
7
|
+
s.license = "BSD-2-Clause"
|
8
|
+
s.email = ["dorian@dorianmarie.fr"]
|
9
|
+
s.description = "It was a fork on cookiejar but now cookiejar is up-to-date."
|
10
|
+
s.summary = s.description + " Please use cookiejar directly"
|
11
|
+
s.homepage = "https://github.com/dorianmariefr/cookiejar2"
|
12
|
+
s.files = ["cookiejar2.gemspec"]
|
13
|
+
s.add_dependency "cookiejar", "~> 0"
|
14
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cookiejar2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.5
|
4
|
+
version: 0.3.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Waite
|
@@ -9,113 +9,36 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: cookiejar
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '0'
|
21
|
-
type: :
|
21
|
+
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
|
-
-
|
29
|
-
name: rspec-collection_matchers
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - ">="
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '0'
|
35
|
-
type: :development
|
36
|
-
prerelease: false
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - ">="
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '0'
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: rspec
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - ">="
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: '0'
|
49
|
-
type: :development
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - ">="
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '0'
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: yard
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '0'
|
63
|
-
type: :development
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - ">="
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: bundler
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - ">="
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '0'
|
77
|
-
type: :development
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - ">="
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: '0'
|
84
|
-
description: Allows for parsing and returning cookies in Ruby HTTP client code
|
28
|
+
description: It was a fork on cookiejar but now cookiejar is up-to-date.
|
85
29
|
email:
|
86
30
|
- dorian@dorianmarie.fr
|
87
31
|
executables: []
|
88
32
|
extensions: []
|
89
33
|
extra_rdoc_files: []
|
90
34
|
files:
|
91
|
-
-
|
92
|
-
- ".gitignore"
|
93
|
-
- ".rspec"
|
94
|
-
- ".travis.yml"
|
95
|
-
- Gemfile
|
96
|
-
- LICENSE
|
97
|
-
- README.markdown
|
98
|
-
- Rakefile
|
99
|
-
- _config.yml
|
100
|
-
- contributors.json
|
101
|
-
- cookiejar.gemspec
|
102
|
-
- lib/cookiejar.rb
|
103
|
-
- lib/cookiejar/cookie.rb
|
104
|
-
- lib/cookiejar/cookie_validation.rb
|
105
|
-
- lib/cookiejar/jar.rb
|
106
|
-
- lib/cookiejar/version.rb
|
107
|
-
- spec/cookie_spec.rb
|
108
|
-
- spec/cookie_validation_spec.rb
|
109
|
-
- spec/jar_spec.rb
|
110
|
-
- spec/spec_helper.rb
|
35
|
+
- cookiejar2.gemspec
|
111
36
|
homepage: https://github.com/dorianmariefr/cookiejar2
|
112
37
|
licenses:
|
113
38
|
- BSD-2-Clause
|
114
39
|
metadata: {}
|
115
40
|
post_install_message:
|
116
|
-
rdoc_options:
|
117
|
-
- "--title"
|
118
|
-
- CookieJar -- Client-side HTTP Cookies
|
41
|
+
rdoc_options: []
|
119
42
|
require_paths:
|
120
43
|
- lib
|
121
44
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -129,12 +52,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
52
|
- !ruby/object:Gem::Version
|
130
53
|
version: '0'
|
131
54
|
requirements: []
|
132
|
-
rubygems_version: 3.3
|
55
|
+
rubygems_version: 3.5.3
|
133
56
|
signing_key:
|
134
57
|
specification_version: 4
|
135
|
-
summary:
|
136
|
-
|
137
|
-
|
138
|
-
- spec/cookie_validation_spec.rb
|
139
|
-
- spec/jar_spec.rb
|
140
|
-
- spec/spec_helper.rb
|
58
|
+
summary: It was a fork on cookiejar but now cookiejar is up-to-date. Please use cookiejar
|
59
|
+
directly
|
60
|
+
test_files: []
|
data/.circleci/config.yml
DELETED
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/LICENSE
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
Copyright (c) 2009 - 2018, David Waite and Other Contributors
|
2
|
-
All rights reserved.
|
3
|
-
|
4
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
5
|
-
|
6
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
7
|
-
|
8
|
-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
9
|
-
|
10
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.markdown
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
[![CircleCI](https://circleci.com/gh/dorianmariefr/cookiejar2/tree/main.svg?style=svg)](https://circleci.com/gh/dorianmariefr/cookiejar2/tree/main)
|
2
|
-
|
3
|
-
This is a fork to fix warnings.
|
4
|
-
|
5
|
-
-----
|
6
|
-
|
7
|
-
Ruby CookieJar
|
8
|
-
==============
|
9
|
-
|
10
|
-
**Git**: [http://github.com/dwaite/cookiejar](http://github.com/dwaite/cookiejar)
|
11
|
-
|
12
|
-
**Author**: David Waite
|
13
|
-
|
14
|
-
[![Build Status](https://travis-ci.org/dwaite/cookiejar.svg?branch=master)](https://travis-ci.org/dwaite/cookiejar)
|
15
|
-
|
16
|
-
Synopsis
|
17
|
-
--------
|
18
|
-
|
19
|
-
The Ruby CookieJar is a library to help manage client-side cookies in pure Ruby. It enables parsing and setting of cookie headers, alternating between multiple 'jars' of cookies at one time (such as having a set of cookies for each browser or thread), and supports persistence of the cookies in a JSON string.
|
20
|
-
|
21
|
-
Both Netscape/RFC 2109 cookies and RFC 2965 cookies are supported.
|
22
|
-
|
23
|
-
Roadmap
|
24
|
-
-------
|
25
|
-
|
26
|
-
For the Next major release, I would like to accomplish:
|
27
|
-
|
28
|
-
1. Check against [RFC 6265 - HTTP State Management Mechanism][rfc6265], the latest cookie spec which came out after the initial release of cookiejar
|
29
|
-
2. Determine better code structure to encourage alternate persistence mechanisms for cookie jars
|
30
|
-
|
31
|
-
[rfc6265]: http://tools.ietf.org/html/rfc6265
|
32
|
-
COPYRIGHT
|
33
|
-
---------
|
34
|
-
The Ruby CookieJar is Copyright © 2009-2014 David Waite, with [additional contributions from various authors][contributions]. Licensing terms are given within the [LICENSE file][LICENSE].
|
35
|
-
|
36
|
-
[contributions]: ./contributors.json
|
37
|
-
[LICENSE]: ./LICENSE
|
data/Rakefile
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'bundler/gem_tasks'
|
2
|
-
|
3
|
-
require 'rake'
|
4
|
-
|
5
|
-
require 'rake/clean'
|
6
|
-
require 'yard'
|
7
|
-
require 'yard/rake/yardoc_task'
|
8
|
-
|
9
|
-
CLEAN << Rake::FileList['doc/**', '.yardoc']
|
10
|
-
# Yard
|
11
|
-
YARD::Rake::YardocTask.new do |t|
|
12
|
-
t.files = ['lib/**/*.rb'] # optional
|
13
|
-
t.options = ['--title', 'CookieJar, a HTTP Client Cookie Parsing Library',
|
14
|
-
'--main', 'README.markdown', '--files', 'LICENSE']
|
15
|
-
end
|
16
|
-
|
17
|
-
begin
|
18
|
-
require 'rspec/core/rake_task'
|
19
|
-
|
20
|
-
RSpec::Core::RakeTask.new do |t|
|
21
|
-
t.ruby_opts = %w(-w)
|
22
|
-
t.pattern = 'spec/**/*_spec.rb'
|
23
|
-
end
|
24
|
-
task test: :spec
|
25
|
-
rescue LoadError
|
26
|
-
puts 'Warning: unable to load rspec tasks'
|
27
|
-
end
|
28
|
-
|
29
|
-
# Default Rake task is to run all tests
|
30
|
-
task default: :test
|
data/_config.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
theme: jekyll-theme-tactile
|
data/contributors.json
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
[
|
2
|
-
{
|
3
|
-
"author": {
|
4
|
-
"github": "http://github.com/secobarbital",
|
5
|
-
"name": "Seggy Umboh"
|
6
|
-
},
|
7
|
-
"contributions": [
|
8
|
-
"widen supported IP addresses",
|
9
|
-
"fix case-sensitivity issue with HTTP headers",
|
10
|
-
"correct issue when running under Ruby 1.8.x",
|
11
|
-
"made Jar act more like a browser (dropping cookies w/o exception)"
|
12
|
-
]
|
13
|
-
}
|
14
|
-
]
|
data/cookiejar.gemspec
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
lib = File.expand_path('../lib', __FILE__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require 'cookiejar/version'
|
6
|
-
|
7
|
-
Gem::Specification.new do |s|
|
8
|
-
s.name = 'cookiejar2'
|
9
|
-
s.version = CookieJar::VERSION
|
10
|
-
s.authors = ['David Waite', 'Dorian Marié']
|
11
|
-
s.license = 'BSD-2-Clause'
|
12
|
-
s.email = ['dorian@dorianmarie.fr']
|
13
|
-
s.description = 'Allows for parsing and returning cookies in Ruby HTTP client code'
|
14
|
-
s.summary = 'Client-side HTTP Cookie library'
|
15
|
-
s.homepage = 'https://github.com/dorianmariefr/cookiejar2'
|
16
|
-
s.date = '2022-05-15'
|
17
|
-
|
18
|
-
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
19
|
-
s.test_files = s.files.grep(%r{^(spec)/})
|
20
|
-
s.rdoc_options = ['--title', 'CookieJar -- Client-side HTTP Cookies']
|
21
|
-
s.require_paths = ['lib']
|
22
|
-
|
23
|
-
s.add_development_dependency 'rake'
|
24
|
-
s.add_development_dependency 'rspec-collection_matchers'
|
25
|
-
s.add_development_dependency 'rspec'
|
26
|
-
s.add_development_dependency 'yard'
|
27
|
-
s.add_development_dependency 'bundler'
|
28
|
-
end
|
data/lib/cookiejar/cookie.rb
DELETED
@@ -1,257 +0,0 @@
|
|
1
|
-
require 'time'
|
2
|
-
require 'uri'
|
3
|
-
require 'cookiejar/cookie_validation'
|
4
|
-
|
5
|
-
module CookieJar
|
6
|
-
# Cookie is an immutable object which defines the data model of a HTTP Cookie.
|
7
|
-
# The data values within the cookie may be different from the
|
8
|
-
# values described in the literal cookie declaration.
|
9
|
-
# Specifically, the 'domain' and 'path' values may be set to defaults
|
10
|
-
# based on the requested resource that resulted in the cookie being set.
|
11
|
-
class Cookie
|
12
|
-
# [String] The name of the cookie.
|
13
|
-
attr_reader :name
|
14
|
-
# [String] The value of the cookie, without any attempts at decoding.
|
15
|
-
attr_reader :value
|
16
|
-
|
17
|
-
# [String] The domain scope of the cookie. Follows the RFC 2965
|
18
|
-
# 'effective host' rules. A 'dot' prefix indicates that it applies both
|
19
|
-
# to the non-dotted domain and child domains, while no prefix indicates
|
20
|
-
# that only exact matches of the domain are in scope.
|
21
|
-
attr_reader :domain
|
22
|
-
|
23
|
-
# [String] The path scope of the cookie. The cookie applies to URI paths
|
24
|
-
# that prefix match this value.
|
25
|
-
attr_reader :path
|
26
|
-
|
27
|
-
# [Boolean] The secure flag is set to indicate that the cookie should
|
28
|
-
# only be sent securely. Nearly all HTTP User Agent implementations assume
|
29
|
-
# this to mean that the cookie should only be sent over a
|
30
|
-
# SSL/TLS-protected connection
|
31
|
-
attr_reader :secure
|
32
|
-
|
33
|
-
# [Boolean] Popular browser extension to mark a cookie as invisible
|
34
|
-
# to code running within the browser, such as JavaScript
|
35
|
-
attr_reader :http_only
|
36
|
-
|
37
|
-
# [Fixnum] Version indicator, currently either
|
38
|
-
# * 0 for netscape cookies
|
39
|
-
# * 1 for RFC 2965 cookies
|
40
|
-
attr_reader :version
|
41
|
-
# [String] RFC 2965 field for indicating comment (or a location)
|
42
|
-
# describing the cookie to a usesr agent.
|
43
|
-
attr_reader :comment, :comment_url
|
44
|
-
# [Boolean] RFC 2965 field for indicating session lifetime for a cookie
|
45
|
-
attr_reader :discard
|
46
|
-
# [Array<FixNum>, nil] RFC 2965 port scope for the cookie. If not nil,
|
47
|
-
# indicates specific ports on the HTTP server which should receive this
|
48
|
-
# cookie if contacted.
|
49
|
-
attr_reader :ports
|
50
|
-
# [Time] Time when this cookie was first evaluated and created.
|
51
|
-
attr_reader :created_at
|
52
|
-
|
53
|
-
# Evaluate when this cookie will expire. Uses the original cookie fields
|
54
|
-
# for a max age or expires
|
55
|
-
#
|
56
|
-
# @return [Time, nil] Time of expiry, if this cookie has an expiry set
|
57
|
-
def expires_at
|
58
|
-
if @expiry.nil? || @expiry.is_a?(Time)
|
59
|
-
@expiry
|
60
|
-
else
|
61
|
-
@created_at + @expiry
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# Indicates whether the cookie is currently considered valid
|
66
|
-
#
|
67
|
-
# @param [Time] time to compare against, or 'now' if omitted
|
68
|
-
# @return [Boolean]
|
69
|
-
def expired?(time = Time.now)
|
70
|
-
!expires_at.nil? && time > expires_at
|
71
|
-
end
|
72
|
-
|
73
|
-
# Indicates whether the cookie will be considered invalid after the end
|
74
|
-
# of the current user session
|
75
|
-
# @return [Boolean]
|
76
|
-
def session?
|
77
|
-
@expiry.nil? || @discard
|
78
|
-
end
|
79
|
-
|
80
|
-
# Create a cookie based on an absolute URI and the string value of a
|
81
|
-
# 'Set-Cookie' header.
|
82
|
-
#
|
83
|
-
# @param request_uri [String, URI] HTTP/HTTPS absolute URI of request.
|
84
|
-
# This is used to fill in domain and port if missing from the cookie,
|
85
|
-
# and to perform appropriate validation.
|
86
|
-
# @param set_cookie_value [String] HTTP value for the Set-Cookie header.
|
87
|
-
# @return [Cookie] created from the header string and request URI
|
88
|
-
# @raise [InvalidCookieError] on validation failure(s)
|
89
|
-
def self.from_set_cookie(request_uri, set_cookie_value)
|
90
|
-
args = CookieJar::CookieValidation.parse_set_cookie set_cookie_value
|
91
|
-
args[:domain] = CookieJar::CookieValidation
|
92
|
-
.determine_cookie_domain request_uri, args[:domain]
|
93
|
-
args[:path] = CookieJar::CookieValidation
|
94
|
-
.determine_cookie_path request_uri, args[:path]
|
95
|
-
cookie = Cookie.new args
|
96
|
-
CookieJar::CookieValidation.validate_cookie request_uri, cookie
|
97
|
-
cookie
|
98
|
-
end
|
99
|
-
|
100
|
-
# Create a cookie based on an absolute URI and the string value of a
|
101
|
-
# 'Set-Cookie2' header.
|
102
|
-
#
|
103
|
-
# @param request_uri [String, URI] HTTP/HTTPS absolute URI of request.
|
104
|
-
# This is used to fill in domain and port if missing from the cookie,
|
105
|
-
# and to perform appropriate validation.
|
106
|
-
# @param set_cookie_value [String] HTTP value for the Set-Cookie2 header.
|
107
|
-
# @return [Cookie] created from the header string and request URI
|
108
|
-
# @raise [InvalidCookieError] on validation failure(s)
|
109
|
-
def self.from_set_cookie2(request_uri, set_cookie_value)
|
110
|
-
args = CookieJar::CookieValidation.parse_set_cookie2 set_cookie_value
|
111
|
-
args[:domain] = CookieJar::CookieValidation
|
112
|
-
.determine_cookie_domain request_uri, args[:domain]
|
113
|
-
args[:path] = CookieJar::CookieValidation
|
114
|
-
.determine_cookie_path request_uri, args[:path]
|
115
|
-
cookie = Cookie.new args
|
116
|
-
CookieJar::CookieValidation.validate_cookie request_uri, cookie
|
117
|
-
cookie
|
118
|
-
end
|
119
|
-
|
120
|
-
# Returns cookie in a format appropriate to send to a server.
|
121
|
-
#
|
122
|
-
# @param [FixNum] 0 version, 0 for Netscape-style cookies, 1 for
|
123
|
-
# RFC2965-style.
|
124
|
-
# @param [Boolean] true prefix, for RFC2965, whether to prefix with
|
125
|
-
# "$Version=<version>;". Ignored for Netscape-style cookies
|
126
|
-
def to_s(ver = 0, prefix = true)
|
127
|
-
return "#{name}=#{value}" if ver == 0
|
128
|
-
|
129
|
-
# we do not need to encode path; the only characters required to be
|
130
|
-
# quoted must be escaped in URI
|
131
|
-
str = prefix ? "$Version=#{version};" : ''
|
132
|
-
str << "#{name}=#{value};$Path=\"#{path}\""
|
133
|
-
str << ";$Domain=#{domain}" if domain.start_with? '.'
|
134
|
-
str << ";$Port=\"#{ports.join ','}\"" if ports
|
135
|
-
str
|
136
|
-
end
|
137
|
-
|
138
|
-
# Return a hash representation of the cookie.
|
139
|
-
|
140
|
-
def to_hash
|
141
|
-
result = {
|
142
|
-
name: @name,
|
143
|
-
value: @value,
|
144
|
-
domain: @domain,
|
145
|
-
path: @path,
|
146
|
-
created_at: @created_at
|
147
|
-
}
|
148
|
-
{
|
149
|
-
expiry: @expiry,
|
150
|
-
secure: (true if @secure),
|
151
|
-
http_only: (true if @http_only),
|
152
|
-
version: (@version if version != 0),
|
153
|
-
comment: @comment,
|
154
|
-
comment_url: @comment_url,
|
155
|
-
discard: (true if @discard),
|
156
|
-
ports: @ports
|
157
|
-
}.each do |name, value|
|
158
|
-
result[name] = value if value
|
159
|
-
end
|
160
|
-
|
161
|
-
result
|
162
|
-
end
|
163
|
-
|
164
|
-
# Determine if a cookie should be sent given a request URI along with
|
165
|
-
# other options.
|
166
|
-
#
|
167
|
-
# This currently ignores domain.
|
168
|
-
#
|
169
|
-
# @param uri [String, URI] the requested page which may need to receive
|
170
|
-
# this cookie
|
171
|
-
# @param script [Boolean] indicates that cookies with the 'httponly'
|
172
|
-
# extension should be ignored
|
173
|
-
# @return [Boolean] whether this cookie should be sent to the server
|
174
|
-
def should_send?(request_uri, script)
|
175
|
-
uri = CookieJar::CookieValidation.to_uri request_uri
|
176
|
-
# cookie path must start with the uri, it must not be a secure cookie
|
177
|
-
# being sent over http, and it must not be a http_only cookie sent to
|
178
|
-
# a script
|
179
|
-
path = if uri.path == ''
|
180
|
-
'/'
|
181
|
-
else
|
182
|
-
uri.path
|
183
|
-
end
|
184
|
-
path_match = path.start_with? @path
|
185
|
-
secure_match = !(@secure && uri.scheme == 'http')
|
186
|
-
script_match = !(script && @http_only)
|
187
|
-
expiry_match = !expired?
|
188
|
-
ports_match = ports.nil? || (ports.include? uri.port)
|
189
|
-
path_match && secure_match && script_match && expiry_match && ports_match
|
190
|
-
end
|
191
|
-
|
192
|
-
def decoded_value
|
193
|
-
CookieJar::CookieValidation.decode_value value
|
194
|
-
end
|
195
|
-
|
196
|
-
# Return a JSON 'object' for the various data values. Allows for
|
197
|
-
# persistence of the cookie information
|
198
|
-
#
|
199
|
-
# @param [Array] a options controlling output JSON text
|
200
|
-
# (usually a State and a depth)
|
201
|
-
# @return [String] JSON representation of object data
|
202
|
-
def to_json(*a)
|
203
|
-
to_hash.merge(json_class: self.class.name).to_json(*a)
|
204
|
-
end
|
205
|
-
|
206
|
-
# Given a Hash representation of a JSON document, create a local cookie
|
207
|
-
# from the included data.
|
208
|
-
#
|
209
|
-
# @param [Hash] o JSON object of array data
|
210
|
-
# @return [Cookie] cookie formed from JSON data
|
211
|
-
def self.json_create(o)
|
212
|
-
params = o.inject({}) do |hash, (key, value)|
|
213
|
-
hash[key.to_sym] = value
|
214
|
-
hash
|
215
|
-
end
|
216
|
-
params[:version] ||= 0
|
217
|
-
params[:created_at] = Time.parse params[:created_at]
|
218
|
-
if params[:expiry].is_a? String
|
219
|
-
params[:expires_at] = Time.parse params[:expiry]
|
220
|
-
else
|
221
|
-
params[:max_age] = params[:expiry]
|
222
|
-
end
|
223
|
-
params.delete :expiry
|
224
|
-
|
225
|
-
new params
|
226
|
-
end
|
227
|
-
|
228
|
-
# Compute the cookie search domains for a given request URI
|
229
|
-
# This will be the effective host of the request uri, along with any
|
230
|
-
# possibly matching dot-prefixed domains
|
231
|
-
#
|
232
|
-
# @param request_uri [String, URI] address being requested
|
233
|
-
# @return [Array<String>] String domain matches
|
234
|
-
def self.compute_search_domains(request_uri)
|
235
|
-
CookieValidation.compute_search_domains request_uri
|
236
|
-
end
|
237
|
-
|
238
|
-
protected
|
239
|
-
|
240
|
-
# Call {from_set_cookie} to create a new Cookie instance
|
241
|
-
def initialize(args)
|
242
|
-
@created_at, @name, @value, @domain, @path, @secure,
|
243
|
-
@http_only, @version, @comment, @comment_url, @discard, @ports \
|
244
|
-
= args.values_at \
|
245
|
-
:created_at, :name, :value, :domain, :path, :secure,
|
246
|
-
:http_only, :version, :comment, :comment_url, :discard, :ports
|
247
|
-
|
248
|
-
@created_at ||= Time.now
|
249
|
-
@expiry = args[:max_age] || args[:expires_at]
|
250
|
-
@secure ||= false
|
251
|
-
@http_only ||= false
|
252
|
-
@discard ||= false
|
253
|
-
|
254
|
-
@ports = [@ports] if @ports.is_a? Integer
|
255
|
-
end
|
256
|
-
end
|
257
|
-
end
|