httparty 0.13.0 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.editorconfig +18 -0
- data/.github/workflows/ci.yml +26 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +92 -0
- data/.rubocop_todo.yml +124 -0
- data/CONTRIBUTING.md +23 -0
- data/Changelog.md +557 -0
- data/Gemfile +15 -3
- data/Guardfile +4 -3
- data/README.md +24 -25
- data/Rakefile +5 -7
- data/bin/httparty +20 -14
- data/docs/README.md +191 -0
- data/examples/README.md +89 -0
- data/examples/aaws.rb +10 -6
- data/examples/basic.rb +6 -10
- data/examples/body_stream.rb +14 -0
- data/examples/crack.rb +2 -2
- data/examples/custom_parsers.rb +6 -5
- data/examples/delicious.rb +8 -8
- data/examples/google.rb +2 -2
- data/examples/headers_and_user_agents.rb +7 -3
- data/examples/idn.rb +10 -0
- data/examples/logging.rb +36 -0
- data/examples/microsoft_graph.rb +52 -0
- data/examples/multipart.rb +22 -0
- data/examples/nokogiri_html_parser.rb +0 -3
- data/examples/peer_cert.rb +9 -0
- data/examples/rescue_json.rb +17 -0
- data/examples/rubyurl.rb +3 -3
- data/examples/stackexchange.rb +24 -0
- data/examples/stream_download.rb +26 -0
- data/examples/tripit_sign_in.rb +20 -9
- data/examples/twitter.rb +7 -7
- data/examples/whoismyrep.rb +1 -1
- data/httparty.gemspec +13 -9
- data/lib/httparty/connection_adapter.rb +105 -25
- data/lib/httparty/cookie_hash.rb +10 -9
- data/lib/httparty/decompressor.rb +102 -0
- data/lib/httparty/exceptions.rb +8 -2
- data/lib/httparty/hash_conversions.rb +39 -19
- data/lib/httparty/headers_processor.rb +32 -0
- data/lib/httparty/logger/apache_formatter.rb +47 -0
- data/lib/httparty/logger/curl_formatter.rb +93 -0
- data/lib/httparty/logger/logger.rb +22 -10
- data/lib/httparty/logger/logstash_formatter.rb +61 -0
- data/lib/httparty/module_inheritable_attributes.rb +6 -4
- data/lib/httparty/net_digest_auth.rb +76 -25
- data/lib/httparty/parser.rb +28 -15
- data/lib/httparty/request/body.rb +105 -0
- data/lib/httparty/request/multipart_boundary.rb +13 -0
- data/lib/httparty/request.rb +218 -130
- data/lib/httparty/response/headers.rb +23 -19
- data/lib/httparty/response.rb +99 -15
- data/lib/httparty/response_fragment.rb +21 -0
- data/lib/httparty/text_encoder.rb +72 -0
- data/lib/httparty/utils.rb +13 -0
- data/lib/httparty/version.rb +3 -1
- data/lib/httparty.rb +191 -83
- data/website/css/common.css +1 -1
- data/website/index.html +3 -3
- metadata +50 -120
- data/.travis.yml +0 -7
- data/History +0 -303
- data/features/basic_authentication.feature +0 -20
- data/features/command_line.feature +0 -7
- data/features/deals_with_http_error_codes.feature +0 -26
- data/features/digest_authentication.feature +0 -20
- data/features/handles_compressed_responses.feature +0 -27
- data/features/handles_multiple_formats.feature +0 -57
- data/features/steps/env.rb +0 -22
- data/features/steps/httparty_response_steps.rb +0 -52
- data/features/steps/httparty_steps.rb +0 -35
- data/features/steps/mongrel_helper.rb +0 -94
- data/features/steps/remote_service_steps.rb +0 -74
- data/features/supports_redirection.feature +0 -22
- data/features/supports_timeout_option.feature +0 -13
- data/lib/httparty/core_extensions.rb +0 -32
- data/lib/httparty/logger/apache_logger.rb +0 -22
- data/lib/httparty/logger/curl_logger.rb +0 -48
- data/spec/fixtures/delicious.xml +0 -23
- data/spec/fixtures/empty.xml +0 -0
- data/spec/fixtures/google.html +0 -3
- data/spec/fixtures/ssl/generate.sh +0 -29
- data/spec/fixtures/ssl/generated/1fe462c2.0 +0 -16
- 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/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 -298
- data/spec/httparty/cookie_hash_spec.rb +0 -83
- data/spec/httparty/exception_spec.rb +0 -23
- data/spec/httparty/logger/apache_logger_spec.rb +0 -26
- data/spec/httparty/logger/curl_logger_spec.rb +0 -18
- data/spec/httparty/logger/logger_spec.rb +0 -22
- data/spec/httparty/net_digest_auth_spec.rb +0 -152
- data/spec/httparty/parser_spec.rb +0 -165
- data/spec/httparty/request_spec.rb +0 -631
- data/spec/httparty/response_spec.rb +0 -221
- data/spec/httparty/ssl_spec.rb +0 -74
- data/spec/httparty_spec.rb +0 -764
- data/spec/spec.opts +0 -2
- data/spec/spec_helper.rb +0 -37
- 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 -43
@@ -1,221 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
describe HTTParty::Response do
|
4
|
-
before do
|
5
|
-
@last_modified = Date.new(2010, 1, 15).to_s
|
6
|
-
@content_length = '1024'
|
7
|
-
@request_object = HTTParty::Request.new Net::HTTP::Get, '/'
|
8
|
-
@response_object = Net::HTTPOK.new('1.1', 200, 'OK')
|
9
|
-
@response_object.stub(:body => "{foo:'bar'}")
|
10
|
-
@response_object['last-modified'] = @last_modified
|
11
|
-
@response_object['content-length'] = @content_length
|
12
|
-
@parsed_response = lambda { {"foo" => "bar"} }
|
13
|
-
@response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
|
14
|
-
end
|
15
|
-
|
16
|
-
describe ".underscore" do
|
17
|
-
it "works with one capitalized word" do
|
18
|
-
HTTParty::Response.underscore("Accepted").should == "accepted"
|
19
|
-
end
|
20
|
-
|
21
|
-
it "works with titlecase" do
|
22
|
-
HTTParty::Response.underscore("BadGateway").should == "bad_gateway"
|
23
|
-
end
|
24
|
-
|
25
|
-
it "works with all caps" do
|
26
|
-
HTTParty::Response.underscore("OK").should == "ok"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "initialization" do
|
31
|
-
it "should set the Net::HTTP Response" do
|
32
|
-
@response.response.should == @response_object
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should set body" do
|
36
|
-
@response.body.should == @response_object.body
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should set code" do
|
40
|
-
@response.code.should.to_s == @response_object.code
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should set code as a Fixnum" do
|
44
|
-
@response.code.should be_an_instance_of(Fixnum)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
it "returns response headers" do
|
49
|
-
response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
|
50
|
-
response.headers.should == {'last-modified' => [@last_modified], 'content-length' => [@content_length]}
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should send missing methods to delegate" do
|
54
|
-
response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
|
55
|
-
response['foo'].should == 'bar'
|
56
|
-
end
|
57
|
-
|
58
|
-
it "response to request" do
|
59
|
-
response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
|
60
|
-
response.respond_to?(:request).should be_true
|
61
|
-
end
|
62
|
-
|
63
|
-
it "responds to response" do
|
64
|
-
response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
|
65
|
-
response.respond_to?(:response).should be_true
|
66
|
-
end
|
67
|
-
|
68
|
-
it "responds to body" do
|
69
|
-
response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
|
70
|
-
response.respond_to?(:body).should be_true
|
71
|
-
end
|
72
|
-
|
73
|
-
it "responds to headers" do
|
74
|
-
response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
|
75
|
-
response.respond_to?(:headers).should be_true
|
76
|
-
end
|
77
|
-
|
78
|
-
it "responds to parsed_response" do
|
79
|
-
response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
|
80
|
-
response.respond_to?(:parsed_response).should be_true
|
81
|
-
end
|
82
|
-
|
83
|
-
it "responds to anything parsed_response responds to" do
|
84
|
-
response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
|
85
|
-
response.respond_to?(:[]).should be_true
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should be able to iterate if it is array" do
|
89
|
-
response = HTTParty::Response.new(@request_object, @response_object, lambda { [{'foo' => 'bar'}, {'foo' => 'baz'}] })
|
90
|
-
response.size.should == 2
|
91
|
-
expect {
|
92
|
-
response.each { |item| }
|
93
|
-
}.to_not raise_error
|
94
|
-
end
|
95
|
-
|
96
|
-
it "allows headers to be accessed by mixed-case names in hash notation" do
|
97
|
-
response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
|
98
|
-
response.headers['Content-LENGTH'].should == @content_length
|
99
|
-
end
|
100
|
-
|
101
|
-
it "returns a comma-delimited value when multiple values exist" do
|
102
|
-
@response_object.add_field 'set-cookie', 'csrf_id=12345; path=/'
|
103
|
-
@response_object.add_field 'set-cookie', '_github_ses=A123CdE; path=/'
|
104
|
-
response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
|
105
|
-
response.headers['set-cookie'].should == "csrf_id=12345; path=/, _github_ses=A123CdE; path=/"
|
106
|
-
end
|
107
|
-
|
108
|
-
# Backwards-compatibility - previously, #headers returned a Hash
|
109
|
-
it "responds to hash methods" do
|
110
|
-
response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
|
111
|
-
hash_methods = {}.methods - response.headers.methods
|
112
|
-
hash_methods.each do |method_name|
|
113
|
-
response.headers.respond_to?(method_name).should be_true
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe "semantic methods for response codes" do
|
118
|
-
def response_mock(klass)
|
119
|
-
response = klass.new('', '', '')
|
120
|
-
response.stub(:body)
|
121
|
-
response
|
122
|
-
end
|
123
|
-
|
124
|
-
context "major codes" do
|
125
|
-
it "is information" do
|
126
|
-
net_response = response_mock(Net::HTTPInformation)
|
127
|
-
response = HTTParty::Response.new(@request_object, net_response, '')
|
128
|
-
response.information?.should be_true
|
129
|
-
end
|
130
|
-
|
131
|
-
it "is success" do
|
132
|
-
net_response = response_mock(Net::HTTPSuccess)
|
133
|
-
response = HTTParty::Response.new(@request_object, net_response, '')
|
134
|
-
response.success?.should be_true
|
135
|
-
end
|
136
|
-
|
137
|
-
it "is redirection" do
|
138
|
-
net_response = response_mock(Net::HTTPRedirection)
|
139
|
-
response = HTTParty::Response.new(@request_object, net_response, '')
|
140
|
-
response.redirection?.should be_true
|
141
|
-
end
|
142
|
-
|
143
|
-
it "is client error" do
|
144
|
-
net_response = response_mock(Net::HTTPClientError)
|
145
|
-
response = HTTParty::Response.new(@request_object, net_response, '')
|
146
|
-
response.client_error?.should be_true
|
147
|
-
end
|
148
|
-
|
149
|
-
it "is server error" do
|
150
|
-
net_response = response_mock(Net::HTTPServerError)
|
151
|
-
response = HTTParty::Response.new(@request_object, net_response, '')
|
152
|
-
response.server_error?.should be_true
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
context "for specific codes" do
|
157
|
-
SPECIFIC_CODES = {
|
158
|
-
:accepted? => Net::HTTPAccepted,
|
159
|
-
:bad_gateway? => Net::HTTPBadGateway,
|
160
|
-
:bad_request? => Net::HTTPBadRequest,
|
161
|
-
:conflict? => Net::HTTPConflict,
|
162
|
-
:continue? => Net::HTTPContinue,
|
163
|
-
:created? => Net::HTTPCreated,
|
164
|
-
:expectation_failed? => Net::HTTPExpectationFailed,
|
165
|
-
:forbidden? => Net::HTTPForbidden,
|
166
|
-
:found? => Net::HTTPFound,
|
167
|
-
:gateway_time_out? => Net::HTTPGatewayTimeOut,
|
168
|
-
:gone? => Net::HTTPGone,
|
169
|
-
:internal_server_error? => Net::HTTPInternalServerError,
|
170
|
-
:length_required? => Net::HTTPLengthRequired,
|
171
|
-
:method_not_allowed? => Net::HTTPMethodNotAllowed,
|
172
|
-
:moved_permanently? => Net::HTTPMovedPermanently,
|
173
|
-
:multiple_choice? => Net::HTTPMultipleChoice,
|
174
|
-
:no_content? => Net::HTTPNoContent,
|
175
|
-
:non_authoritative_information? => Net::HTTPNonAuthoritativeInformation,
|
176
|
-
:not_acceptable? => Net::HTTPNotAcceptable,
|
177
|
-
:not_found? => Net::HTTPNotFound,
|
178
|
-
:not_implemented? => Net::HTTPNotImplemented,
|
179
|
-
:not_modified? => Net::HTTPNotModified,
|
180
|
-
:ok? => Net::HTTPOK,
|
181
|
-
:partial_content? => Net::HTTPPartialContent,
|
182
|
-
:payment_required? => Net::HTTPPaymentRequired,
|
183
|
-
:precondition_failed? => Net::HTTPPreconditionFailed,
|
184
|
-
:proxy_authentication_required? => Net::HTTPProxyAuthenticationRequired,
|
185
|
-
:request_entity_too_large? => Net::HTTPRequestEntityTooLarge,
|
186
|
-
:request_time_out? => Net::HTTPRequestTimeOut,
|
187
|
-
:request_uri_too_long? => Net::HTTPRequestURITooLong,
|
188
|
-
:requested_range_not_satisfiable? => Net::HTTPRequestedRangeNotSatisfiable,
|
189
|
-
:reset_content? => Net::HTTPResetContent,
|
190
|
-
:see_other? => Net::HTTPSeeOther,
|
191
|
-
:service_unavailable? => Net::HTTPServiceUnavailable,
|
192
|
-
:switch_protocol? => Net::HTTPSwitchProtocol,
|
193
|
-
:temporary_redirect? => Net::HTTPTemporaryRedirect,
|
194
|
-
:unauthorized? => Net::HTTPUnauthorized,
|
195
|
-
:unsupported_media_type? => Net::HTTPUnsupportedMediaType,
|
196
|
-
:use_proxy? => Net::HTTPUseProxy,
|
197
|
-
:version_not_supported? => Net::HTTPVersionNotSupported
|
198
|
-
}
|
199
|
-
|
200
|
-
# Ruby 2.0, new name for this response.
|
201
|
-
if RUBY_VERSION >= "2.0.0" && ::RUBY_PLATFORM != "java"
|
202
|
-
SPECIFIC_CODES[:multiple_choices?] = Net::HTTPMultipleChoices
|
203
|
-
end
|
204
|
-
|
205
|
-
SPECIFIC_CODES.each do |method, klass|
|
206
|
-
it "responds to #{method}" do
|
207
|
-
net_response = response_mock(klass)
|
208
|
-
response = HTTParty::Response.new(@request_object, net_response, '')
|
209
|
-
response.__send__(method).should be_true
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
describe "headers" do
|
216
|
-
it "can initialize without headers" do
|
217
|
-
headers = HTTParty::Response::Headers.new
|
218
|
-
headers.should == {}
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
data/spec/httparty/ssl_spec.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
describe HTTParty::Request do
|
4
|
-
context "SSL certificate verification" do
|
5
|
-
before do
|
6
|
-
FakeWeb.allow_net_connect = true
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
FakeWeb.allow_net_connect = false
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should fail when no trusted CA list is specified, by default" do
|
14
|
-
lambda do
|
15
|
-
ssl_verify_test(nil, nil, "selfsigned.crt")
|
16
|
-
end.should raise_error OpenSSL::SSL::SSLError
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should work when no trusted CA list is specified, when the verify option is set to false" do
|
20
|
-
ssl_verify_test(nil, nil, "selfsigned.crt", :verify => false).should == {'success' => true}
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should fail when no trusted CA list is specified, with a bogus hostname, by default" do
|
24
|
-
lambda do
|
25
|
-
ssl_verify_test(nil, nil, "bogushost.crt")
|
26
|
-
end.should raise_error OpenSSL::SSL::SSLError
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should work when no trusted CA list is specified, even with a bogus hostname, when the verify option is set to true" do
|
30
|
-
ssl_verify_test(nil, nil, "bogushost.crt", :verify => false).should == {'success' => true}
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should work when using ssl_ca_file with a self-signed CA" do
|
34
|
-
ssl_verify_test(:ssl_ca_file, "selfsigned.crt", "selfsigned.crt").should == {'success' => true}
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should work when using ssl_ca_file with a certificate authority" do
|
38
|
-
ssl_verify_test(:ssl_ca_file, "ca.crt", "server.crt").should == {'success' => true}
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should work when using ssl_ca_path with a certificate authority" do
|
42
|
-
http = Net::HTTP.new('www.google.com', 443)
|
43
|
-
response = stub(Net::HTTPResponse, :[] => '', :body => '', :to_hash => {})
|
44
|
-
http.stub(:request).and_return(response)
|
45
|
-
Net::HTTP.should_receive(:new).with('www.google.com', 443).and_return(http)
|
46
|
-
http.should_receive(:ca_path=).with('/foo/bar')
|
47
|
-
HTTParty.get('https://www.google.com', :ssl_ca_path => '/foo/bar')
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should fail when using ssl_ca_file and the server uses an unrecognized certificate authority" do
|
51
|
-
lambda do
|
52
|
-
ssl_verify_test(:ssl_ca_file, "ca.crt", "selfsigned.crt")
|
53
|
-
end.should raise_error(OpenSSL::SSL::SSLError)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should fail when using ssl_ca_path and the server uses an unrecognized certificate authority" do
|
57
|
-
lambda do
|
58
|
-
ssl_verify_test(:ssl_ca_path, ".", "selfsigned.crt")
|
59
|
-
end.should raise_error(OpenSSL::SSL::SSLError)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should fail when using ssl_ca_file and the server uses a bogus hostname" do
|
63
|
-
lambda do
|
64
|
-
ssl_verify_test(:ssl_ca_file, "ca.crt", "bogushost.crt")
|
65
|
-
end.should raise_error(OpenSSL::SSL::SSLError)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should fail when using ssl_ca_path and the server uses a bogus hostname" do
|
69
|
-
lambda do
|
70
|
-
ssl_verify_test(:ssl_ca_path, ".", "bogushost.crt")
|
71
|
-
end.should raise_error(OpenSSL::SSL::SSLError)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|