faraday-cookie_jar 0.0.2 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6518c4004a5c37f4781930223b709a9331c28f09d78926a99caf6d6d2d7a7231
4
+ data.tar.gz: e07f34c4acfd740cad6668390a22b5a02fcae9ce70b15d7498b66a11ab1425ea
5
+ SHA512:
6
+ metadata.gz: 6397a74a2f902fbcaaffa2637aa14950f228d9154a6fc0fcdcdd6a843f39b285dec03cb2ab479d348b92ffe50c36bf101261725c0ed196f22425aa6eeec336f4
7
+ data.tar.gz: 5f81657bcc13538f3686041e90f77571a38f66a4d8893f630422bbd3d0c90c838673277ccd575bb371f1e0c5b0a4f14e82ca4ca0afdb448492241720121a5377
@@ -1,8 +1,31 @@
1
+ ## 0.0.7 Tue Sep 1 20:25:00 PDT 2020
2
+
3
+ - Avoid loading Faraday by assuming Faraday registry API (chesterbr)
4
+ - To support change above, require Faraday 0.8 as a minimum (chesterbr)
5
+
6
+ ## 0.0.6 Tue Jan 21 16:34:35 PST 2014
7
+
8
+ - Support Faraday 0.9 registry API (cameron-martin)
9
+ - Support specifying CookieJar in configuration (cameron-martin)
10
+
11
+ ## 0.0.5 Mon Jan 20 21:53:13 PST 2014
12
+
13
+ - Lock faraday dependency to < 0.9.0 for now
14
+ - Ability to add extra cookies in addition to the ones in Cookie Jar (nanjingboy)
15
+
16
+ ## 0.0.4 Mon Aug 12 23:11:46 PDT 2013
17
+
18
+ - Fix a crash when there's no valid response header #3
19
+
20
+ ## 0.0.3 Sun Apr 21 08:14:32 CST 2013
21
+
22
+ - Switch to http-cookie gem (knu) #2
23
+
1
24
  ## 0.0.2
2
25
 
3
26
  - Repackaging
4
- - Typo in README
27
+ - Typo in README (tmaesaka) #1
5
28
 
6
29
  ## 0.0.1
7
30
 
8
- - Initial release
31
+ - Initial release
data/README.md CHANGED
@@ -4,7 +4,7 @@ Faraday middleware to manage client-side cookies
4
4
 
5
5
  ## Description
6
6
 
