rest-client 1.6.7 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.mailmap +10 -0
  4. data/.rspec +2 -0
  5. data/.rubocop +2 -0
  6. data/.rubocop-disables.yml +386 -0
  7. data/.rubocop.yml +8 -0
  8. data/.travis.yml +62 -0
  9. data/AUTHORS +106 -0
  10. data/Gemfile +11 -0
  11. data/LICENSE +21 -0
  12. data/README.md +901 -0
  13. data/Rakefile +109 -35
  14. data/bin/restclient +11 -12
  15. data/history.md +244 -1
  16. data/lib/restclient.rb +27 -18
  17. data/lib/restclient/abstract_response.rb +197 -51
  18. data/lib/restclient/exceptions.rb +110 -59
  19. data/lib/restclient/params_array.rb +72 -0
  20. data/lib/restclient/payload.rb +74 -75
  21. data/lib/restclient/platform.rb +49 -0
  22. data/lib/restclient/raw_response.rb +21 -6
  23. data/lib/restclient/request.rb +747 -183
  24. data/lib/restclient/resource.rb +22 -13
  25. data/lib/restclient/response.rb +75 -9
  26. data/lib/restclient/utils.rb +274 -0
  27. data/lib/restclient/version.rb +8 -0
  28. data/lib/restclient/windows.rb +8 -0
  29. data/lib/restclient/windows/root_certs.rb +105 -0
  30. data/rest-client.gemspec +32 -0
  31. data/rest-client.windows.gemspec +19 -0
  32. data/spec/ISS.jpg +0 -0
  33. data/spec/helpers.rb +54 -0
  34. data/spec/integration/_lib.rb +1 -0
  35. data/spec/integration/capath_digicert/3513523f.0 +22 -0
  36. data/spec/integration/capath_digicert/399e7759.0 +22 -0
  37. data/spec/integration/capath_digicert/README +8 -0
  38. data/spec/integration/capath_digicert/digicert.crt +22 -0
  39. data/spec/integration/capath_verisign/415660c1.0 +14 -0
  40. data/spec/integration/capath_verisign/7651b327.0 +14 -0
  41. data/spec/integration/capath_verisign/README +8 -0
  42. data/spec/integration/capath_verisign/verisign.crt +14 -0
  43. data/spec/integration/certs/digicert.crt +22 -0
  44. data/spec/integration/httpbin_spec.rb +128 -0
  45. data/spec/integration/integration_spec.rb +118 -0
  46. data/spec/integration/request_spec.rb +109 -7
  47. data/spec/spec_helper.rb +29 -0
  48. data/spec/unit/_lib.rb +1 -0
  49. data/spec/unit/abstract_response_spec.rb +145 -0
  50. data/spec/unit/exceptions_spec.rb +108 -0
  51. data/spec/unit/params_array_spec.rb +36 -0
  52. data/spec/unit/payload_spec.rb +295 -0
  53. data/spec/unit/raw_response_spec.rb +22 -0
  54. data/spec/unit/request2_spec.rb +54 -0
  55. data/spec/unit/request_spec.rb +1238 -0
  56. data/spec/unit/resource_spec.rb +134 -0
  57. data/spec/unit/response_spec.rb +252 -0
  58. data/spec/unit/restclient_spec.rb +80 -0
  59. data/spec/unit/utils_spec.rb +147 -0
  60. data/spec/unit/windows/root_certs_spec.rb +22 -0
  61. metadata +265 -117
  62. data/README.rdoc +0 -285
  63. data/VERSION +0 -1
  64. data/lib/restclient/net_http_ext.rb +0 -55
  65. data/spec/abstract_response_spec.rb +0 -85
  66. data/spec/base.rb +0 -16
  67. data/spec/exceptions_spec.rb +0 -98
  68. data/spec/integration/certs/equifax.crt +0 -19
  69. data/spec/integration_spec.rb +0 -38
  70. data/spec/master_shake.jpg +0 -0
  71. data/spec/payload_spec.rb +0 -234
  72. data/spec/raw_response_spec.rb +0 -17
  73. data/spec/request2_spec.rb +0 -40
  74. data/spec/request_spec.rb +0 -529
  75. data/spec/resource_spec.rb +0 -134
  76. data/spec/response_spec.rb +0 -169
  77. data/spec/restclient_spec.rb +0 -73
