cookiejar 0.3.2 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9e74c8690174e08cec5fa35868f2d91c4428b77d
4
- data.tar.gz: aab937a1668a87baa131e048b7fc8d3513bb9d47
2
+ SHA256:
3
+ metadata.gz: d08d63f0ec86285b96e7ee8ba926564aa526b10ae9cb77e25bcd9acb8779600e
4
+ data.tar.gz: 6a5c0d291baab26ef76ef25d12c95d31b6ca6f47ada89d67e5aed5fa70582003
5
5
  SHA512:
6
- metadata.gz: b84ac2103a3a7435082647d671ae43c2c41b523c09f6563c8f9946613ae00a61c4de70290f3af4b901736333106cf6066ab46fa0e3f4c5fc1b386873b7c9ab26
7
- data.tar.gz: fe140117a6960848e4b69697b7368d9ace9abec4edffeb4123c7aaa55392b666d9260097d11bee50bdbe0ff3b7ffbaeef26557925aacb9bd4b7110eee3b002a6
6
+ metadata.gz: 2c23451da58eaffb6b878aa9bd21083de306461a88ea2381cb710d10fcd5cd99ee1d4227a26690c2407acc96528e61ce591738f0ce997c358a00e24cea96df06
7
+ data.tar.gz: c5029ccd84b21567f16750a24aca4d4c99f7c0078548451756027012753f001e8c92a7bdb6d520429e7a0a865302ba797ba5fa64b4b723416d644e134f6a98c9
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .yardoc
2
+ *.*proj
3
+ pkg
4
+ doc
5
+ .bundle
6
+ .ruby-version
7
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ -w
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ rvm:
5
+ - 2.3.0
6
+ - 2.2.0
7
+ - 2.1.5
8
+ - 2.1.4
9
+ - 2.1.3
10
+ - 2.1.2
11
+ - 2.0.0
12
+ - jruby-19mode
13
+ - rbx
14
+ jdk:
15
+ - oraclejdk8
16
+
17
+ before_install: gem install bundler -v ">=1.9.3"
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 - 2014, David Waite and Other Contributors
1
+ Copyright (c) 2009 - 2018, David Waite and Other Contributors
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
data/README.markdown CHANGED
@@ -5,6 +5,13 @@ Ruby CookieJar
5
5
 
6
6
  **Author**: David Waite
7
7
 
