httparty 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of httparty might be problematic. Click here for more details.

@@ -1,5 +1,5 @@
1
1
  module HTTParty
2
- class Response < BasicObject
2
+ class Response < Object
3
3
  def self.underscore(string)
4
4
  string.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z])([A-Z])/, '\1_\2').downcase
5
5
  end
@@ -25,16 +25,6 @@ module HTTParty
25
25
  @parsed_response ||= @parsed_block.call
26
26
  end
27
27
 
28
- def class
29
- Response
30
- end
31
-
32
- def is_a?(klass)
33
- self.class == klass || self.class < klass
34
- end
35
-
36
- alias_method :kind_of?, :is_a?
37
-
38
28
  def code
39
29
  response.code.to_i
40
30
  end
@@ -49,16 +39,12 @@ module HTTParty
49
39
  %(#<#{self.class}:0x#{inspect_id} parsed_response=#{parsed_response.inspect}, @response=#{response.inspect}, @headers=#{headers.inspect}>)
50
40
  end
51
41
 
52
- RESPOND_TO_METHODS = [:request, :response, :parsed_response, :body, :headers]
53
-
54
42
  CODES_TO_OBJ = ::Net::HTTPResponse::CODE_CLASS_TO_OBJ.merge ::Net::HTTPResponse::CODE_TO_OBJ
55
43
 
56
44
  CODES_TO_OBJ.each do |response_code, klass|
57
45
  name = klass.name.sub("Net::HTTP", '')
58
46
  name = "#{underscore(name)}?".to_sym
59
47
 
60
- RESPOND_TO_METHODS << name
61
-
62
48
  define_method(name) do
63
49
  klass === response
64
50
  end
@@ -69,11 +55,33 @@ module HTTParty
69
55
  alias_method :multiple_choice?, :multiple_choices?
70
56
  end
71
57
 
72
- def respond_to?(name, include_all = false)
73
- return true if RESPOND_TO_METHODS.include?(name)
74
- parsed_response.respond_to?(name, include_all) || response.respond_to?(name, include_all)
58
+ def nil?
59
+ response.nil? || response.body.nil? || response.body.empty?
75
60
  end
76
61
 
62
+ def to_s
63
+ if !response.nil? && !response.body.nil? && response.body.respond_to?(:to_s)
64
+ response.body.to_s
65
+ else
66
+ inspect
67
+ end
68
+ end
69
+
70
+ def display(port=$>)
71
+ if !parsed_response.nil? && parsed_response.respond_to?(:display)
72
+ parsed_response.display(port)
73
+ elsif !response.nil? && !response.body.nil? && response.body.respond_to?(:display)
74
+ response.body.display(port)
75
+ else
76
+ port.write(inspect)
77
+ end
78
+ end
79
+
80
+ def respond_to_missing?(name, *args)
81
+ return true if super
82
+ parsed_response.respond_to?(name) || response.respond_to?(name)
83
+ end
84
+
77
85
  protected
78
86
 
79
87
  def method_missing(name, *args, &block)
@@ -1,31 +1,31 @@
1
1
  module HTTParty
2
2
  class Response #:nodoc:
3
- class Headers
3
+ class Headers < ::SimpleDelegator
4
4
  include ::Net::HTTPHeader
5
5
 
6
- def initialize(header = {})
7
- @header = header
6
+ def initialize(header_values = nil)
7
+ @header = {}
8
+ if header_values
9
+ header_values.each_pair do |k,v|
10
+ if v.is_a?(Array)
11
+ v.each do |sub_v|
12
+ add_field(k, sub_v)
13
+ end
14
+ else
15
+ add_field(k, v)
16
+ end
17
+ end
18
+ end
19
+ super(@header)
8
20
  end
9
21
 
10
22
  def ==(other)
11
- @header == other
12
- end
13
-
14
- def inspect
15
- @header.inspect
16
- end
17
-
18
- def method_missing(name, *args, &block)
19
- if @header.respond_to?(name)
20
- @header.send(name, *args, &block)
21
- else
22
- super
23
+ if other.is_a?(::Net::HTTPHeader)
24
+ @header == other.instance_variable_get(:@header)
25
+ elsif other.is_a?(Hash)
26
+ @header == other || @header == Headers.new(other).instance_variable_get(:@header)
23
27
  end
24
28
  end
25
-
26
- def respond_to?(method, include_all = false)
27
- super || @header.respond_to?(method, include_all)
28
- end
29
29
  end
30
30
  end
31
31
  end
@@ -1,3 +1,3 @@
1
1
  module HTTParty
2
- VERSION = "0.14.0"
2
+ VERSION = "0.15.0"
3
3
  end
@@ -17,6 +17,34 @@ RSpec.describe Net::HTTPHeader::DigestAuthenticator do
17
17
  @digest.cookie_header
18
18
  end
19
19
 
20
+ context 'Net::HTTPHeader#digest_auth' do
21
+ let(:headers) {
22
+ (Class.new do
23
+ include Net::HTTPHeader
24
+ def initialize
25
+ @header = {}
26
+ end
27
+ end).new
28
+ }
29
+
30
+ let(:response){
31
+ (Class.new do
32
+ include Net::HTTPHeader
33
+ def initialize
34
+ @header = {}
35
+ self['WWW-Authenticate'] =
36
+ 'Digest realm="testrealm@host.com", qop="auth,auth-int", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41"'
37
+ end
38
+ end).new
39
+ }
40
+
41
+ it 'should set the authorization header' do
42
+ expect(headers['authorization']).to be_nil
43
+ headers.digest_auth('user','pass', response)
44
+ expect(headers['authorization']).to_not be_empty
45
+ end
46
+ end
47
+
20
48
  context "with a cookie value in the response header" do
21
49
  before do
22
50
  @digest = setup_digest({
@@ -103,6 +103,11 @@ RSpec.describe HTTParty::Parser do
103
103
  allow(@parser).to receive_messages(supports_format?: false)
104
104
  expect(@parser.parse).to_not be_nil
105
105
  end
106
+
107
+ it "ignores utf-8 bom" do
108
+ allow(@parser).to receive_messages(body: "\xEF\xBB\xBF\{\"hi\":\"yo\"\}")
109
+ expect(@parser.parse).to eq({"hi"=>"yo"})
110
+ end
106
111
  end
107
112
 
108
113
  describe "#supports_format?" do
@@ -33,6 +33,34 @@ RSpec.describe HTTParty::Request do
33
33
  end
34
34
  end
35
35
 
36
+ describe "::JSON_API_QUERY_STRING_NORMALIZER" do
37
+ let(:normalizer) { HTTParty::Request::JSON_API_QUERY_STRING_NORMALIZER }
38
+
39
+ it "doesn't modify strings" do
40
+ query_string = normalizer["foo=bar&foo=baz"]
41
+ expect(CGI.unescape(query_string)).to eq("foo=bar&foo=baz")
42
+ end
43
+
44
+ context "when the query is an array" do
45
+ it "doesn't include brackets" do
46
+ query_string = normalizer[{page: 1, foo: %w(bar baz)}]
47
+ expect(CGI.unescape(query_string)).to eq("foo=bar,baz&page=1")
48
+ end
49
+
50
+ it "URI encodes array values" do
51
+ query_string = normalizer[{people: ["Otis Redding", "Bob Marley", "Tim & Jon"], page: 1, xyzzy: 3}]
52
+ expect(query_string).to eq("page=1&people=Otis%20Redding,Bob%20Marley,Tim%20%26%20Jon&xyzzy=3")
53
+ end
54
+ end
55
+
56
+ context "when the query is a hash" do
57
+ it "correctly handles nil values" do
58
+ query_string = normalizer[{page: 1, per_page: nil}]
59
+ expect(query_string).to eq('page=1&per_page')
60
+ end
61
+ end
62
+ end
63
+
36
64
  describe "initialization" do
37
65
  it "sets parser to HTTParty::Parser" do
38
66
  request = HTTParty::Request.new(Net::HTTP::Get, 'http://google.com')
@@ -129,55 +157,82 @@ RSpec.describe HTTParty::Request do
129
157
  expect(@request.instance_variable_get(:@raw_request)['authorization']).not_to be_nil
130
158
  end
131
159
 
132
- it "should use digest auth when configured" do
133
- FakeWeb.register_uri(:get, "http://api.foo.com/v1",
134
- www_authenticate: 'Digest realm="Log Viewer", qop="auth", nonce="2CA0EC6B0E126C4800E56BA0C0003D3C", opaque="5ccc069c403ebaf9f0171e9517f40e41", stale=false')
135
-
136
- @request.options[:digest_auth] = {username: 'foobar', password: 'secret'}
137
- @request.send(:setup_raw_request)
138
-
139
- raw_request = @request.instance_variable_get(:@raw_request)
140
- expect(raw_request.instance_variable_get(:@header)['Authorization']).not_to be_nil
141
- end
142
-
143
- it "should use the right http method for digest authentication" do
144
- @post_request = HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', format: :xml)
145
- FakeWeb.register_uri(:post, "http://api.foo.com/v1", {})
146
-
147
- http = @post_request.send(:http)
148
- expect(@post_request).to receive(:http).and_return(http)
149
- expect(http).not_to receive(:head).with({'www-authenticate' => nil})
150
- @post_request.options[:digest_auth] = {username: 'foobar', password: 'secret'}
151
- @post_request.send(:setup_raw_request)
152
- end
153
-
154
- it 'should maintain cookies returned from setup_digest_auth' do
155
- FakeWeb.register_uri(
156
- :get, "http://api.foo.com/v1",
157
- set_cookie: 'custom-cookie=1234567',
158
- www_authenticate: 'Digest realm="Log Viewer", qop="auth", nonce="2CA0EC6B0E126C4800E56BA0C0003D3C", opaque="5ccc069c403ebaf9f0171e9517f40e41", stale=false'
159
- )
160
-
161
- @request.options[:digest_auth] = {username: 'foobar', password: 'secret'}
162
- @request.send(:setup_raw_request)
163
-
164
- raw_request = @request.instance_variable_get(:@raw_request)
165
- expect(raw_request.instance_variable_get(:@header)['cookie']).to eql ["custom-cookie=1234567"]
166
- end
167
-
168
- it 'should merge cookies from setup_digest_auth and request' do
169
- FakeWeb.register_uri(
170
- :get, "http://api.foo.com/v1",
171
- set_cookie: 'custom-cookie=1234567',
172
- www_authenticate: 'Digest realm="Log Viewer", qop="auth", nonce="2CA0EC6B0E126C4800E56BA0C0003D3C", opaque="5ccc069c403ebaf9f0171e9517f40e41", stale=false'
173
- )
174
-
175
- @request.options[:digest_auth] = {username: 'foobar', password: 'secret'}
176
- @request.options[:headers] = {'cookie' => 'request-cookie=test'}
177
- @request.send(:setup_raw_request)
178
-
179
- raw_request = @request.instance_variable_get(:@raw_request)
180
- expect(raw_request.instance_variable_get(:@header)['cookie']).to eql ['request-cookie=test', 'custom-cookie=1234567']
160
+ context 'digest_auth' do
161
+ before do
162
+ response_sequence = [
163
+ {status: ['401', 'Unauthorized' ],
164
+ www_authenticate: 'Digest realm="Log Viewer", qop="auth", nonce="2CA0EC6B0E126C4800E56BA0C0003D3C", opaque="5ccc069c403ebaf9f0171e9517f40e41", stale=false',
165
+ set_cookie: 'custom-cookie=1234567',
166
+ },
167
+ {status: ['200', 'OK']}
168
+ ]
169
+ FakeWeb.register_uri(:get, "http://api.foo.com/v1",
170
+ response_sequence)
171
+ end
172
+
173
+ it 'should not send credentials more than once' do
174
+ response_sequence = [
175
+ {status: ['401', 'Unauthorized' ],
176
+ www_authenticate: 'Digest realm="Log Viewer", qop="auth", nonce="2CA0EC6B0E126C4800E56BA0C0003D3C", opaque="5ccc069c403ebaf9f0171e9517f40e41", stale=false',
177
+ set_cookie: 'custom-cookie=1234567',
178
+ },
179
+ {status: ['401', 'Unauthorized' ],
180
+ www_authenticate: 'Digest realm="Log Viewer", qop="auth", nonce="2CA0EC6B0E126C4800E56BA0C0003D3C", opaque="5ccc069c403ebaf9f0171e9517f40e41", stale=false',
181
+ set_cookie: 'custom-cookie=1234567',
182
+ },
183
+ {status: ['404', 'Not found']}
184
+ ]
185
+ FakeWeb.register_uri(:get, "http://api.foo.com/v1",
186
+ response_sequence)
187
+
188
+ @request.options[:digest_auth] = {username: 'foobar', password: 'secret'}
189
+ response = @request.perform { |v| }
190
+ expect(response.code).to eq(401)
191
+
192
+ raw_request = @request.instance_variable_get(:@raw_request)
193
+ expect(raw_request['Authorization']).not_to be_nil
194
+ end
195
+
196
+ it 'should not be used when configured and the response is 200' do
197
+ FakeWeb.register_uri(:get, "http://api.foo.com/v1",
198
+ status: 200)
199
+ @request.options[:digest_auth] = {username: 'foobar', password: 'secret'}
200
+ response = @request.perform { |v| }
201
+ expect(response.code).to eq(200)
202
+
203
+
204
+ raw_request = @request.instance_variable_get(:@raw_request)
205
+ expect(raw_request['Authorization']).to be_nil
206
+ end
207
+
208
+ it "should be used when configured and the response is 401" do
209
+ @request.options[:digest_auth] = {username: 'foobar', password: 'secret'}
210
+ response = @request.perform { |v| }
211
+ expect(response.code).to eq(200)
212
+
213
+ raw_request = @request.instance_variable_get(:@raw_request)
214
+ expect(raw_request['Authorization']).not_to be_nil
215
+ end
216
+
217
+ it 'should maintain cookies returned from a 401 response' do
218
+ @request.options[:digest_auth] = {username: 'foobar', password: 'secret'}
219
+ response = @request.perform {|v|}
220
+ expect(response.code).to eq(200)
221
+
222
+ raw_request = @request.instance_variable_get(:@raw_request)
223
+ expect(raw_request.get_fields('cookie')).to eql ["custom-cookie=1234567"]
224
+ end
225
+
226
+ it 'should merge cookies from request and a 401 response' do
227
+
228
+ @request.options[:digest_auth] = {username: 'foobar', password: 'secret'}
229
+ @request.options[:headers] = {'cookie' => 'request-cookie=test'}
230
+ response = @request.perform {|v|}
231
+ expect(response.code).to eq(200)
232
+
233
+ raw_request = @request.instance_variable_get(:@raw_request)
234
+ expect(raw_request.get_fields('cookie')).to eql ['request-cookie=test', 'custom-cookie=1234567']
235
+ end
181
236
  end
182
237
 
183
238
  it 'should use body_stream when configured' do
@@ -230,6 +285,14 @@ RSpec.describe HTTParty::Request do
230
285
 
231
286
  expect(@request.uri).to eq(URI.parse("http://example.com/bar?foo=bar"))
232
287
  end
288
+
289
+ it "returns correct path when the server sets the location header to a network-path reference" do
290
+ @request.last_uri = URI.parse("https://example.com")
291
+ @request.path = URI.parse("//www.example.com")
292
+ @request.redirect = true
293
+
294
+ expect(@request.uri).to eq(URI.parse("https://www.example.com"))
295
+ end
233
296
  end
234
297
 
235
298
  context "query strings" do
@@ -360,6 +423,12 @@ RSpec.describe HTTParty::Request do
360
423
  expect(@request.send(:parse_response, xml)).to eq({'books' => {'book' => {'id' => '1234', 'name' => 'Foo Bar!'}}})
361
424
  end
362
425
 
426
+ it 'should handle utf-8 bom in xml' do
427
+ xml = "\xEF\xBB\xBF<books><book><id>1234</id><name>Foo Bar!</name></book></books>"
428
+ @request.options[:format] = :xml
429
+ expect(@request.send(:parse_response, xml)).to eq({'books' => {'book' => {'id' => '1234', 'name' => 'Foo Bar!'}}})
430
+ end
431
+
363
432
  it 'should handle csv automatically' do
364
433
  csv = ['"id","Name"', '"1234","Foo Bar!"'].join("\n")
365
434
  @request.options[:format] = :csv
@@ -372,6 +441,12 @@ RSpec.describe HTTParty::Request do
372
441
  expect(@request.send(:parse_response, json)).to eq({'books' => {'book' => {'id' => '1234', 'name' => 'Foo Bar!'}}})
373
442
  end
374
443
 
444
+ it 'should handle utf-8 bom in json' do
445
+ json = "\xEF\xBB\xBF{\"books\": {\"book\": {\"name\": \"Foo Bar!\", \"id\": \"1234\"}}}"
446
+ @request.options[:format] = :json
447
+ expect(@request.send(:parse_response, json)).to eq({'books' => {'book' => {'id' => '1234', 'name' => 'Foo Bar!'}}})
448
+ end
449
+
375
450
  it "should include any HTTP headers in the returned response" do
376
451
  @request.options[:format] = :html
377
452
  response = stub_response "Content"
@@ -382,10 +457,15 @@ RSpec.describe HTTParty::Request do
382
457
 
383
458
  if "".respond_to?(:encoding)
384
459
 
460
+ let(:response_charset) {
461
+ @request.send(:get_charset)
462
+ }
463
+
385
464
  it "should process charset in content type properly" do
386
465
  response = stub_response "Content"
387
466
  response.initialize_http_header("Content-Type" => "text/plain;charset = utf-8")
388
467
  resp = @request.perform
468
+ expect(response_charset).to_not be_empty
389
469
  expect(resp.body.encoding).to eq(Encoding.find("UTF-8"))
390
470
  end
391
471
 
@@ -393,6 +473,7 @@ RSpec.describe HTTParty::Request do
393
473
  response = stub_response "Content"
394
474
  response.initialize_http_header("Content-Type" => "text/plain;CHARSET = utf-8")
395
475
  resp = @request.perform
476
+ expect(response_charset).to_not be_empty
396
477
  expect(resp.body.encoding).to eq(Encoding.find("UTF-8"))
397
478
  end
398
479
 
@@ -400,6 +481,7 @@ RSpec.describe HTTParty::Request do
400
481
  response = stub_response "Content"
401
482
  response.initialize_http_header("Content-Type" => "text/plain;charset = \"utf-8\"")
402
483
  resp = @request.perform
484
+ expect(response_charset).to_not be_empty
403
485
  expect(resp.body.encoding).to eq(Encoding.find("UTF-8"))
404
486
  end
405
487
 
@@ -409,6 +491,7 @@ RSpec.describe HTTParty::Request do
409
491
  response = stub_response "\xFF\xFEC\x00o\x00n\x00t\x00e\x00n\x00t\x00"
410
492
  response.initialize_http_header("Content-Type" => "text/plain;charset = utf-16")
411
493
  resp = @request.perform
494
+ expect(response_charset).to_not be_empty
412
495
  expect(resp.body.encoding).to eq(Encoding.find("UTF-16LE"))
413
496
  end
414
497
 
@@ -418,6 +501,7 @@ RSpec.describe HTTParty::Request do
418
501
  response = stub_response "\xFE\xFF\x00C\x00o\x00n\x00t\x00e\x00n\x00t"
419
502
  response.initialize_http_header("Content-Type" => "text/plain;charset = utf-16")
420
503
  resp = @request.perform
504
+ expect(response_charset).to_not be_empty
421
505
  expect(resp.body.encoding).to eq(Encoding.find("UTF-16BE"))
422
506
  end
423
507
 
@@ -427,6 +511,7 @@ RSpec.describe HTTParty::Request do
427
511
  response = stub_response "C\x00o\x00n\x00t\x00e\x00n\x00t\x00"
428
512
  response.initialize_http_header("Content-Type" => "text/plain;charset = utf-16")
429
513
  resp = @request.perform
514
+ expect(response_charset).to_not be_empty
430
515
  expect(resp.body.encoding).to eq(Encoding.find("UTF-16LE"))
431
516
  end
432
517
 
@@ -434,6 +519,9 @@ RSpec.describe HTTParty::Request do
434
519
  response = stub_response "Content"
435
520
  response.initialize_http_header("Content-Type" => "text/plain;charset = utf-lols")
436
521
  resp = @request.perform
522
+ expect(response_charset).to_not be_empty
523
+ # This encoding does not exist, thus the string should not be encodd with it
524
+ expect(resp.body.encoding).to_not eq(response_charset)
437
525
  expect(resp.body).to eq("Content")
438
526
  expect(resp.body.encoding).to eq("Content".encoding)
439
527
  end
@@ -442,6 +530,7 @@ RSpec.describe HTTParty::Request do
442
530
  response = stub_response "Content"
443
531
  response.initialize_http_header("Content-Type" => "text/plain")
444
532
  resp = @request.perform
533
+ expect(response_charset).to be_nil
445
534
  expect(resp.body).to eq("Content")
446
535
  expect(resp.body.encoding).to eq("Content".encoding)
447
536
  end
@@ -1037,54 +1126,6 @@ RSpec.describe HTTParty::Request do
1037
1126
  end
1038
1127
  end
1039
1128
 
1040
- describe "#handle_deflation" do
1041
- context "context-encoding" do
1042
- before do
1043
- @request.options[:format] = :html
1044
- @last_response = double
1045
- allow(@last_response).to receive(:body).and_return('')
1046
- end
1047
-
1048
- it "should inflate the gzipped body with content-encoding: gzip" do
1049
- allow(@last_response).to receive(:[]).with("content-encoding").and_return("gzip")
1050
- allow(@request).to receive(:last_response).and_return(@last_response)
1051
- expect(Zlib::GzipReader).to receive(:new).and_return(StringIO.new(''))
1052
- expect(@request.last_response).to receive(:delete).with('content-encoding')
1053
- @request.send(:handle_deflation)
1054
- end
1055
-
1056
- it "should inflate the gzipped body with content-encoding: x-gzip" do
1057
- allow(@last_response).to receive(:[]).with("content-encoding").and_return("x-gzip")
1058
- allow(@request).to receive(:last_response).and_return(@last_response)
1059
- expect(Zlib::GzipReader).to receive(:new).and_return(StringIO.new(''))
1060
- expect(@request.last_response).to receive(:delete).with('content-encoding')
1061
- @request.send(:handle_deflation)
1062
- end
1063
-
1064
- it "should inflate the deflated body" do
1065
- allow(@last_response).to receive(:[]).with("content-encoding").and_return("deflate")
1066
- allow(@request).to receive(:last_response).and_return(@last_response)
1067
- expect(Zlib::Inflate).to receive(:inflate).and_return('')
1068
- expect(@request.last_response).to receive(:delete).with('content-encoding')
1069
- @request.send(:handle_deflation)
1070
- end
1071
-
1072
- it "should not inflate a redirected response with content-encoding: gzip" do
1073
- allow(@last_response).to receive(:[]).with("content-encoding").and_return("gzip")
1074
- allow(@request).to receive(:last_response).and_return(@last_response)
1075
- allow(@request).to receive(:response_redirects?).and_return(true)
1076
- @request.send(:handle_deflation)
1077
- end
1078
-
1079
- it "should not inflate a redirected response with content-encoding: deflate" do
1080
- allow(@last_response).to receive(:[]).with("content-encoding").and_return("deflate")
1081
- allow(@request).to receive(:last_response).and_return(@last_response)
1082
- allow(@request).to receive(:response_redirects?).and_return(true)
1083
- @request.send(:handle_deflation)
1084
- end
1085
- end
1086
- end
1087
-
1088
1129
  describe "#send_authorization_header?" do
1089
1130
  context "basic_auth" do
1090
1131
  before do
@@ -1180,4 +1221,24 @@ RSpec.describe HTTParty::Request do
1180
1221
  }.to raise_error(HTTParty::RedirectionTooDeep, 'HTTP redirects too deep')
1181
1222
  end
1182
1223
  end
1224
+
1225
+ context 'with Accept-Encoding header' do
1226
+ it 'should disable content decoding if present' do
1227
+ request = HTTParty::Request.new(Net::HTTP::Get, 'http://api.foo.com/v1', headers:{'Accept-Encoding' => 'custom'})
1228
+ request.send(:setup_raw_request)
1229
+ expect(request.instance_variable_get(:@raw_request).decode_content).to eq(false)
1230
+ end
1231
+
1232
+ it 'should disable content decoding if present and lowercase' do
1233
+ request = HTTParty::Request.new(Net::HTTP::Get, 'http://api.foo.com/v1', headers:{'accept-encoding' => 'custom'})
1234
+ request.send(:setup_raw_request)
1235
+ expect(request.instance_variable_get(:@raw_request).decode_content).to eq(false)
1236
+ end
1237
+
1238
+ it 'should disable content decoding if present' do
1239
+ request = HTTParty::Request.new(Net::HTTP::Get, 'http://api.foo.com/v1')
1240
+ request.send(:setup_raw_request)
1241
+ expect(request.instance_variable_get(:@raw_request).decode_content).to eq(true)
1242
+ end
1243
+ end
1183
1244
  end