httparty 0.17.0 → 0.17.1

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 (60) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +7 -0
  3. data/Gemfile +1 -0
  4. data/httparty.gemspec +0 -1
  5. data/lib/httparty.rb +2 -18
  6. data/lib/httparty/connection_adapter.rb +10 -0
  7. data/lib/httparty/headers_processor.rb +30 -0
  8. data/lib/httparty/request.rb +4 -4
  9. data/lib/httparty/version.rb +1 -1
  10. metadata +4 -103
  11. data/features/basic_authentication.feature +0 -20
  12. data/features/command_line.feature +0 -95
  13. data/features/deals_with_http_error_codes.feature +0 -26
  14. data/features/digest_authentication.feature +0 -30
  15. data/features/handles_compressed_responses.feature +0 -27
  16. data/features/handles_multiple_formats.feature +0 -57
  17. data/features/steps/env.rb +0 -27
  18. data/features/steps/httparty_response_steps.rb +0 -56
  19. data/features/steps/httparty_steps.rb +0 -43
  20. data/features/steps/mongrel_helper.rb +0 -127
  21. data/features/steps/remote_service_steps.rb +0 -92
  22. data/features/supports_read_timeout_option.feature +0 -13
  23. data/features/supports_redirection.feature +0 -22
  24. data/features/supports_timeout_option.feature +0 -13
  25. data/spec/fixtures/delicious.xml +0 -23
  26. data/spec/fixtures/empty.xml +0 -0
  27. data/spec/fixtures/example.html +0 -10
  28. data/spec/fixtures/ssl/generate.sh +0 -29
  29. data/spec/fixtures/ssl/generated/bogushost.crt +0 -29
  30. data/spec/fixtures/ssl/generated/ca.crt +0 -31
  31. data/spec/fixtures/ssl/generated/ca.key +0 -52
  32. data/spec/fixtures/ssl/generated/selfsigned.crt +0 -29
  33. data/spec/fixtures/ssl/generated/server.crt +0 -30
  34. data/spec/fixtures/ssl/generated/server.key +0 -52
  35. data/spec/fixtures/ssl/openssl-exts.cnf +0 -9
  36. data/spec/fixtures/tiny.gif +0 -0
  37. data/spec/fixtures/twitter.csv +0 -2
  38. data/spec/fixtures/twitter.json +0 -1
  39. data/spec/fixtures/twitter.xml +0 -403
  40. data/spec/fixtures/undefined_method_add_node_for_nil.xml +0 -2
  41. data/spec/httparty/connection_adapter_spec.rb +0 -628
  42. data/spec/httparty/cookie_hash_spec.rb +0 -100
  43. data/spec/httparty/exception_spec.rb +0 -45
  44. data/spec/httparty/hash_conversions_spec.rb +0 -58
  45. data/spec/httparty/logger/apache_formatter_spec.rb +0 -40
  46. data/spec/httparty/logger/curl_formatter_spec.rb +0 -119
  47. data/spec/httparty/logger/logger_spec.rb +0 -43
  48. data/spec/httparty/logger/logstash_formatter_spec.rb +0 -44
  49. data/spec/httparty/net_digest_auth_spec.rb +0 -270
  50. data/spec/httparty/parser_spec.rb +0 -190
  51. data/spec/httparty/request/body_spec.rb +0 -165
  52. data/spec/httparty/request_spec.rb +0 -1389
  53. data/spec/httparty/response_fragment_spec.rb +0 -17
  54. data/spec/httparty/response_spec.rb +0 -374
  55. data/spec/httparty/ssl_spec.rb +0 -82
  56. data/spec/httparty_spec.rb +0 -943
  57. data/spec/spec_helper.rb +0 -57
  58. data/spec/support/ssl_test_helper.rb +0 -47
  59. data/spec/support/ssl_test_server.rb +0 -80
  60. data/spec/support/stub_response.rb +0 -50
@@ -1,57 +0,0 @@
1
- require "simplecov"
2
- SimpleCov.start
3
- require 'pry'
4
-
5
- require "httparty"
6
- require 'webmock/rspec'
7
-
8
- def file_fixture(filename)
9
- open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename}")).read
10
- end
11
-
12
- Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].each {|f| require f}
13
-
14
- RSpec.configure do |config|
15
- config.include HTTParty::StubResponse
16
- config.include HTTParty::SSLTestHelper
17
-
18
- config.expect_with :rspec do |expectations|
19
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
20
- end
21
-
22
- config.mock_with :rspec do |mocks|
23
- mocks.verify_partial_doubles = false
24
- end
25
-
26
- config.filter_run :focus
27
- config.run_all_when_everything_filtered = true
28
-
29
- config.disable_monkey_patching!
30
-
31
- config.warnings = true
32
-
33
- if config.files_to_run.one?
34
- config.default_formatter = 'doc'
35
- end
36
-
37
- config.profile_examples = 10
38
-
39
- config.order = :random
40
-
41
- config.before(:each) do
42
- # Reset default_cert_store cache
43
- HTTParty::ConnectionAdapter.instance_variable_set(:@default_cert_store, nil)
44
- end
45
-
46
- Kernel.srand config.seed
47
- end
48
-
49
- RSpec::Matchers.define :use_ssl do
50
- match(&:use_ssl?)
51
- end
52
-
53
- RSpec::Matchers.define :use_cert_store do |cert_store|
54
- match do |connection|
55
- connection.cert_store == cert_store
56
- end
57
- 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 = {}, &block)
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, &block)
28
- else
29
- return HTTParty.get("https://localhost:#{test_server.port}/", options, &block)
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, &block)
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,50 +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
- yield(response) if block_given?
23
-
24
- http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', options)
25
- allow(http_request).to receive_message_chain(:http, :request).and_yield(response).and_return(response)
26
-
27
- expect(HTTParty::Request).to receive(:new).and_return(http_request)
28
- end
29
-
30
- def stub_response(body, code = '200')
31
- code = code.to_s
32
- @request.options[:base_uri] ||= 'http://localhost'
33
- unless defined?(@http) && @http
34
- @http = Net::HTTP.new('localhost', 80)
35
- allow(@request).to receive(:http).and_return(@http)
36
- end
37
-
38
- # CODE_TO_OBJ currently missing 308
39
- if code == '308'
40
- response = Net::HTTPRedirection.new("1.1", code, body)
41
- else
42
- response = Net::HTTPResponse::CODE_TO_OBJ[code].new("1.1", code, body)
43
- end
44
- allow(response).to receive(:body).and_return(body)
45
-
46
- allow(@http).to receive(:request).and_return(response)
47
- response
48
- end
49
- end
50
- end