8
+ [![Build Status](https://travis-ci.org/dwaite/cookiejar.svg?branch=master)](https://travis-ci.org/dwaite/cookiejar)
9
+
10
+ Status
11
+ ------
12
+
13
+ This project is no longer maintained. There may be other gems more appropriate for use which support newer versions of the cookie specifications, or more maintained forks of this gem such as [cookiejar2](https://github.com/dorianmariefr/cookiejar2).
14
+
8
15
  Synopsis
9
16
  --------
10
17
 
@@ -12,6 +19,18 @@ The Ruby CookieJar is a library to help manage client-side cookies in pure Ruby.
12
19
 
13
20
  Both Netscape/RFC 2109 cookies and RFC 2965 cookies are supported.
14
21
 
22
+ Roadmap
23
+ -------
24
+
25
+ For the Next major release, I would like to accomplish:
26
+
27
+ 1. Check against [RFC 6265 - HTTP State Management Mechanism][rfc6265], the latest cookie spec which came out after the initial release of cookiejar
28
+ 2. Determine better code structure to encourage alternate persistence mechanisms for cookie jars
29
+
30
+ [rfc6265]: http://tools.ietf.org/html/rfc6265
15
31
  COPYRIGHT
16
32
  ---------
17
- The Ruby CookieJar is Copyright © 2009 David Waite. Licensing terms are given within the LICENSE file.
33
+ 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].
34
+
35
+ [contributions]: ./contributors.json
36
+ [LICENSE]: ./LICENSE
data/Rakefile CHANGED
@@ -1,19 +1,15 @@
1
+ require 'bundler/gem_tasks'
2
+
1
3
  require 'rake'
2
4
 
3
5
  require 'rake/clean'
4
- require 'rake/packagetask'
5
6
  require 'yard'
6
7
  require 'yard/rake/yardoc_task'
7
8
 
8
- require 'fileutils'
9
- include FileUtils
10
-
11
- # Default Rake task is to run all tests
12
- task :default => :test
13
9
  CLEAN << Rake::FileList['doc/**', '.yardoc']
14
- #Yard
10
+ # Yard
15
11
  YARD::Rake::YardocTask.new do |t|
16
- t.files = ['lib/**/*.rb'] # optional
12
+ t.files = ['lib/**/*.rb'] # optional
17
13
  t.options = ['--title', 'CookieJar, a HTTP Client Cookie Parsing Library',
18
14
  '--main', 'README.markdown', '--files', 'LICENSE']
19
15
  end
@@ -22,10 +18,13 @@ begin
22
18
  require 'rspec/core/rake_task'
23
19
 
24
20
  RSpec::Core::RakeTask.new do |t|
25
- # t.libs << 'lib'
26
- # t.pattern = 'test/**/*_test.rb'
21
+ t.ruby_opts = %w(-w)
22
+ t.pattern = 'spec/**/*_spec.rb'
27
23
  end
28
- task :test => :spec
24
+ task test: :spec
29
25
  rescue LoadError
30
- puts "Warning: unable to load rspec tasks"
26
+ puts 'Warning: unable to load rspec tasks'
31
27
  end
28
+
29
+ # Default Rake task is to run all tests
30
+ task default: :test
data/_config.yml ADDED
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-tactile
data/cookiejar.gemspec ADDED
@@ -0,0 +1,28 @@
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 = 'cookiejar'
9
+ s.version = CookieJar::VERSION
10
+ s.authors = ['David Waite']
11
+ s.license = 'BSD-2-Clause'
12
+ s.email = ['david@alkaline-solutions.com']
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 = 'http://alkaline-solutions.com'
16
+ s.date = '2014-02-01'
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', '>= 10.0'
24
+ s.add_development_dependency 'rspec-collection_matchers', '~> 1.0'
25
+ s.add_development_dependency 'rspec', '~> 3.0'
26
+ s.add_development_dependency 'yard', '~> 0.9.20'
27
+ s.add_development_dependency 'bundler', '>= 0.9.3'
28
+ end
@@ -3,14 +3,12 @@ require 'uri'
3
3
  require 'cookiejar/cookie_validation'
4
4
 
5
5
  module CookieJar
6
-
7
6
  # Cookie is an immutable object which defines the data model of a HTTP Cookie.
8
7
  # The data values within the cookie may be different from the
9
8
  # values described in the literal cookie declaration.
10
9
  # Specifically, the 'domain' and 'path' values may be set to defaults
11
10
  # based on the requested resource that resulted in the cookie being set.
12
11
  class Cookie
13
-
14
12
  # [String] The name of the cookie.
15
13
  attr_reader :name
16
14
  # [String] The value of the cookie, without any attempts at decoding.
@@ -68,15 +66,15 @@ module CookieJar
68
66
  #
69
67
  # @param [Time] time to compare against, or 'now' if omitted
70
68
  # @return [Boolean]
71
- def expired? (time = Time.now)
72
- expires_at != nil && time > expires_at
69
+ def expired?(time = Time.now)
70
+ !expires_at.nil? && time > expires_at
73
71
  end
74
72
 
75
73
  # Indicates whether the cookie will be considered invalid after the end
76
74
  # of the current user session
77
75
  # @return [Boolean]
78
76
  def session?
79
- @expiry == nil || @discard
77
+ @expiry.nil? || @discard
80
78
  end
81
79
 
82
80
  # Create a cookie based on an absolute URI and the string value of a
@@ -88,12 +86,12 @@ module CookieJar
88
86
  # @param set_cookie_value [String] HTTP value for the Set-Cookie header.
89
87
  # @return [Cookie] created from the header string and request URI
90
88
  # @raise [InvalidCookieError] on validation failure(s)
91
- def self.from_set_cookie request_uri, set_cookie_value
89
+ def self.from_set_cookie(request_uri, set_cookie_value)
92
90
  args = CookieJar::CookieValidation.parse_set_cookie set_cookie_value
93
- args[:domain] = CookieJar::CookieValidation.
94
- determine_cookie_domain request_uri, args[:domain]
95
- args[:path] = CookieJar::CookieValidation.
96
- determine_cookie_path request_uri, args[:path]
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]
97
95
  cookie = Cookie.new args
98
96
  CookieJar::CookieValidation.validate_cookie request_uri, cookie
99
97
  cookie
@@ -108,12 +106,12 @@ module CookieJar
108
106
  # @param set_cookie_value [String] HTTP value for the Set-Cookie2 header.
109
107
  # @return [Cookie] created from the header string and request URI
110
108
  # @raise [InvalidCookieError] on validation failure(s)
111
- def self.from_set_cookie2 request_uri, set_cookie_value
109
+ def self.from_set_cookie2(request_uri, set_cookie_value)
112
110
  args = CookieJar::CookieValidation.parse_set_cookie2 set_cookie_value
113
- args[:domain] = CookieJar::CookieValidation.
114
- determine_cookie_domain request_uri, args[:domain]
115
- args[:path] = CookieJar::CookieValidation.
116
- determine_cookie_path request_uri, args[:path]
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]
117
115
  cookie = Cookie.new args
118
116
  CookieJar::CookieValidation.validate_cookie request_uri, cookie
119
117
  cookie
@@ -125,45 +123,37 @@ module CookieJar
125
123
  # RFC2965-style.
126
124
  # @param [Boolean] true prefix, for RFC2965, whether to prefix with
127
125
  # "$Version=<version>;". Ignored for Netscape-style cookies
128
- def to_s ver=0, prefix=true
129
- case ver
130
- when 0
131
- "#{name}=#{value}"
132
- when 1
133
- # we do not need to encode path; the only characters required to be
134
- # quoted must be escaped in URI
135
- str = prefix ? "$Version=#{version};" : ""
136
- str << "#{name}=#{value};$Path=\"#{path}\""
137
- if domain.start_with? '.'
138
- str << ";$Domain=#{domain}"
139
- end
140
- if ports
141
- str << ";$Port=\"#{ports.join ','}\""
142
- end
143
- str
144
- end
145
- end
126
+ def to_s(ver = 0, prefix = true)
127
+ return "#{name}=#{value}" if ver == 0
146
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
147
137
 
