restify 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +3 -2
- data/lib/restify/context.rb +7 -6
- data/lib/restify/version.rb +1 -1
- data/spec/restify/context_spec.rb +5 -5
- data/spec/restify/features/request_headers_spec.rb +87 -0
- data/spec/spec_helper.rb +4 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c8ac98ab3e0dab023e3ab8d312e9c1e88a58dd13b05652097bc514a3c1e6d23
|
4
|
+
data.tar.gz: eaad6494cb221afc8a3ee4175da1c754fa4cc0ca69c5fa4e12af54162672ae7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a323d105962242cc5254373f7c6481956d04dbd3cc1baada59154bcc0256e44ddae3714f184c50d99632bd4f2ceff5e16c1d27fb826c5c07f0edbfaf7e19fc7
|
7
|
+
data.tar.gz: d215812e63850c400efe4339ec7ef6d770f844bf1990344a074c8811fe5c0868d92b432ad573f6ae0e2d716f48e191101c3321b889e6cf4d934bcd593fa245b0
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -20,7 +20,8 @@ The HTTP adapters are mostly run in a background thread and may not survive mid-
|
|
20
20
|
|
21
21
|
Included processors can handle:
|
22
22
|
|
23
|
-
* Plain JSON with GitHub-
|
23
|
+
* Plain JSON with GitHub-style relations
|
24
|
+
* MessagePack with GitHub-style relations *(currently experimental)*
|
24
25
|
|
25
26
|
(Beside HTTP Link header that's always supported)
|
26
27
|
|
@@ -31,7 +32,7 @@ Restify requires Ruby 2.0+.
|
|
31
32
|
* HTTP cache
|
32
33
|
* API versions via header
|
33
34
|
* Content-Type and Language negotiation
|
34
|
-
* Processors for
|
35
|
+
* Processors for JSON-HAL, etc.
|
35
36
|
|
36
37
|
## Installation
|
37
38
|
|
data/lib/restify/context.rb
CHANGED
@@ -48,12 +48,13 @@ module Restify
|
|
48
48
|
end
|
49
49
|
|
50
50
|
# rubocop:disable Metrics/MethodLength
|
51
|
-
def request(method, uri, data: nil, **kwargs)
|
52
|
-
request = Request.new(
|
51
|
+
def request(method, uri, data: nil, headers: {}, **kwargs)
|
52
|
+
request = Request.new(
|
53
|
+
headers: default_headers.merge(headers),
|
54
|
+
**kwargs,
|
53
55
|
method: method,
|
54
56
|
uri: join(uri),
|
55
|
-
data: data
|
56
|
-
headers: headers
|
57
|
+
data: data
|
57
58
|
)
|
58
59
|
|
59
60
|
ret = cache.call(request) {|req| adapter.call(req) }
|
@@ -77,7 +78,7 @@ module Restify
|
|
77
78
|
def marshal_dump
|
78
79
|
{
|
79
80
|
uri: uri.to_s,
|
80
|
-
headers:
|
81
|
+
headers: default_headers
|
81
82
|
}
|
82
83
|
end
|
83
84
|
|
@@ -96,7 +97,7 @@ module Restify
|
|
96
97
|
options[:cache] || Restify.cache
|
97
98
|
end
|
98
99
|
|
99
|
-
def
|
100
|
+
def default_headers
|
100
101
|
options.fetch(:headers, {})
|
101
102
|
end
|
102
103
|
|
data/lib/restify/version.rb
CHANGED
@@ -13,8 +13,8 @@ describe Restify::Context do
|
|
13
13
|
describe '#uri' do
|
14
14
|
subject { super().uri }
|
15
15
|
|
16
|
-
it {
|
17
|
-
it {
|
16
|
+
it { is_expected.to be_a Addressable::URI }
|
17
|
+
it { is_expected.to eq context.uri }
|
18
18
|
end
|
19
19
|
|
20
20
|
describe '#adapter' do
|
@@ -36,11 +36,11 @@ describe Restify::Context do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
describe '#headers' do
|
39
|
-
let(:kwargs) { {headers: {'Accept'
|
39
|
+
let(:kwargs) { {headers: {'Accept' => 'application/json'}} }
|
40
40
|
subject { super().options[:headers] }
|
41
41
|
|
42
|
-
it do
|
43
|
-
expect(subject).to eq
|
42
|
+
it 'all headers are serialized' do
|
43
|
+
expect(subject).to eq({'Accept' => 'application/json'})
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Restify do
|
6
|
+
let!(:request_stub) do
|
7
|
+
stub_request(:get, 'http://localhost/base').to_return do
|
8
|
+
<<-EOF.gsub(/^ {8}/, '')
|
9
|
+
HTTP/1.1 200 OK
|
10
|
+
Content-Type: application/json
|
11
|
+
Transfer-Encoding: chunked
|
12
|
+
Link: <http://localhost/base>; rel="self"
|
13
|
+
|
14
|
+
{ "response": "success" }
|
15
|
+
EOF
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with request headers configured for a single request' do
|
20
|
+
let(:context) { Restify.new('http://localhost/base') }
|
21
|
+
|
22
|
+
it 'sends the headers only for that request' do
|
23
|
+
root = context.get(
|
24
|
+
{},
|
25
|
+
headers: {'Accept' => 'application/msgpack, application/json'}
|
26
|
+
).value!
|
27
|
+
|
28
|
+
root.rel(:self).get.value!
|
29
|
+
|
30
|
+
expect(request_stub).to have_been_requested.twice
|
31
|
+
expect(
|
32
|
+
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'})
|
33
|
+
).to have_been_requested.once
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with request headers configured for context' do
|
38
|
+
let(:context) do
|
39
|
+
Restify.new(
|
40
|
+
'http://localhost/base',
|
41
|
+
headers: {'Accept' => 'application/msgpack, application/json'}
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'sends the headers with each request' do
|
46
|
+
root = context.get.value!
|
47
|
+
|
48
|
+
root.rel(:self).get.value!
|
49
|
+
|
50
|
+
expect(
|
51
|
+
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'})
|
52
|
+
).to have_been_requested.twice
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'can overwrite headers for single requests' do
|
56
|
+
root = context.get(
|
57
|
+
{},
|
58
|
+
headers: {'Accept' => 'application/xml'}
|
59
|
+
).value!
|
60
|
+
|
61
|
+
root.rel(:self).get.value!
|
62
|
+
|
63
|
+
expect(
|
64
|
+
request_stub.with(headers: {'Accept' => 'application/xml'})
|
65
|
+
).to have_been_requested.once
|
66
|
+
expect(
|
67
|
+
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'})
|
68
|
+
).to have_been_requested.once
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'can add additional headers for single requests' do
|
72
|
+
root = context.get(
|
73
|
+
{},
|
74
|
+
headers: {'X-Custom' => 'foobar'}
|
75
|
+
).value!
|
76
|
+
|
77
|
+
root.rel(:self).get.value!
|
78
|
+
|
79
|
+
expect(
|
80
|
+
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'})
|
81
|
+
).to have_been_requested.twice
|
82
|
+
expect(
|
83
|
+
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json', 'X-Custom' => 'foobar'})
|
84
|
+
).to have_been_requested.once
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -47,7 +47,9 @@ RSpec.configure do |config|
|
|
47
47
|
::Logging.logger.root.add_appenders ::Logging.appenders.stdout
|
48
48
|
end
|
49
49
|
|
50
|
-
config.after(:
|
51
|
-
|
50
|
+
config.after(:all) do
|
51
|
+
if defined?(EventMachine) && EventMachine.reactor_running?
|
52
|
+
EventMachine.stop
|
53
|
+
end
|
52
54
|
end
|
53
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -171,6 +171,7 @@ files:
|
|
171
171
|
- lib/restify/version.rb
|
172
172
|
- spec/restify/cache_spec.rb
|
173
173
|
- spec/restify/context_spec.rb
|
174
|
+
- spec/restify/features/request_headers_spec.rb
|
174
175
|
- spec/restify/global_spec.rb
|
175
176
|
- spec/restify/link_spec.rb
|
176
177
|
- spec/restify/processors/base_spec.rb
|
@@ -209,6 +210,7 @@ summary: An experimental hypermedia REST client.
|
|
209
210
|
test_files:
|
210
211
|
- spec/restify/cache_spec.rb
|
211
212
|
- spec/restify/context_spec.rb
|
213
|
+
- spec/restify/features/request_headers_spec.rb
|
212
214
|
- spec/restify/global_spec.rb
|
213
215
|
- spec/restify/link_spec.rb
|
214
216
|
- spec/restify/processors/base_spec.rb
|