@@ -0,0 +1,8 @@
1
+ module RestClient
2
+ VERSION_INFO = [2, 1, 0].freeze
3
+ VERSION = VERSION_INFO.map(&:to_s).join('.').freeze
4
+
5
+ def self.version
6
+ VERSION
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module RestClient
2
+ module Windows
3
+ end
4
+ end
5
+
6
+ if RestClient::Platform.windows?
7
+ require_relative './windows/root_certs'
8
+ end
@@ -0,0 +1,105 @@
1
+ require 'openssl'
2
+ require 'ffi'
3
+
4
+ # Adapted from Puppet, Copyright (c) Puppet Labs Inc,
5
+ # licensed under the Apache License, Version 2.0.
6
+ #
7
+ # https://github.com/puppetlabs/puppet/blob/bbe30e0a/lib/puppet/util/windows/root_certs.rb
8
+
9
+ # Represents a collection of trusted root certificates.
10
+ #
11
+ # @api public
12
+ class RestClient::Windows::RootCerts
13
+ include Enumerable
14
+ extend FFI::Library
15
+
16
+ typedef :ulong, :dword
17
+ typedef :uintptr_t, :handle
18
+
19
+ def initialize(roots)
20
+ @roots = roots
21
+ end
22
+
23
+ # Enumerates each root certificate.
24
+ # @yieldparam cert [OpenSSL::X509::Certificate] each root certificate
25
+ # @api public
26
+ def each
27
+ @roots.each {|cert| yield cert}
28
+ end
29
+
30
+ # Returns a new instance.
31
+ # @return [RestClient::Windows::RootCerts] object constructed from current root certificates
32
+ def self.instance
33
+ new(self.load_certs)
34
+ end
35
+
36
+ # Returns an array of root certificates.
37
+ #
38
+ # @return [Array<[OpenSSL::X509::Certificate]>] an array of root certificates
39
+ # @api private
40
+ def self.load_certs
41
+ certs = []
42
+
43
+ # This is based on a patch submitted to openssl:
44
+ # http://www.mail-archive.com/openssl-dev@openssl.org/msg26958.html
45
+ ptr = FFI::Pointer::NULL
46
+ store = CertOpenSystemStoreA(nil, "ROOT")
47
+ begin
48
+ while (ptr = CertEnumCertificatesInStore(store, ptr)) and not ptr.null?
49
+ context = CERT_CONTEXT.new(ptr)
50
+ cert_buf = context[:pbCertEncoded].read_bytes(context[:cbCertEncoded])
51
+ begin
52
+ certs << OpenSSL::X509::Certificate.new(cert_buf)
53
+ rescue => detail
54
+ warn("Failed to import root certificate: #{detail.inspect}")
55
+ end
56
+ end
57
+ ensure
58
+ CertCloseStore(store, 0)
59
+ end
60
+
61
+ certs
62
+ end
63
+
64
+ private
65
+
66
+ # typedef ULONG_PTR HCRYPTPROV_LEGACY;
67
+ # typedef void *HCERTSTORE;
68
+
69
+ class CERT_CONTEXT < FFI::Struct
70
+ layout(
71
+ :dwCertEncodingType, :dword,
72
+ :pbCertEncoded, :pointer,
73
+ :cbCertEncoded, :dword,
74
+ :pCertInfo, :pointer,
75
+ :hCertStore, :handle
76
+ )
77
+ end
78
+
79
+ # HCERTSTORE
80
+ # WINAPI
81
+ # CertOpenSystemStoreA(
82
+ # __in_opt HCRYPTPROV_LEGACY hProv,
83
+ # __in LPCSTR szSubsystemProtocol
84
+ # );
85
+ ffi_lib :crypt32
86
+ attach_function :CertOpenSystemStoreA, [:pointer, :string], :handle
87
+
88
+ # PCCERT_CONTEXT
89
+ # WINAPI
90
+ # CertEnumCertificatesInStore(
91
+ # __in HCERTSTORE hCertStore,
92
+ # __in_opt PCCERT_CONTEXT pPrevCertContext
93
+ # );
94
+ ffi_lib :crypt32
95
+ attach_function :CertEnumCertificatesInStore, [:handle, :pointer], :pointer
96
+
97
+ # BOOL
98
+ # WINAPI
99
+ # CertCloseStore(
100
+ # __in_opt HCERTSTORE hCertStore,
101
+ # __in DWORD dwFlags
102
+ # );
103
+ ffi_lib :crypt32
104
+ attach_function :CertCloseStore, [:handle, :dword], :bool
105
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/restclient/version', __FILE__)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'rest-client'
7
+ s.version = RestClient::VERSION
8
+ s.authors = ['REST Client Team']
9
+ s.description = 'A simple HTTP and REST client for Ruby, inspired by the Sinatra microframework style of specifying actions: get, put, post, delete.'
10
+ s.license = 'MIT'
11
+ s.email = 'discuss@rest-client.groups.io'
12
+ s.executables = ['restclient']
13
+ s.extra_rdoc_files = ['README.md', 'history.md']
14
+ s.files = `git ls-files -z`.split("\0")
15
+ s.test_files = `git ls-files -z spec/`.split("\0")
16
+ s.homepage = 'https://github.com/rest-client/rest-client'
17
+ s.summary = 'Simple HTTP and REST client for Ruby, inspired by microframework syntax for specifying actions.'
18
+
19
+ s.add_development_dependency('webmock', '~> 2.0')
20
+ s.add_development_dependency('rspec', '~> 3.0')
21
+ s.add_development_dependency('pry', '~> 0')
22
+ s.add_development_dependency('pry-doc', '~> 0')
23
+ s.add_development_dependency('rdoc', '>= 2.4.2', '< 6.0')
24
+ s.add_development_dependency('rubocop', '~> 0.49')
25
+
26
+ s.add_dependency('http-accept', '>= 1.7.0', '< 2.0')
27
+ s.add_dependency('http-cookie', '>= 1.0.2', '< 2.0')
28
+ s.add_dependency('mime-types', '>= 1.16', '< 4.0')
29
+ s.add_dependency('netrc', '~> 0.8')
30
+
31
+ s.required_ruby_version = '>= 2.0.0'
32
+ end
@@ -0,0 +1,19 @@
1
+ #
2
+ # Gemspec for Windows platforms. We can't put these in the main gemspec because
3
+ # it results in bundler platform hell when trying to build the gem.
4
+ #
5
+ # Set $BUILD_PLATFORM when calling gem build with this gemspec to build for
6
+ # Windows platforms like x86-mingw32.
7
+ #
8
+ s = eval(File.read(File.join(File.dirname(__FILE__), 'rest-client.gemspec')))
9
+
10
+ platform = ENV['BUILD_PLATFORM'] || RUBY_PLATFORM
11
+
12
+ case platform
13
+ when /(mingw32|mswin32)/
14
+ # ffi is needed for RestClient::Windows::RootCerts
15
+ s.add_dependency('ffi', '~> 1.9')
16
+ s.platform = platform
17
+ end
18
+
19
+ s
data/spec/ISS.jpg ADDED
Binary file
data/spec/helpers.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'uri'
2
+
3
+ module Helpers
4
+
5
+ # @param [Hash] opts A hash of methods, passed directly to the double
6
+ # definition. Use this to stub other required methods.
7
+ #
8
+ # @return double for Net::HTTPResponse
9
+ def res_double(opts={})
10
+ instance_double('Net::HTTPResponse', {to_hash: {}, body: 'response body'}.merge(opts))
11
+ end
12
+
13
+ # Given a Net::HTTPResponse or double and a Request or double, create a
14
+ # RestClient::Response object.
15
+ #
16
+ # @param net_http_res_double an rspec double for Net::HTTPResponse
17
+ # @param request A RestClient::Request or rspec double
18
+ #
19
+ # @return [RestClient::Response]
20
+ #
21
+ def response_from_res_double(net_http_res_double, request=nil, duration: 1)
22
+ request ||= request_double()
23
+ start_time = Time.now - duration
24
+
25
+ response = RestClient::Response.create(net_http_res_double.body, net_http_res_double, request, start_time)
26
+
27
+ # mock duration to ensure it gets the value we expect
28
+ allow(response).to receive(:duration).and_return(duration)
29
+
30
+ response
31
+ end
32
+
33
+ # Redirect stderr to a string for the duration of the passed block.
34
+ def fake_stderr
35
+ original_stderr = $stderr
36
+ $stderr = StringIO.new
37
+ yield
38
+ $stderr.string
39
+ ensure
40
+ $stderr = original_stderr
41
+ end
42
+
43
+ # Create a double for RestClient::Request
44
+ def request_double(url: 'http://example.com', method: 'get')
45
+ instance_double('RestClient::Request',
46
+ url: url, uri: URI.parse(url), method: method, user: nil, password: nil,
47
+ cookie_jar: HTTP::CookieJar.new, redirection_history: nil,
48
+ args: {url: url, method: method})
49
+ end
50
+
51
+ def test_image_path
52
+ File.dirname(__FILE__) + "/ISS.jpg"
53
+ end
54
+ end
@@ -0,0 +1 @@
1
+ require_relative '../spec_helper'
@@ -0,0 +1,22 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh
3
+ MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
4
+ d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
5
+ QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT
6
+ MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
7
+ b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG
8
+ 9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB
9
+ CSD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W6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls
20
+ YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
21
+ CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
22
+ -----END CERTIFICATE-----
@@ -0,0 +1,8 @@
1
+ The CA path symlinks can be created by c_rehash(1ssl).
2
+
3
+ But in order for the tests to work on Windows, they have to be regular files.
4
+ You can turn them all into regular files by running this on a GNU system:
5
+
6
+ for file in $(find . -type l); do
7
+ cp -iv --remove-destination $(readlink -e $file) $file
8
+ done
@@ -0,0 +1,22 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh
3
+ MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
4
+ d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
5
+ QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT
6
+ MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
7
+ b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG
8
+ 9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB
9
+ CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97
10
+ nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt
11
+ 43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P
12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0jnvT0Lwdd8KkMaOIG+YD/is
10
+ I19wKTakyYbnsZogy1Olhec9vn2a/iRFM9x2Fe0PonFkTGUugWhFpwIDAQABMA0G
11
+ CSqGSIb3DQEBAgUAA4GBALtMEivPLCYATxQT3ab7/AoRhIzzKBxnki98tsX63/Do
12
+ lbwdj2wsqFHMc9ikwFPwTtYmwHYBV4GSXiHx0bH/59AhWM1pF+NEHJwZRDmJXNyc
13
+ AA9WjQKZ7aKQRUzkuxCkPfAyAw7xzvjoyVGM5mKf5p/AfbdynMk2OmufTqj/ZA1k
14
+ -----END CERTIFICATE-----
@@ -0,0 +1,8 @@
1
+ The CA path symlinks can be created by c_rehash(1ssl).
2
+
3
+ But in order for the tests to work on Windows, they have to be regular files.
4
+ You can turn them all into regular files by running this on a GNU system:
5
+
6
+ for file in $(find . -type l); do
7
+ cp -iv --remove-destination $(readlink -e $file) $file
8
+ done
@@ -0,0 +1,14 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIICPDCCAaUCEHC65B0Q2Sk0tjjKewPMur8wDQYJKoZIhvcNAQECBQAwXzELMAkG
3
+ A1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFz
4
+ cyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2
5
+ MDEyOTAwMDAwMFoXDTI4MDgwMTIzNTk1OVowXzELMAkGA1UEBhMCVVMxFzAVBgNV
6
+ BAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQcmlt
7
+ YXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUAA4GN
8
+ ADCBiQKBgQDJXFme8huKARS0EN8EQNvjV69qRUCPhAwL0TPZ2RHP7gJYHyX3KqhE
9
+ BarsAx94f56TuZoAqiN91qyFomNFx3InzPRMxnVx0jnvT0Lwdd8KkMaOIG+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ZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4
13
+ gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO
14
+ BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR
15
+ TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw
16
+ DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr
17
+ hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg
18
+ 06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF
19
+ PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls
20
+ YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
21
+ CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
22
+ -----END CERTIFICATE-----
@@ -0,0 +1,128 @@
1
+ require_relative '_lib'
2
+ require 'json'
3
+
4
+ require 'zlib'
5
+
6
+ describe RestClient::Request do
7
+ before(:all) do
8
+ WebMock.disable!
9
+ end
10
+
11
+ after(:all) do
12
+ WebMock.enable!
13
+ end
14
+
15
+ def default_httpbin_url
16
+ # add a hack to work around java/jruby bug
17
+ # java.lang.RuntimeException: Could not generate DH keypair with backtrace
18
+ # Also (2017-04-09) Travis Jruby versions have a broken CA keystore
19
+ if ENV['TRAVIS_RUBY_VERSION'] =~ /\Ajruby-/
20
+ 'http://httpbin.org/'
21
+ else
22
+ 'https://httpbin.org/'
23
+ end
24
+ end
25
+
26
+ def httpbin(suffix='')
27
+ url = ENV.fetch('HTTPBIN_URL', default_httpbin_url)
28
+ unless url.end_with?('/')
29
+ url += '/'
30
+ end
31
+
32
+ url + suffix
33
+ end
34
+
35
+ def execute_httpbin(suffix, opts={})
36
+ opts = {url: httpbin(suffix)}.merge(opts)
37
+ RestClient::Request.execute(opts)
38
+ end
39
+
40
+ def execute_httpbin_json(suffix, opts={})
41
+ JSON.parse(execute_httpbin(suffix, opts))
42
+ end
43
+
44
+ describe '.execute' do
45
+ it 'sends a user agent' do
46
+ data = execute_httpbin_json('user-agent', method: :get)
47
+ expect(data['user-agent']).to match(/rest-client/)
48
+ end
49
+
50
+ it 'receives cookies on 302' do
51
+ expect {
52
+ execute_httpbin('cookies/set?foo=bar', method: :get, max_redirects: 0)
53
+ }.to raise_error(RestClient::Found) { |ex|
54
+ expect(ex.http_code).to eq 302
55
+ expect(ex.response.cookies['foo']).to eq 'bar'
56
+ }
57
+ end
58
+
59
+ it 'passes along cookies through 302' do
60
+ data = execute_httpbin_json('cookies/set?foo=bar', method: :get)
61
+ expect(data).to have_key('cookies')
62
+ expect(data['cookies']['foo']).to eq 'bar'
63
+ end
64
+
65
+ it 'handles quote wrapped cookies' do
66
+ expect {
67
+ execute_httpbin('cookies/set?foo=' + CGI.escape('"bar:baz"'),
68
+ method: :get, max_redirects: 0)
69
+ }.to raise_error(RestClient::Found) { |ex|
70
+ expect(ex.http_code).to eq 302
71
+ expect(ex.response.cookies['foo']).to eq '"bar:baz"'
72
+ }
73
+ end
74
+
75
+ it 'sends basic auth' do
76
+ user = 'user'
77
+ pass = 'pass'
78
+
79
+ data = execute_httpbin_json("basic-auth/#{user}/#{pass}", method: :get, user: user, password: pass)
80
+ expect(data).to eq({'authenticated' => true, 'user' => user})
81
+
82
+ expect {
83
+ execute_httpbin_json("basic-auth/#{user}/#{pass}", method: :get, user: user, password: 'badpass')
84
+ }.to raise_error(RestClient::Unauthorized) { |ex|
85
+ expect(ex.http_code).to eq 401
86
+ }
87
+ end
88
+
89
+ it 'handles gzipped/deflated responses' do
90
+ [['gzip', 'gzipped'], ['deflate', 'deflated']].each do |encoding, var|
91
+ raw = execute_httpbin(encoding, method: :get)
92
+
93
+ begin
94
+ data = JSON.parse(raw)
95
+ rescue StandardError
96
+ puts "Failed to parse: " + raw.inspect
97
+ raise
98
+ end
99
+
100
+ expect(data['method']).to eq 'GET'
101
+ expect(data.fetch(var)).to be true
102
+ end
103
+ end
104
+
105
+ it 'does not uncompress response when accept-encoding is set' do
106
+ # == gzip ==
107
+ raw = execute_httpbin('gzip', method: :get, headers: {accept_encoding: 'gzip, deflate'})
108
+
109
+ # check for gzip magic number
110
+ expect(raw.body).to start_with("\x1F\x8B".b)
111
+
112
+ decoded = Zlib::GzipReader.new(StringIO.new(raw.body)).read
113
+ parsed = JSON.parse(decoded)
114
+
115
+ expect(parsed['method']).to eq 'GET'
116
+ expect(parsed.fetch('gzipped')).to be true
117
+
118
+ # == delate ==
119
+ raw = execute_httpbin('deflate', method: :get, headers: {accept_encoding: 'gzip, deflate'})
120
+
121
+ decoded = Zlib::Inflate.new.inflate(raw.body)
122
+ parsed = JSON.parse(decoded)
123
+
124
+ expect(parsed['method']).to eq 'GET'
125
+ expect(parsed.fetch('deflated')).to be true
126
+ end
127
+ end
128
+ end