7
- This gem is a piece of Faraday middleware that adds client-side Cookies management, using [cookiejar gem](https://github.com/dwaite/cookiejar).
7
+ This gem is a piece of Faraday middleware that adds client-side Cookies management, using [http-cookie gem](https://github.com/sparklemotion/http-cookie).
8
8
 
9
9
  ## Installation
10
10
 
@@ -27,6 +27,7 @@ require 'faraday-cookie_jar'
27
27
 
28
28
  conn = Faraday.new(:url => "http://example.com") do |builder|
29
29
  builder.use :cookie_jar
30
+ builder.adapter Faraday.default_adapter
30
31
  end
31
32
 
32
33
  conn.get "/foo" # gets cookie
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -18,12 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "faraday", ">= 0.7.4"
22
- spec.add_dependency "cookiejar"
21
+ spec.add_dependency "faraday", ">= 0.8.0"
22
+ spec.add_dependency "http-cookie", "~> 1.0.0"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
25
  spec.add_development_dependency "rake"
26
- spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "rspec", "~> 3.2"
27
27
  spec.add_development_dependency "sinatra"
28
28
  spec.add_development_dependency "sham_rack"
29
29
  end
@@ -1,26 +1,37 @@
1
1
  require "faraday"
2
- require "cookiejar"
2
+ require "http/cookie_jar"
3
3
 
4
4
  module Faraday
5
5
  class CookieJar < Faraday::Middleware
6
6
  def initialize(app, options = {})
7
7
  super(app)
8
- @jar = ::CookieJar::Jar.new
8
+ @jar = options[:jar] || HTTP::CookieJar.new
9
9
  end
10
10
 
11
11
  def call(env)
12
- cookie = @jar.get_cookie_header(env[:url])
13
- unless cookie.empty?
14
- env[:request_headers]["Cookie"] = cookie
12
+ cookies = @jar.cookies(env[:url])
13
+ unless cookies.empty?
14
+ cookie_value = HTTP::Cookie.cookie_value(cookies)
15
+ if env[:request_headers]["Cookie"]
16
+ unless env[:request_headers]["Cookie"] == cookie_value
17
+ env[:request_headers]["Cookie"] = cookie_value + ';' + env[:request_headers]["Cookie"]
18
+ end
19
+ else
20
+ env[:request_headers]["Cookie"] = cookie_value
21
+ end
15
22
  end
16
23
 
17
24
  @app.call(env).on_complete do |res|
18
- @jar.set_cookies_from_headers(env[:url], res[:response_headers])
25
+ if res[:response_headers]
26
+ if set_cookie = res[:response_headers]["Set-Cookie"]
27
+ @jar.parse(set_cookie, env[:url])
28
+ end
29
+ end
19
30
  end
20
31
  end
21
32
  end
22
33
  end
23
34
 
24
- if Faraday.respond_to? :register_middleware
25
- Faraday.register_middleware :cookie_jar => lambda { Faraday::CookieJar }
35
+ if Faraday::Middleware.respond_to? :register_middleware
36
+ Faraday::Middleware.register_middleware :cookie_jar => Faraday::CookieJar
26
37
  end
@@ -1,5 +1,5 @@
1
1
  module Faraday
2
2
  module CookieJarVersion
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Faraday::CookieJar do
4
4
  let(:conn) { Faraday.new(:url => 'http://faraday.example.com') }
5
+ let(:cookie_jar) { HTTP::CookieJar.new }
5
6
 
6
7
  before do
7
8
  conn.use :cookie_jar
@@ -10,19 +11,43 @@ describe Faraday::CookieJar do
10
11
 
11
12
  it 'get default cookie' do
12
13
  conn.get('/default')
13
- conn.get('/dump').body.should == 'foo=bar'
14
+ expect(conn.get('/dump').body).to eq('foo=bar')
14
15
  end
15
16
 
16
17
  it 'does not send cookies to wrong path' do
17
18
  conn.get('/path')
18
- conn.get('/dump').body.should_not == 'foo=bar'
19
+ expect(conn.get('/dump').body).to_not eq('foo=bar')
19
20
  end
20
21
 
21
22
  it 'expires cookie' do
22
23
  conn.get('/expires')
23
- conn.get('/dump').body.should == 'foo=bar'
24
+ expect(conn.get('/dump').body).to eq('foo=bar')
24
25
  sleep 2
25
- conn.get('/dump').body.should_not == 'foo=bar'
26
+ expect(conn.get('/dump').body).to_not eq('foo=bar')
27
+ end
28
+
29
+ it 'fills an injected cookie jar' do
30
+
31
+ conn_with_jar = Faraday.new(:url => 'http://faraday.example.com') do |conn|
32
+ conn.use :cookie_jar, jar: cookie_jar
33
+ conn.adapter :net_http # for sham_rock
34
+ end
35
+
36
+ conn_with_jar.get('/default')
37
+
38
+ expect(cookie_jar.empty?).to be false
39
+
40
+ end
41
+
42
+ it 'multiple cookies' do
43
+ conn.get('/default')
44
+
45
+ response = conn.send('get') do |request|
46
+ request.url '/multiple_cookies'
47
+ request.headers.merge!({:Cookie => 'language=english'})
48
+ end
49
+
50
+ expect(response.body).to eq('foo=bar;language=english')
26
51
  end
27
52
  end
28
53
 
@@ -16,4 +16,8 @@ class FakeApp < Sinatra::Application
16
16
  get '/expires' do
17
17
  response.set_cookie "foo", :value => "bar", :expires => Time.now + 1
18
18
  end
19
+
20
+ get '/multiple_cookies' do
21
+ "foo=#{request.cookies['foo']};language=#{request.cookies['language']}"
22
+ end
19
23
  end
metadata CHANGED
@@ -1,126 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday-cookie_jar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tatsuhiko Miyagawa
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-11 00:00:00.000000000 Z
11
+ date: 2020-09-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: faraday
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
- version: 0.7.4
19
+ version: 0.8.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: 0.7.4
26
+ version: 0.8.0
30
27
  - !ruby/object:Gem::Dependency
31
- name: cookiejar
28
+ name: http-cookie
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
- version: '0'
33
+ version: 1.0.0
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
- version: '0'
40
+ version: 1.0.0
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: bundler
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '1.3'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: '1.3'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rspec
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - "~>"
84
74
  - !ruby/object:Gem::Version
85
- version: '0'
75
+ version: '3.2'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - "~>"
92
81
  - !ruby/object:Gem::Version
93
- version: '0'
82
+ version: '3.2'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: sinatra
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - ">="
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: sham_rack
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - ">="
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - ">="
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  description: Cookie jar middleware for Faraday
@@ -130,7 +115,7 @@ executables: []
130
115
  extensions: []
131
116
  extra_rdoc_files: []
132
117
  files:
133
- - .gitignore
118
+ - ".gitignore"
134
119
  - CHANGELOG.md
135
120
  - Gemfile
136
121
  - LICENSE.txt
@@ -146,27 +131,25 @@ files:
146
131
  homepage: https://github.com/miyagawa/faraday-cookie_jar
147
132
  licenses:
148
133
  - MIT
134
+ metadata: {}
149
135
  post_install_message:
150
136
  rdoc_options: []
151
137
  require_paths:
152
138
  - lib
153
139
  required_ruby_version: !ruby/object:Gem::Requirement
154
- none: false
155
140
  requirements:
156
- - - ! '>='
141
+ - - ">="
157
142
  - !ruby/object:Gem::Version
158
143
  version: '0'
159
144
  required_rubygems_version: !ruby/object:Gem::Requirement
160
- none: false
161
145
  requirements:
162
- - - ! '>='
146
+ - - ">="
163
147
  - !ruby/object:Gem::Version
164
148
  version: '0'
165
149
  requirements: []
166
- rubyforge_project:
167
- rubygems_version: 1.8.23
150
+ rubygems_version: 3.0.3
168
151
  signing_key:
169
- specification_version: 3
152
+ specification_version: 4
170
153
  summary: Manages client-side cookie jar for Faraday HTTP client
171
154
  test_files:
172
155
  - spec/faraday-cookie_jar/cookie_jar_spec.rb