httparty 0.15.4 → 0.20.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.

Files changed (93) hide show
  1. checksums.yaml +5 -5
  2. data/.editorconfig +18 -0
  3. data/.github/workflows/ci.yml +23 -0
  4. data/.gitignore +2 -0
  5. data/.rubocop_todo.yml +1 -1
  6. data/Changelog.md +105 -0
  7. data/Gemfile +6 -1
  8. data/README.md +6 -6
  9. data/docs/README.md +100 -38
  10. data/examples/README.md +28 -11
  11. data/examples/aaws.rb +6 -2
  12. data/examples/body_stream.rb +14 -0
  13. data/examples/custom_parsers.rb +4 -0
  14. data/examples/headers_and_user_agents.rb +7 -3
  15. data/examples/idn.rb +10 -0
  16. data/examples/logging.rb +3 -3
  17. data/examples/microsoft_graph.rb +52 -0
  18. data/examples/multipart.rb +22 -0
  19. data/examples/peer_cert.rb +9 -0
  20. data/examples/stream_download.rb +8 -2
  21. data/httparty.gemspec +3 -3
  22. data/lib/httparty/connection_adapter.rb +59 -16
  23. data/lib/httparty/cookie_hash.rb +10 -8
  24. data/lib/httparty/decompressor.rb +92 -0
  25. data/lib/httparty/exceptions.rb +4 -1
  26. data/lib/httparty/hash_conversions.rb +28 -12
  27. data/lib/httparty/headers_processor.rb +32 -0
  28. data/lib/httparty/logger/apache_formatter.rb +31 -6
  29. data/lib/httparty/logger/curl_formatter.rb +9 -7
  30. data/lib/httparty/logger/logger.rb +5 -1
  31. data/lib/httparty/logger/logstash_formatter.rb +61 -0
  32. data/lib/httparty/module_inheritable_attributes.rb +6 -4
  33. data/lib/httparty/net_digest_auth.rb +15 -15
  34. data/lib/httparty/parser.rb +22 -16
  35. data/lib/httparty/request/body.rb +98 -0
  36. data/lib/httparty/request/multipart_boundary.rb +13 -0
  37. data/lib/httparty/request.rb +82 -95
  38. data/lib/httparty/response/headers.rb +4 -2
  39. data/lib/httparty/response.rb +59 -8
  40. data/lib/httparty/response_fragment.rb +21 -0
  41. data/lib/httparty/text_encoder.rb +72 -0
  42. data/lib/httparty/utils.rb +13 -0
  43. data/lib/httparty/version.rb +3 -1
  44. data/lib/httparty.rb +70 -24
  45. data/website/css/common.css +1 -1
  46. metadata +35 -100
  47. data/.travis.yml +0 -8
  48. data/features/basic_authentication.feature +0 -20
  49. data/features/command_line.feature +0 -95
  50. data/features/deals_with_http_error_codes.feature +0 -26
  51. data/features/digest_authentication.feature +0 -30
  52. data/features/handles_compressed_responses.feature +0 -27
  53. data/features/handles_multiple_formats.feature +0 -57
  54. data/features/steps/env.rb +0 -27
  55. data/features/steps/httparty_response_steps.rb +0 -56
  56. data/features/steps/httparty_steps.rb +0 -43
  57. data/features/steps/mongrel_helper.rb +0 -127
  58. data/features/steps/remote_service_steps.rb +0 -92
  59. data/features/supports_read_timeout_option.feature +0 -13
  60. data/features/supports_redirection.feature +0 -22
  61. data/features/supports_timeout_option.feature +0 -13
  62. data/spec/fixtures/delicious.xml +0 -23
  63. data/spec/fixtures/empty.xml +0 -0
  64. data/spec/fixtures/google.html +0 -3
  65. data/spec/fixtures/ssl/generate.sh +0 -29
  66. data/spec/fixtures/ssl/generated/bogushost.crt +0 -13
  67. data/spec/fixtures/ssl/generated/ca.crt +0 -16
  68. data/spec/fixtures/ssl/generated/ca.key +0 -15
  69. data/spec/fixtures/ssl/generated/selfsigned.crt +0 -14
  70. data/spec/fixtures/ssl/generated/server.crt +0 -13
  71. data/spec/fixtures/ssl/generated/server.key +0 -15
  72. data/spec/fixtures/ssl/openssl-exts.cnf +0 -9
  73. data/spec/fixtures/twitter.csv +0 -2
  74. data/spec/fixtures/twitter.json +0 -1
  75. data/spec/fixtures/twitter.xml +0 -403
  76. data/spec/fixtures/undefined_method_add_node_for_nil.xml +0 -2
  77. data/spec/httparty/connection_adapter_spec.rb +0 -495
  78. data/spec/httparty/cookie_hash_spec.rb +0 -100
  79. data/spec/httparty/exception_spec.rb +0 -45
  80. data/spec/httparty/hash_conversions_spec.rb +0 -49
  81. data/spec/httparty/logger/apache_formatter_spec.rb +0 -41
  82. data/spec/httparty/logger/curl_formatter_spec.rb +0 -119
  83. data/spec/httparty/logger/logger_spec.rb +0 -38
  84. data/spec/httparty/net_digest_auth_spec.rb +0 -268
  85. data/spec/httparty/parser_spec.rb +0 -185
  86. data/spec/httparty/request_spec.rb +0 -1251
  87. data/spec/httparty/response_spec.rb +0 -347
  88. data/spec/httparty/ssl_spec.rb +0 -74
  89. data/spec/httparty_spec.rb +0 -877
  90. data/spec/spec_helper.rb +0 -59
  91. data/spec/support/ssl_test_helper.rb +0 -47
  92. data/spec/support/ssl_test_server.rb +0 -80
  93. data/spec/support/stub_response.rb +0 -49
data/spec/spec_helper.rb DELETED
@@ -1,59 +0,0 @@
1
- require "simplecov"
2
- SimpleCov.start
3
-
4
- require "httparty"
5
- require "fakeweb"
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.before(:suite) do
18
- FakeWeb.allow_net_connect = false
19
- end
20
-
21
- config.after(:suite) do
22
- FakeWeb.allow_net_connect = true
23
- end
24
-
25
- config.expect_with :rspec do |expectations|
26
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
27
- end
28
-
29
- config.mock_with :rspec do |mocks|
30
- mocks.verify_partial_doubles = false
31
- end
32
-
33
- config.filter_run :focus
34
- config.run_all_when_everything_filtered = true
35
-
36
- config.disable_monkey_patching!
37
-
38
- config.warnings = true
39
-
40
- if config.files_to_run.one?
41
- config.default_formatter = 'doc'
42
- end
43
-
44
- config.profile_examples = 10
45
-
46
- config.order = :random
47
-
48
- Kernel.srand config.seed
49
- end
50
-
51
- RSpec::Matchers.define :use_ssl do
52
- match(&:use_ssl?)
53
- end
54
-
55
- RSpec::Matchers.define :use_cert_store do |cert_store|
56
- match do |connection|
57
- connection.cert_store == cert_store
58
- end
59
- 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