148
138
  # Return a hash representation of the cookie.
149
139
 
150
140
  def to_hash
151
141
  result = {
152
- :name => @name,
153
- :value => @value,
154
- :domain => @domain,
155
- :path => @path,
156
- :created_at => @created_at
142
+ name: @name,
143
+ value: @value,
144
+ domain: @domain,
145
+ path: @path,
146
+ created_at: @created_at
157
147
  }
158
148
  {
159
- :expiry => @expiry,
160
- :secure => (true if @secure),
161
- :http_only => (true if @http_only),
162
- :version => (@version if version != 0),
163
- :comment => @comment,
164
- :comment_url => @comment_url,
165
- :discard => (true if @discard),
166
- :ports => @ports
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
167
157
  }.each do |name, value|
168
158
  result[name] = value if value
169
159
  end
@@ -181,12 +171,17 @@ module CookieJar
181
171
  # @param script [Boolean] indicates that cookies with the 'httponly'
182
172
  # extension should be ignored
183
173
  # @return [Boolean] whether this cookie should be sent to the server
184
- def should_send? request_uri, script
174
+ def should_send?(request_uri, script)
185
175
  uri = CookieJar::CookieValidation.to_uri request_uri
186
176
  # cookie path must start with the uri, it must not be a secure cookie
187
177
  # being sent over http, and it must not be a http_only cookie sent to
188
178
  # a script
189
- path_match = uri.path.start_with? @path
179
+ path = if uri.path == ''
180
+ '/'
181
+ else
182
+ uri.path
183
+ end
184
+ path_match = path.start_with? @path
190
185
  secure_match = !(@secure && uri.scheme == 'http')
191
186
  script_match = !(script && @http_only)
192
187
  expiry_match = !expired?
@@ -195,7 +190,7 @@ module CookieJar
195
190
  end
196
191
 
197
192
  def decoded_value
198
- CookieJar::CookieValidation::decode_value value
193
+ CookieJar::CookieValidation.decode_value value
199
194
  end
200
195
 
201
196
  # Return a JSON 'object' for the various data values. Allows for
@@ -204,8 +199,8 @@ module CookieJar
204
199
  # @param [Array] a options controlling output JSON text
205
200
  # (usually a State and a depth)
206
201
  # @return [String] JSON representation of object data
207
- def to_json *a
208
- to_hash.merge(:json_class => self.class.name).to_json(*a)
202
+ def to_json(*a)
203
+ to_hash.merge(json_class: self.class.name).to_json(*a)
209
204
  end
210
205
 
211
206
  # Given a Hash representation of a JSON document, create a local cookie
@@ -213,7 +208,7 @@ module CookieJar
213
208
  #
214
209
  # @param [Hash] o JSON object of array data
215
210
  # @return [Cookie] cookie formed from JSON data
216
- def self.json_create o
211
+ def self.json_create(o)
217
212
  params = o.inject({}) do |hash, (key, value)|
218
213
  hash[key.to_sym] = value
219
214
  hash
@@ -227,7 +222,7 @@ module CookieJar
227
222
  end
228
223
  params.delete :expiry
229
224
 
230
- self.new params
225
+ new params
231
226
  end
232
227
 
233
228
  # Compute the cookie search domains for a given request URI
@@ -236,28 +231,27 @@ module CookieJar
236
231
  #
237
232
  # @param request_uri [String, URI] address being requested
238
233
  # @return [Array<String>] String domain matches
239
- def self.compute_search_domains request_uri
234
+ def self.compute_search_domains(request_uri)
240
235
  CookieValidation.compute_search_domains request_uri
241
236
  end
242
- protected
243
- # Call {from_set_cookie} to create a new Cookie instance
244
- def initialize args
245
237
 
238
+ protected
239
+
240
+ # Call {from_set_cookie} to create a new Cookie instance
241
+ def initialize(args)
246
242
  @created_at, @name, @value, @domain, @path, @secure,
247
243
  @http_only, @version, @comment, @comment_url, @discard, @ports \
248
244
  = args.values_at \
249
- :created_at, :name, :value, :domain, :path, :secure,
250
- :http_only, :version, :comment, :comment_url, :discard, :ports
245
+ :created_at, :name, :value, :domain, :path, :secure,
246
+ :http_only, :version, :comment, :comment_url, :discard, :ports
251
247
 
252
248
  @created_at ||= Time.now
253
- @expiry = args[:max_age] || args[:expires_at]
249
+ @expiry = args[:max_age] || args[:expires_at]
254
250
  @secure ||= false
255
251
  @http_only ||= false
256
252
  @discard ||= false
257
253
 
258
- if @ports.is_a? Integer
259
- @ports = [@ports]
260
- end
254
+ @ports = [@ports] if @ports.is_a? Integer
261
255
  end
262
256
  end
263
257
  end