httparty 0.16.4 → 0.20.0
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.
Potentially problematic release.
This version of httparty might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +23 -0
- data/.rubocop_todo.yml +1 -1
- data/Changelog.md +55 -0
- data/Gemfile +5 -0
- data/README.md +4 -4
- data/docs/README.md +70 -5
- data/examples/README.md +6 -0
- data/examples/aaws.rb +6 -2
- data/examples/idn.rb +10 -0
- data/examples/peer_cert.rb +9 -0
- data/httparty.gemspec +1 -2
- data/lib/httparty/connection_adapter.rb +41 -10
- data/lib/httparty/cookie_hash.rb +10 -8
- data/lib/httparty/decompressor.rb +92 -0
- data/lib/httparty/exceptions.rb +3 -1
- data/lib/httparty/hash_conversions.rb +4 -2
- data/lib/httparty/headers_processor.rb +32 -0
- data/lib/httparty/logger/apache_formatter.rb +4 -2
- data/lib/httparty/logger/curl_formatter.rb +6 -4
- data/lib/httparty/logger/logger.rb +2 -0
- data/lib/httparty/logger/logstash_formatter.rb +4 -2
- data/lib/httparty/module_inheritable_attributes.rb +3 -1
- data/lib/httparty/net_digest_auth.rb +9 -10
- data/lib/httparty/parser.rb +9 -5
- data/lib/httparty/request/body.rb +24 -10
- data/lib/httparty/request/multipart_boundary.rb +2 -0
- data/lib/httparty/request.rb +67 -96
- data/lib/httparty/response/headers.rb +2 -0
- data/lib/httparty/response.rb +24 -4
- data/lib/httparty/{fragment_with_response.rb → response_fragment.rb} +6 -5
- data/lib/httparty/text_encoder.rb +72 -0
- data/lib/httparty/utils.rb +2 -0
- data/lib/httparty/version.rb +3 -1
- data/lib/httparty.rb +58 -35
- metadata +12 -108
- data/.travis.yml +0 -11
- data/features/basic_authentication.feature +0 -20
- data/features/command_line.feature +0 -95
- data/features/deals_with_http_error_codes.feature +0 -26
- data/features/digest_authentication.feature +0 -30
- data/features/handles_compressed_responses.feature +0 -27
- data/features/handles_multiple_formats.feature +0 -57
- data/features/steps/env.rb +0 -27
- data/features/steps/httparty_response_steps.rb +0 -56
- data/features/steps/httparty_steps.rb +0 -43
- data/features/steps/mongrel_helper.rb +0 -127
- data/features/steps/remote_service_steps.rb +0 -92
- data/features/supports_read_timeout_option.feature +0 -13
- data/features/supports_redirection.feature +0 -22
- data/features/supports_timeout_option.feature +0 -13
- data/spec/fixtures/delicious.xml +0 -23
- data/spec/fixtures/empty.xml +0 -0
- data/spec/fixtures/example.html +0 -10
- data/spec/fixtures/ssl/generate.sh +0 -29
- data/spec/fixtures/ssl/generated/bogushost.crt +0 -13
- data/spec/fixtures/ssl/generated/ca.crt +0 -16
- data/spec/fixtures/ssl/generated/ca.key +0 -15
- data/spec/fixtures/ssl/generated/selfsigned.crt +0 -14
- data/spec/fixtures/ssl/generated/server.crt +0 -13
- data/spec/fixtures/ssl/generated/server.key +0 -15
- data/spec/fixtures/ssl/openssl-exts.cnf +0 -9
- data/spec/fixtures/tiny.gif +0 -0
- data/spec/fixtures/twitter.csv +0 -2
- data/spec/fixtures/twitter.json +0 -1
- data/spec/fixtures/twitter.xml +0 -403
- data/spec/fixtures/undefined_method_add_node_for_nil.xml +0 -2
- data/spec/httparty/connection_adapter_spec.rb +0 -502
- data/spec/httparty/cookie_hash_spec.rb +0 -100
- data/spec/httparty/exception_spec.rb +0 -45
- data/spec/httparty/fragment_with_response_spec.rb +0 -14
- data/spec/httparty/hash_conversions_spec.rb +0 -58
- data/spec/httparty/logger/apache_formatter_spec.rb +0 -40
- data/spec/httparty/logger/curl_formatter_spec.rb +0 -119
- data/spec/httparty/logger/logger_spec.rb +0 -43
- data/spec/httparty/logger/logstash_formatter_spec.rb +0 -44
- data/spec/httparty/net_digest_auth_spec.rb +0 -270
- data/spec/httparty/parser_spec.rb +0 -190
- data/spec/httparty/request/body_spec.rb +0 -165
- data/spec/httparty/request_spec.rb +0 -1367
- data/spec/httparty/response_spec.rb +0 -368
- data/spec/httparty/ssl_spec.rb +0 -74
- data/spec/httparty_spec.rb +0 -923
- data/spec/spec_helper.rb +0 -56
- data/spec/support/ssl_test_helper.rb +0 -47
- data/spec/support/ssl_test_server.rb +0 -80
- data/spec/support/stub_response.rb +0 -49
data/spec/spec_helper.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require "simplecov"
|
2
|
-
SimpleCov.start
|
3
|
-
|
4
|
-
require "httparty"
|
5
|
-
require 'webmock/rspec'
|
6
|
-
|
7
|
-
def file_fixture(filename)
|
8
|
-
open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename}")).read
|
9
|
-
end
|
10
|
-
|
11
|
-
Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].each {|f| require f}
|
12
|
-
|
13
|
-
RSpec.configure do |config|
|
14
|
-
config.include HTTParty::StubResponse
|
15
|
-
config.include HTTParty::SSLTestHelper
|
16
|
-
|
17
|
-
config.expect_with :rspec do |expectations|
|
18
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
19
|
-
end
|
20
|
-
|
21
|
-
config.mock_with :rspec do |mocks|
|
22
|
-
mocks.verify_partial_doubles = false
|
23
|
-
end
|
24
|
-
|
25
|
-
config.filter_run :focus
|
26
|
-
config.run_all_when_everything_filtered = true
|
27
|
-
|
28
|
-
config.disable_monkey_patching!
|
29
|
-
|
30
|
-
config.warnings = true
|
31
|
-
|
32
|
-
if config.files_to_run.one?
|
33
|
-
config.default_formatter = 'doc'
|
34
|
-
end
|
35
|
-
|
36
|
-
config.profile_examples = 10
|
37
|
-
|
38
|
-
config.order = :random
|
39
|
-
|
40
|
-
config.before(:each) do
|
41
|
-
# Reset default_cert_store cache
|
42
|
-
HTTParty::ConnectionAdapter.instance_variable_set(:@default_cert_store, nil)
|
43
|
-
end
|
44
|
-
|
45
|
-
Kernel.srand config.seed
|
46
|
-
end
|
47
|
-
|
48
|
-
RSpec::Matchers.define :use_ssl do
|
49
|
-
match(&:use_ssl?)
|
50
|
-
end
|
51
|
-
|
52
|
-
RSpec::Matchers.define :use_cert_store do |cert_store|
|
53
|
-
match do |connection|
|
54
|
-
connection.cert_store == cert_store
|
55
|
-
end
|
56
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
|
3
|
-
module HTTParty
|
4
|
-
module SSLTestHelper
|
5
|
-
def ssl_verify_test(mode, ca_basename, server_cert_filename, options = {})
|
6
|
-
options = {
|
7
|
-
format: :json,
|
8
|
-
timeout: 30
|
9
|
-
}.merge(options)
|
10
|
-
|
11
|
-
if mode
|
12
|
-
ca_path = File.expand_path("../../fixtures/ssl/generated/#{ca_basename}", __FILE__)
|
13
|
-
raise ArgumentError.new("#{ca_path} does not exist") unless File.exist?(ca_path)
|
14
|
-
options[mode] = ca_path
|
15
|
-
end
|
16
|
-
|
17
|
-
begin
|
18
|
-
test_server = SSLTestServer.new(
|
19
|
-
rsa_key: File.read(File.expand_path("../../fixtures/ssl/generated/server.key", __FILE__)),
|
20
|
-
cert: File.read(File.expand_path("../../fixtures/ssl/generated/#{server_cert_filename}", __FILE__)))
|
21
|
-
|
22
|
-
test_server.start
|
23
|
-
|
24
|
-
if mode
|
25
|
-
ca_path = File.expand_path("../../fixtures/ssl/generated/#{ca_basename}", __FILE__)
|
26
|
-
raise ArgumentError.new("#{ca_path} does not exist") unless File.exist?(ca_path)
|
27
|
-
return HTTParty.get("https://localhost:#{test_server.port}/", options)
|
28
|
-
else
|
29
|
-
return HTTParty.get("https://localhost:#{test_server.port}/", options)
|
30
|
-
end
|
31
|
-
ensure
|
32
|
-
test_server.stop if test_server
|
33
|
-
end
|
34
|
-
|
35
|
-
test_server = SSLTestServer.new({
|
36
|
-
rsa_key: path.join('server.key').read,
|
37
|
-
cert: path.join(server_cert_filename).read
|
38
|
-
})
|
39
|
-
|
40
|
-
test_server.start
|
41
|
-
|
42
|
-
HTTParty.get("https://localhost:#{test_server.port}/", options)
|
43
|
-
ensure
|
44
|
-
test_server.stop if test_server
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'openssl'
|
2
|
-
require 'socket'
|
3
|
-
require 'thread'
|
4
|
-
|
5
|
-
# NOTE: This code is garbage. It probably has deadlocks, it might leak
|
6
|
-
# threads, and otherwise cause problems in a real system. It's really only
|
7
|
-
# intended for testing HTTParty.
|
8
|
-
class SSLTestServer
|
9
|
-
attr_accessor :ctx # SSLContext object
|
10
|
-
attr_reader :port
|
11
|
-
|
12
|
-
def initialize(options = {})
|
13
|
-
@ctx = OpenSSL::SSL::SSLContext.new
|
14
|
-
@ctx.cert = OpenSSL::X509::Certificate.new(options[:cert])
|
15
|
-
@ctx.key = OpenSSL::PKey::RSA.new(options[:rsa_key])
|
16
|
-
@ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE # Don't verify client certificate
|
17
|
-
@port = options[:port] || 0
|
18
|
-
@thread = nil
|
19
|
-
@stopping_mutex = Mutex.new
|
20
|
-
@stopping = false
|
21
|
-
end
|
22
|
-
|
23
|
-
def start
|
24
|
-
@raw_server = TCPServer.new(@port)
|
25
|
-
|
26
|
-
if @port == 0
|
27
|
-
@port = Socket.getnameinfo(@raw_server.getsockname, Socket::NI_NUMERICHOST | Socket::NI_NUMERICSERV)[1].to_i
|
28
|
-
end
|
29
|
-
|
30
|
-
@ssl_server = OpenSSL::SSL::SSLServer.new(@raw_server, @ctx)
|
31
|
-
|
32
|
-
@stopping_mutex.synchronize {
|
33
|
-
return if @stopping
|
34
|
-
@thread = Thread.new { thread_main }
|
35
|
-
}
|
36
|
-
|
37
|
-
nil
|
38
|
-
end
|
39
|
-
|
40
|
-
def stop
|
41
|
-
@stopping_mutex.synchronize {
|
42
|
-
return if @stopping
|
43
|
-
@stopping = true
|
44
|
-
}
|
45
|
-
@thread.join
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def thread_main
|
51
|
-
until @stopping_mutex.synchronize { @stopping }
|
52
|
-
(rr, _, _) = select([@ssl_server.to_io], nil, nil, 0.1)
|
53
|
-
|
54
|
-
next unless rr && rr.include?(@ssl_server.to_io)
|
55
|
-
|
56
|
-
socket = @ssl_server.accept
|
57
|
-
|
58
|
-
Thread.new {
|
59
|
-
header = []
|
60
|
-
|
61
|
-
until (line = socket.readline).rstrip.empty?
|
62
|
-
header << line
|
63
|
-
end
|
64
|
-
|
65
|
-
response = <<EOF
|
66
|
-
HTTP/1.1 200 OK
|
67
|
-
Connection: close
|
68
|
-
Content-Type: application/json; charset=UTF-8
|
69
|
-
|
70
|
-
{"success":true}
|
71
|
-
EOF
|
72
|
-
|
73
|
-
socket.write(response.gsub(/\r\n/n, "\n").gsub(/\n/n, "\r\n"))
|
74
|
-
socket.close
|
75
|
-
}
|
76
|
-
end
|
77
|
-
|
78
|
-
@ssl_server.close
|
79
|
-
end
|
80
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module HTTParty
|
2
|
-
module StubResponse
|
3
|
-
def stub_http_response_with(filename)
|
4
|
-
format = filename.split('.').last.intern
|
5
|
-
data = file_fixture(filename)
|
6
|
-
|
7
|
-
response = Net::HTTPOK.new("1.1", 200, "Content for you")
|
8
|
-
allow(response).to receive(:body).and_return(data)
|
9
|
-
|
10
|
-
http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', format: format)
|
11
|
-
allow(http_request).to receive_message_chain(:http, :request).and_return(response)
|
12
|
-
|
13
|
-
expect(HTTParty::Request).to receive(:new).and_return(http_request)
|
14
|
-
end
|
15
|
-
|
16
|
-
def stub_chunked_http_response_with(chunks, options = {format: "html"})
|
17
|
-
response = Net::HTTPResponse.new("1.1", 200, nil)
|
18
|
-
allow(response).to receive(:chunked_data).and_return(chunks)
|
19
|
-
def response.read_body(&block)
|
20
|
-
@body || chunked_data.each(&block)
|
21
|
-
end
|
22
|
-
|
23
|
-
http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', options)
|
24
|
-
allow(http_request).to receive_message_chain(:http, :request).and_yield(response).and_return(response)
|
25
|
-
|
26
|
-
expect(HTTParty::Request).to receive(:new).and_return(http_request)
|
27
|
-
end
|
28
|
-
|
29
|
-
def stub_response(body, code = '200')
|
30
|
-
code = code.to_s
|
31
|
-
@request.options[:base_uri] ||= 'http://localhost'
|
32
|
-
unless defined?(@http) && @http
|
33
|
-
@http = Net::HTTP.new('localhost', 80)
|
34
|
-
allow(@request).to receive(:http).and_return(@http)
|
35
|
-
end
|
36
|
-
|
37
|
-
# CODE_TO_OBJ currently missing 308
|
38
|
-
if code == '308'
|
39
|
-
response = Net::HTTPRedirection.new("1.1", code, body)
|
40
|
-
else
|
41
|
-
response = Net::HTTPResponse::CODE_TO_OBJ[code].new("1.1", code, body)
|
42
|
-
end
|
43
|
-
allow(response).to receive(:body).and_return(body)
|
44
|
-
|
45
|
-
allow(@http).to receive(:request).and_return(response)
|
46
|
-
response
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|