httparty 0.16.4 → 0.17.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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Changelog.md +6 -0
- data/Gemfile +4 -0
- data/docs/README.md +2 -2
- data/examples/README.md +3 -0
- data/examples/peer_cert.rb +9 -0
- data/lib/httparty.rb +29 -9
- data/lib/httparty/connection_adapter.rb +28 -9
- data/lib/httparty/request.rb +14 -71
- data/lib/httparty/response.rb +4 -0
- data/lib/httparty/{fragment_with_response.rb → response_fragment.rb} +4 -5
- data/lib/httparty/text_encoder.rb +70 -0
- data/lib/httparty/version.rb +1 -1
- data/spec/fixtures/ssl/generate.sh +3 -3
- data/spec/fixtures/ssl/generated/bogushost.crt +27 -11
- data/spec/fixtures/ssl/generated/ca.crt +29 -14
- data/spec/fixtures/ssl/generated/ca.key +52 -15
- data/spec/fixtures/ssl/generated/selfsigned.crt +27 -12
- data/spec/fixtures/ssl/generated/server.crt +28 -11
- data/spec/fixtures/ssl/generated/server.key +52 -15
- data/spec/httparty/connection_adapter_spec.rb +128 -2
- data/spec/httparty/request_spec.rb +57 -35
- data/spec/httparty/{fragment_with_response_spec.rb → response_fragment_spec.rb} +6 -3
- data/spec/httparty/response_spec.rb +7 -1
- data/spec/httparty/ssl_spec.rb +10 -2
- data/spec/httparty_spec.rb +20 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/ssl_test_helper.rb +4 -4
- data/spec/support/stub_response.rb +1 -0
- metadata +7 -5
@@ -505,50 +505,72 @@ RSpec.describe HTTParty::Request do
|
|
505
505
|
end
|
506
506
|
|
507
507
|
if "".respond_to?(:encoding)
|
508
|
+
context 'when body has ascii-8bit encoding' do
|
509
|
+
let(:response) { stub_response "Content".force_encoding('ascii-8bit') }
|
508
510
|
|
509
|
-
|
510
|
-
|
511
|
-
|
511
|
+
it "processes charset in content type properly" do
|
512
|
+
response.initialize_http_header("Content-Type" => "text/plain;charset = utf-8")
|
513
|
+
resp = @request.perform
|
512
514
|
|
513
|
-
|
514
|
-
|
515
|
-
response.initialize_http_header("Content-Type" => "text/plain;charset = utf-8")
|
516
|
-
resp = @request.perform
|
517
|
-
expect(response_charset).to_not be_empty
|
518
|
-
expect(resp.body.encoding).to eq(Encoding.find("UTF-8"))
|
519
|
-
end
|
515
|
+
expect(resp.body.encoding).to eq(Encoding.find("UTF-8"))
|
516
|
+
end
|
520
517
|
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
resp = @request.perform
|
525
|
-
expect(response_charset).to_not be_empty
|
526
|
-
expect(resp.body.encoding).to eq(Encoding.find("UTF-8"))
|
527
|
-
end
|
518
|
+
it "processes charset in content type properly if it has a different case" do
|
519
|
+
response.initialize_http_header("Content-Type" => "text/plain;CHARSET = utf-8")
|
520
|
+
resp = @request.perform
|
528
521
|
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
522
|
+
expect(resp.body.encoding).to eq(Encoding.find("UTF-8"))
|
523
|
+
end
|
524
|
+
|
525
|
+
it "processes quoted charset in content type properly" do
|
526
|
+
response.initialize_http_header("Content-Type" => "text/plain;charset = \"utf-8\"")
|
527
|
+
resp = @request.perform
|
528
|
+
|
529
|
+
expect(resp.body.encoding).to eq(Encoding.find("UTF-8"))
|
530
|
+
end
|
531
|
+
|
532
|
+
context 'when stubed body is frozen' do
|
533
|
+
let(:response) do
|
534
|
+
stub_response "Content".force_encoding('ascii-8bit').freeze
|
535
|
+
end
|
536
|
+
|
537
|
+
it 'processes frozen body correctly' do
|
538
|
+
response.initialize_http_header("Content-Type" => "text/plain;charset = utf-8")
|
539
|
+
resp = @request.perform
|
540
|
+
|
541
|
+
expect(resp.body.encoding).to eq(Encoding.find("UTF-8"))
|
542
|
+
end
|
543
|
+
end
|
535
544
|
end
|
536
545
|
|
537
546
|
it "should process response with a nil body" do
|
538
547
|
response = stub_response nil
|
539
548
|
response.initialize_http_header("Content-Type" => "text/html;charset=UTF-8")
|
540
549
|
resp = @request.perform
|
550
|
+
|
541
551
|
expect(resp.body).to be_nil
|
542
552
|
end
|
543
553
|
|
544
|
-
|
545
|
-
@request.options[:assume_utf16_is_big_endian] = true
|
554
|
+
context 'when assume_utf16_is_big_endian is true' do
|
555
|
+
before { @request.options[:assume_utf16_is_big_endian] = true }
|
546
556
|
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
557
|
+
it "should process utf-16 charset with little endian bom correctly" do
|
558
|
+
response = stub_response "\xFF\xFEC\x00o\x00n\x00t\x00e\x00n\x00t\x00"
|
559
|
+
|
560
|
+
response.initialize_http_header("Content-Type" => "text/plain;charset = utf-16")
|
561
|
+
resp = @request.perform
|
562
|
+
|
563
|
+
expect(resp.body.encoding).to eq(Encoding.find("UTF-16LE"))
|
564
|
+
end
|
565
|
+
|
566
|
+
it 'processes stubbed frozen body correctly' do
|
567
|
+
response = stub_response "\xFF\xFEC\x00o\x00n\x00t\x00e\x00n\x00t\x00".freeze
|
568
|
+
|
569
|
+
response.initialize_http_header("Content-Type" => "text/plain;charset = utf-16")
|
570
|
+
resp = @request.perform
|
571
|
+
|
572
|
+
expect(resp.body.encoding).to eq(Encoding.find("UTF-16LE"))
|
573
|
+
end
|
552
574
|
end
|
553
575
|
|
554
576
|
it "should process utf-16 charset with big endian bom correctly" do
|
@@ -557,7 +579,7 @@ RSpec.describe HTTParty::Request do
|
|
557
579
|
response = stub_response "\xFE\xFF\x00C\x00o\x00n\x00t\x00e\x00n\x00t"
|
558
580
|
response.initialize_http_header("Content-Type" => "text/plain;charset = utf-16")
|
559
581
|
resp = @request.perform
|
560
|
-
|
582
|
+
|
561
583
|
expect(resp.body.encoding).to eq(Encoding.find("UTF-16BE"))
|
562
584
|
end
|
563
585
|
|
@@ -567,7 +589,7 @@ RSpec.describe HTTParty::Request do
|
|
567
589
|
response = stub_response "C\x00o\x00n\x00t\x00e\x00n\x00t\x00"
|
568
590
|
response.initialize_http_header("Content-Type" => "text/plain;charset = utf-16")
|
569
591
|
resp = @request.perform
|
570
|
-
|
592
|
+
|
571
593
|
expect(resp.body.encoding).to eq(Encoding.find("UTF-16LE"))
|
572
594
|
end
|
573
595
|
|
@@ -575,9 +597,9 @@ RSpec.describe HTTParty::Request do
|
|
575
597
|
response = stub_response "Content"
|
576
598
|
response.initialize_http_header("Content-Type" => "text/plain;charset = utf-lols")
|
577
599
|
resp = @request.perform
|
578
|
-
|
600
|
+
|
579
601
|
# This encoding does not exist, thus the string should not be encodd with it
|
580
|
-
|
602
|
+
|
581
603
|
expect(resp.body).to eq("Content")
|
582
604
|
expect(resp.body.encoding).to eq("Content".encoding)
|
583
605
|
end
|
@@ -586,7 +608,7 @@ RSpec.describe HTTParty::Request do
|
|
586
608
|
response = stub_response "Content"
|
587
609
|
response.initialize_http_header("Content-Type" => "text/plain")
|
588
610
|
resp = @request.perform
|
589
|
-
|
611
|
+
|
590
612
|
expect(resp.body).to eq("Content")
|
591
613
|
expect(resp.body.encoding).to eq("Content".encoding)
|
592
614
|
end
|
@@ -1,14 +1,17 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
|
2
2
|
|
3
|
-
RSpec.describe HTTParty::
|
3
|
+
RSpec.describe HTTParty::ResponseFragment do
|
4
4
|
it "access to fragment" do
|
5
|
-
fragment = HTTParty::
|
5
|
+
fragment = HTTParty::ResponseFragment.new("chunk", nil, nil)
|
6
6
|
expect(fragment).to eq("chunk")
|
7
7
|
end
|
8
|
+
|
8
9
|
it "has access to delegators" do
|
9
10
|
response = double(code: '200')
|
10
|
-
|
11
|
+
connection = double
|
12
|
+
fragment = HTTParty::ResponseFragment.new("chunk", response, connection)
|
11
13
|
expect(fragment.code).to eq(200)
|
12
14
|
expect(fragment.http_response).to eq response
|
15
|
+
expect(fragment.connection).to eq connection
|
13
16
|
end
|
14
17
|
end
|
@@ -39,10 +39,16 @@ RSpec.describe HTTParty::Response do
|
|
39
39
|
it "should set code" do
|
40
40
|
expect(@response.code).to eq(@response_object.code)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
it "should set code as an Integer" do
|
44
44
|
expect(@response.code).to be_a(Integer)
|
45
45
|
end
|
46
|
+
|
47
|
+
it "should set http_version" do
|
48
|
+
unparseable_body = lambda { raise "Unparseable" }
|
49
|
+
unparseable_response = HTTParty::Response.new(@request_object, @response_object, unparseable_body)
|
50
|
+
expect(unparseable_response.http_version).to eq(@response_object.http_version)
|
51
|
+
end
|
46
52
|
|
47
53
|
context 'when raise_on is supplied' do
|
48
54
|
let(:request) { HTTParty::Request.new(Net::HTTP::Get, '/', raise_on: [404]) }
|
data/spec/httparty/ssl_spec.rb
CHANGED
@@ -3,11 +3,11 @@ require 'spec_helper'
|
|
3
3
|
RSpec.describe HTTParty::Request do
|
4
4
|
context "SSL certificate verification" do
|
5
5
|
before do
|
6
|
-
WebMock.
|
6
|
+
WebMock.disable!
|
7
7
|
end
|
8
8
|
|
9
9
|
after do
|
10
|
-
WebMock.
|
10
|
+
WebMock.enable!
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should fail when no trusted CA list is specified, by default" do
|
@@ -70,5 +70,13 @@ RSpec.describe HTTParty::Request do
|
|
70
70
|
ssl_verify_test(:ssl_ca_path, ".", "bogushost.crt")
|
71
71
|
end.to raise_error(OpenSSL::SSL::SSLError)
|
72
72
|
end
|
73
|
+
|
74
|
+
it "should provide the certificate used by the server via peer_cert" do
|
75
|
+
peer_cert = nil
|
76
|
+
ssl_verify_test(:ssl_ca_file, "ca.crt", "server.crt") do |response|
|
77
|
+
peer_cert ||= response.connection.peer_cert
|
78
|
+
end
|
79
|
+
expect(peer_cert).to be_a OpenSSL::X509::Certificate
|
80
|
+
end
|
73
81
|
end
|
74
82
|
end
|
data/spec/httparty_spec.rb
CHANGED
@@ -329,6 +329,10 @@ RSpec.describe HTTParty do
|
|
329
329
|
@klass.default_timeout 0.5
|
330
330
|
expect(@klass.default_options[:timeout]).to eq(0.5)
|
331
331
|
end
|
332
|
+
|
333
|
+
it "should raise an exception if unsupported type provided" do
|
334
|
+
expect { @klass.default_timeout "0.5" }.to raise_error ArgumentError
|
335
|
+
end
|
332
336
|
end
|
333
337
|
|
334
338
|
describe "debug_output" do
|
@@ -837,6 +841,22 @@ RSpec.describe HTTParty do
|
|
837
841
|
).to eq(nil)
|
838
842
|
end
|
839
843
|
|
844
|
+
context 'when streaming body' do
|
845
|
+
let(:chunk) { 'Content'.force_encoding('ascii-8bit') }
|
846
|
+
let(:options) { { stream_body: true } }
|
847
|
+
before do
|
848
|
+
stub_chunked_http_response_with([chunk], options) do |response|
|
849
|
+
allow(response).to receive(:[]).with('content-type').and_return('text/plain; charset = "utf-8"')
|
850
|
+
end
|
851
|
+
end
|
852
|
+
|
853
|
+
specify do
|
854
|
+
HTTParty.get('http://www.google.com', options) do |fragment|
|
855
|
+
expect(fragment.encoding).to eq(Encoding.find("UTF-8"))
|
856
|
+
end
|
857
|
+
end
|
858
|
+
end
|
859
|
+
|
840
860
|
it "should be able parse response type json automatically" do
|
841
861
|
stub_http_response_with('twitter.json')
|
842
862
|
tweets = HTTParty.get('http://twitter.com/statuses/public_timeline.json')
|
data/spec/spec_helper.rb
CHANGED
@@ -2,7 +2,7 @@ require 'pathname'
|
|
2
2
|
|
3
3
|
module HTTParty
|
4
4
|
module SSLTestHelper
|
5
|
-
def ssl_verify_test(mode, ca_basename, server_cert_filename, options = {})
|
5
|
+
def ssl_verify_test(mode, ca_basename, server_cert_filename, options = {}, &block)
|
6
6
|
options = {
|
7
7
|
format: :json,
|
8
8
|
timeout: 30
|
@@ -24,9 +24,9 @@ module HTTParty
|
|
24
24
|
if mode
|
25
25
|
ca_path = File.expand_path("../../fixtures/ssl/generated/#{ca_basename}", __FILE__)
|
26
26
|
raise ArgumentError.new("#{ca_path} does not exist") unless File.exist?(ca_path)
|
27
|
-
return HTTParty.get("https://localhost:#{test_server.port}/", options)
|
27
|
+
return HTTParty.get("https://localhost:#{test_server.port}/", options, &block)
|
28
28
|
else
|
29
|
-
return HTTParty.get("https://localhost:#{test_server.port}/", options)
|
29
|
+
return HTTParty.get("https://localhost:#{test_server.port}/", options, &block)
|
30
30
|
end
|
31
31
|
ensure
|
32
32
|
test_server.stop if test_server
|
@@ -39,7 +39,7 @@ module HTTParty
|
|
39
39
|
|
40
40
|
test_server.start
|
41
41
|
|
42
|
-
HTTParty.get("https://localhost:#{test_server.port}/", options)
|
42
|
+
HTTParty.get("https://localhost:#{test_server.port}/", options, &block)
|
43
43
|
ensure
|
44
44
|
test_server.stop if test_server
|
45
45
|
end
|
@@ -19,6 +19,7 @@ module HTTParty
|
|
19
19
|
def response.read_body(&block)
|
20
20
|
@body || chunked_data.each(&block)
|
21
21
|
end
|
22
|
+
yield(response) if block_given?
|
22
23
|
|
23
24
|
http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', options)
|
24
25
|
allow(http_request).to receive_message_chain(:http, :request).and_yield(response).and_return(response)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httparty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-04-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_xml
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- examples/microsoft_graph.rb
|
77
77
|
- examples/multipart.rb
|
78
78
|
- examples/nokogiri_html_parser.rb
|
79
|
+
- examples/peer_cert.rb
|
79
80
|
- examples/rescue_json.rb
|
80
81
|
- examples/rubyurl.rb
|
81
82
|
- examples/stackexchange.rb
|
@@ -102,7 +103,6 @@ files:
|
|
102
103
|
- lib/httparty/connection_adapter.rb
|
103
104
|
- lib/httparty/cookie_hash.rb
|
104
105
|
- lib/httparty/exceptions.rb
|
105
|
-
- lib/httparty/fragment_with_response.rb
|
106
106
|
- lib/httparty/hash_conversions.rb
|
107
107
|
- lib/httparty/logger/apache_formatter.rb
|
108
108
|
- lib/httparty/logger/curl_formatter.rb
|
@@ -116,6 +116,8 @@ files:
|
|
116
116
|
- lib/httparty/request/multipart_boundary.rb
|
117
117
|
- lib/httparty/response.rb
|
118
118
|
- lib/httparty/response/headers.rb
|
119
|
+
- lib/httparty/response_fragment.rb
|
120
|
+
- lib/httparty/text_encoder.rb
|
119
121
|
- lib/httparty/utils.rb
|
120
122
|
- lib/httparty/version.rb
|
121
123
|
- script/release
|
@@ -138,7 +140,6 @@ files:
|
|
138
140
|
- spec/httparty/connection_adapter_spec.rb
|
139
141
|
- spec/httparty/cookie_hash_spec.rb
|
140
142
|
- spec/httparty/exception_spec.rb
|
141
|
-
- spec/httparty/fragment_with_response_spec.rb
|
142
143
|
- spec/httparty/hash_conversions_spec.rb
|
143
144
|
- spec/httparty/logger/apache_formatter_spec.rb
|
144
145
|
- spec/httparty/logger/curl_formatter_spec.rb
|
@@ -148,6 +149,7 @@ files:
|
|
148
149
|
- spec/httparty/parser_spec.rb
|
149
150
|
- spec/httparty/request/body_spec.rb
|
150
151
|
- spec/httparty/request_spec.rb
|
152
|
+
- spec/httparty/response_fragment_spec.rb
|
151
153
|
- spec/httparty/response_spec.rb
|
152
154
|
- spec/httparty/ssl_spec.rb
|
153
155
|
- spec/httparty_spec.rb
|
@@ -215,7 +217,6 @@ test_files:
|
|
215
217
|
- spec/httparty/connection_adapter_spec.rb
|
216
218
|
- spec/httparty/cookie_hash_spec.rb
|
217
219
|
- spec/httparty/exception_spec.rb
|
218
|
-
- spec/httparty/fragment_with_response_spec.rb
|
219
220
|
- spec/httparty/hash_conversions_spec.rb
|
220
221
|
- spec/httparty/logger/apache_formatter_spec.rb
|
221
222
|
- spec/httparty/logger/curl_formatter_spec.rb
|
@@ -225,6 +226,7 @@ test_files:
|
|
225
226
|
- spec/httparty/parser_spec.rb
|
226
227
|
- spec/httparty/request/body_spec.rb
|
227
228
|
- spec/httparty/request_spec.rb
|
229
|
+
- spec/httparty/response_fragment_spec.rb
|
228
230
|
- spec/httparty/response_spec.rb
|
229
231
|
- spec/httparty/ssl_spec.rb
|
230
232
|
- spec/httparty_spec.rb
|