http 0.8.9 → 0.8.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +2 -2
- data/lib/http/client.rb +10 -1
- data/lib/http/headers.rb +4 -1
- data/lib/http/options.rb +7 -3
- data/lib/http/version.rb +1 -1
- data/spec/lib/http_spec.rb +28 -0
- data/spec/support/dummy_server/servlet.rb +5 -0
- metadata +2 -3
- data/lib/http/options/cookies.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fca22402af79f980dc7e1b701e4d422daaf7fea8
|
4
|
+
data.tar.gz: 329410d55bbbedbb774496ed0c8f8c177c9d2f12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 769d422631b9551000a9e647736eeafdbf511f3bd5ed40e9efac847e5be69a72f77ef7cc87b6c83811599437f7ae6a1b39349730e6096a314abe433b146b744d
|
7
|
+
data.tar.gz: faefd914628653751aa3168442a0ade2032b809add4a2e9594c5494bb05160a5edf69f5b559668f5ea4077e0f6a74b3d33ca6669eab1c15e6069279773dee271
|
data/CHANGES.md
CHANGED
data/lib/http/client.rb
CHANGED
@@ -32,7 +32,7 @@ module HTTP
|
|
32
32
|
def request(verb, uri, opts = {})
|
33
33
|
opts = @default_options.merge(opts)
|
34
34
|
uri = make_request_uri(uri, opts)
|
35
|
-
headers =
|
35
|
+
headers = make_request_headers(opts)
|
36
36
|
body = make_request_body(opts, headers)
|
37
37
|
proxy = opts.proxy
|
38
38
|
|
@@ -145,6 +145,15 @@ module HTTP
|
|
145
145
|
uri
|
146
146
|
end
|
147
147
|
|
148
|
+
# Creates request headers with cookies (if any) merged in
|
149
|
+
def make_request_headers(opts)
|
150
|
+
cookies = opts.cookies.values
|
151
|
+
return opts.headers if cookies.empty?
|
152
|
+
|
153
|
+
cookies = opts.headers.get(Headers::COOKIE).concat(cookies).join("; ")
|
154
|
+
opts.headers.merge(Headers::COOKIE => cookies)
|
155
|
+
end
|
156
|
+
|
148
157
|
# Create the request body object to send
|
149
158
|
def make_request_body(opts, headers)
|
150
159
|
case
|
data/lib/http/headers.rb
CHANGED
@@ -16,9 +16,12 @@ module HTTP
|
|
16
16
|
# @see http://tools.ietf.org/html/rfc7230#section-3.2
|
17
17
|
HEADER_NAME_RE = /^[A-Za-z0-9!#\$%&'*+\-.^_`|~]+$/
|
18
18
|
|
19
|
-
#
|
19
|
+
# Set-Cookie (response) header name
|
20
20
|
SET_COOKIE = "Set-Cookie".freeze
|
21
21
|
|
22
|
+
# Cookie (request) header name
|
23
|
+
COOKIE = "Cookie".freeze
|
24
|
+
|
22
25
|
# Class constructor.
|
23
26
|
def initialize
|
24
27
|
@pile = []
|
data/lib/http/options.rb
CHANGED
@@ -65,6 +65,13 @@ module HTTP
|
|
65
65
|
self.headers.merge(headers)
|
66
66
|
end
|
67
67
|
|
68
|
+
def_option :cookies do |cookies|
|
69
|
+
cookies.each_with_object self.cookies.dup do |(k, v), jar|
|
70
|
+
cookie = k.is_a?(Cookie) ? k : Cookie.new(k.to_s, v.to_s)
|
71
|
+
jar[cookie.name] = cookie.cookie_value
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
68
75
|
%w(
|
69
76
|
proxy params form json body follow response
|
70
77
|
socket_class ssl_socket_class ssl_context ssl
|
@@ -145,6 +152,3 @@ module HTTP
|
|
145
152
|
end
|
146
153
|
end
|
147
154
|
end
|
148
|
-
|
149
|
-
# require cookies options
|
150
|
-
require "http/options/cookies"
|
data/lib/http/version.rb
CHANGED
data/spec/lib/http_spec.rb
CHANGED
@@ -292,4 +292,32 @@ RSpec.describe HTTP do
|
|
292
292
|
to raise_error(ArgumentError, /foobar/)
|
293
293
|
end
|
294
294
|
end
|
295
|
+
|
296
|
+
describe ".cookies" do
|
297
|
+
let(:endpoint) { "#{dummy.endpoint}/cookies" }
|
298
|
+
|
299
|
+
it "passes correct `Cookie` header" do
|
300
|
+
expect(HTTP.cookies(:abc => :def).get(endpoint).to_s).
|
301
|
+
to eq "abc: def"
|
302
|
+
end
|
303
|
+
|
304
|
+
it "properly works with cookie jars from response" do
|
305
|
+
res = HTTP.get(endpoint).flush
|
306
|
+
|
307
|
+
expect(HTTP.cookies(res.cookies).get(endpoint).to_s).
|
308
|
+
to eq "foo: bar"
|
309
|
+
end
|
310
|
+
|
311
|
+
it "properly merges cookies" do
|
312
|
+
res = HTTP.get(endpoint).flush
|
313
|
+
client = HTTP.cookies(:foo => 123, :bar => 321).cookies(res.cookies)
|
314
|
+
|
315
|
+
expect(client.get(endpoint).to_s).to eq "foo: bar\nbar: 321"
|
316
|
+
end
|
317
|
+
|
318
|
+
it "properly merges Cookie headers and cookies" do
|
319
|
+
client = HTTP.headers("Cookie" => "foo=bar").cookies(:baz => :moo)
|
320
|
+
expect(client.get(endpoint).to_s).to eq "foo: bar\nbaz: moo"
|
321
|
+
end
|
322
|
+
end
|
295
323
|
end
|
@@ -128,5 +128,10 @@ class DummyServer < WEBrick::HTTPServer
|
|
128
128
|
res["Content-Type"] = "application/octet-stream"
|
129
129
|
res.body = bytes.pack("c*")
|
130
130
|
end
|
131
|
+
|
132
|
+
get "/cookies" do |req, res|
|
133
|
+
res["Set-Cookie"] = "foo=bar"
|
134
|
+
res.body = req.cookies.map { |c| [c.name, c.value].join ": " }.join("\n")
|
135
|
+
end
|
131
136
|
end
|
132
137
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-05-
|
14
|
+
date: 2015-05-14 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: http_parser.rb
|
@@ -121,7 +121,6 @@ files:
|
|
121
121
|
- lib/http/mime_type/adapter.rb
|
122
122
|
- lib/http/mime_type/json.rb
|
123
123
|
- lib/http/options.rb
|
124
|
-
- lib/http/options/cookies.rb
|
125
124
|
- lib/http/redirector.rb
|
126
125
|
- lib/http/request.rb
|
127
126
|
- lib/http/request/caching.rb
|
data/lib/http/options/cookies.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module HTTP
|
2
|
-
class Options
|
3
|
-
# Default path of cookies
|
4
|
-
DEFAULT_COOKIE_PATH = "/".freeze
|
5
|
-
|
6
|
-
def_option :cookies do |cookies|
|
7
|
-
cookies.each_with_object self.cookies.dup do |(k, v), jar|
|
8
|
-
cookie = case
|
9
|
-
when k.is_a?(Cookie) then k
|
10
|
-
when k.is_a?(Hash) then Cookie.new k
|
11
|
-
when v.is_a?(Hash) then Cookie.new(k.to_s, v)
|
12
|
-
else Cookie.new(k.to_s, v.to_s)
|
13
|
-
end
|
14
|
-
|
15
|
-
cookie.path ||= DEFAULT_COOKIE_PATH
|
16
|
-
jar[cookie.name] = cookie.set_cookie_value
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|