apill 3.1.2 → 3.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/apill/middleware/api_request.rb +6 -4
- data/lib/apill/version.rb +1 -1
- data/spec/apill/middleware/api_request_spec.rb +36 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4626664836143aaf78bf2b5b3484ba7da329a7d
|
4
|
+
data.tar.gz: 70758012561218a831754e3a6f85678f92da35c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4fe0941c2ce6d10a1cf60950bd4742a78a6cb3fd3f5a17701932b1b35ec95c177637eddcd9caf75a0ad19ff872252266dda004c028d7cc254d2d247bd3b7c50
|
7
|
+
data.tar.gz: d021d2ebc2314c817889df412c77fa2718433b4f314a6066a6a74b503620f8512e0e99f31c767d03fbfb7e4d83750f379391d09c1519df392d7efe2d156d5ef9
|
@@ -8,6 +8,8 @@ require 'apill/responses/invalid_subdomain_response'
|
|
8
8
|
module Apill
|
9
9
|
module Middleware
|
10
10
|
class ApiRequest
|
11
|
+
JSON_API_MIME_TYPE_PATTERN = %r{application/vnd\.api\+json(?=\z|;)}
|
12
|
+
|
11
13
|
def initialize(app)
|
12
14
|
@app = app
|
13
15
|
end
|
@@ -22,10 +24,10 @@ class ApiRequest
|
|
22
24
|
Matchers::AcceptHeaderMatcher.new.matches?(env)
|
23
25
|
|
24
26
|
env['QUERY_STRING'] = Parameters.process(env['QUERY_STRING'])
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
env['CONTENT_TYPE'] = env['CONTENT_TYPE'].
|
28
|
+
to_s.
|
29
|
+
gsub! JSON_API_MIME_TYPE_PATTERN,
|
30
|
+
'application/json'
|
29
31
|
|
30
32
|
@app.call(env)
|
31
33
|
else
|
data/lib/apill/version.rb
CHANGED
@@ -143,6 +143,42 @@ describe ApiRequest, singletons: HumanError::Configuration do
|
|
143
143
|
'nice_to_meet=you-bob&' \
|
144
144
|
'hows_the_weather=today-bob'
|
145
145
|
end
|
146
|
+
|
147
|
+
it 'properly converts the content type for Rails when it is the only one' do
|
148
|
+
api_request_middleware = ApiRequest.new(app)
|
149
|
+
|
150
|
+
request = {
|
151
|
+
'CONTENT_TYPE' => 'application/vnd.api+json',
|
152
|
+
'HTTP_HOST' => 'matrix.example.com',
|
153
|
+
'HTTP_ACCEPT' => '',
|
154
|
+
'QUERY_STRING' => '',
|
155
|
+
}
|
156
|
+
|
157
|
+
allow(app).to receive(:call)
|
158
|
+
|
159
|
+
_response = api_request_middleware.call(request)
|
160
|
+
|
161
|
+
expect(app).to have_received(:call).
|
162
|
+
with(a_hash_including('CONTENT_TYPE' => 'application/json'))
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'properly converts the content type for Rails when it is not the only one' do
|
166
|
+
api_request_middleware = ApiRequest.new(app)
|
167
|
+
|
168
|
+
request = {
|
169
|
+
'CONTENT_TYPE' => 'application/vnd.api+json;other',
|
170
|
+
'HTTP_HOST' => 'matrix.example.com',
|
171
|
+
'HTTP_ACCEPT' => '',
|
172
|
+
'QUERY_STRING' => '',
|
173
|
+
}
|
174
|
+
|
175
|
+
allow(app).to receive(:call)
|
176
|
+
|
177
|
+
_response = api_request_middleware.call(request)
|
178
|
+
|
179
|
+
expect(app).to have_received(:call).
|
180
|
+
with(a_hash_including('CONTENT_TYPE' => 'application/json;other'))
|
181
|
+
end
|
146
182
|
end
|
147
183
|
end
|
148
184
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jfelchner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: human_error
|
@@ -147,3 +147,4 @@ test_files:
|
|
147
147
|
- spec/apill/resource/processors/indexing_spec.rb
|
148
148
|
- spec/apill/resource/processors/paging_spec.rb
|
149
149
|
- spec/apill/resource/processors/sorting_spec.rb
|
150
|
+
has_rdoc:
|