rubysl-net-http 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +0 -1
- data/.travis.yml +7 -0
- data/README.md +2 -2
- data/Rakefile +0 -1
- data/lib/net/http.rb +1 -0
- data/lib/rubysl/net/http.rb +2 -0
- data/lib/rubysl/net/http/http.rb +2290 -0
- data/lib/rubysl/net/http/https.rb +173 -0
- data/lib/{rubysl-net-http → rubysl/net/http}/version.rb +2 -2
- data/rubysl-net-http.gemspec +18 -18
- data/spec/HTTPBadResponse_spec.rb +7 -0
- data/spec/HTTPError_spec.rb +11 -0
- data/spec/HTTPFatalError_spec.rb +11 -0
- data/spec/HTTPHeaderSyntaxError_spec.rb +7 -0
- data/spec/HTTPRetriableError_spec.rb +11 -0
- data/spec/HTTPServerException_spec.rb +11 -0
- data/spec/http/Proxy_spec.rb +34 -0
- data/spec/http/active_spec.rb +7 -0
- data/spec/http/address_spec.rb +8 -0
- data/spec/http/close_on_empty_response_spec.rb +9 -0
- data/spec/http/copy_spec.rb +26 -0
- data/spec/http/default_port_spec.rb +7 -0
- data/spec/http/delete_spec.rb +26 -0
- data/spec/http/finish_spec.rb +30 -0
- data/spec/http/fixtures/http_server.rb +97 -0
- data/spec/http/get2_spec.rb +7 -0
- data/spec/http/get_print_spec.rb +28 -0
- data/spec/http/get_response_spec.rb +28 -0
- data/spec/http/get_spec.rb +52 -0
- data/spec/http/head2_spec.rb +8 -0
- data/spec/http/head_spec.rb +30 -0
- data/spec/http/http_default_port_spec.rb +7 -0
- data/spec/http/https_default_port_spec.rb +7 -0
- data/spec/http/initialize_spec.rb +45 -0
- data/spec/http/inspect_spec.rb +25 -0
- data/spec/http/is_version_1_1_spec.rb +6 -0
- data/spec/http/is_version_1_2_spec.rb +6 -0
- data/spec/http/lock_spec.rb +26 -0
- data/spec/http/mkcol_spec.rb +26 -0
- data/spec/http/move_spec.rb +30 -0
- data/spec/http/new_spec.rb +96 -0
- data/spec/http/newobj_spec.rb +47 -0
- data/spec/http/open_timeout_spec.rb +23 -0
- data/spec/http/options_spec.rb +30 -0
- data/spec/http/port_spec.rb +8 -0
- data/spec/http/post2_spec.rb +7 -0
- data/spec/http/post_form_spec.rb +20 -0
- data/spec/http/post_spec.rb +43 -0
- data/spec/http/propfind_spec.rb +29 -0
- data/spec/http/proppatch_spec.rb +29 -0
- data/spec/http/proxy_address_spec.rb +30 -0
- data/spec/http/proxy_class_spec.rb +8 -0
- data/spec/http/proxy_pass_spec.rb +38 -0
- data/spec/http/proxy_port_spec.rb +38 -0
- data/spec/http/proxy_user_spec.rb +38 -0
- data/spec/http/put2_spec.rb +7 -0
- data/spec/http/put_spec.rb +29 -0
- data/spec/http/read_timeout_spec.rb +23 -0
- data/spec/http/request_get_spec.rb +7 -0
- data/spec/http/request_head_spec.rb +7 -0
- data/spec/http/request_post_spec.rb +7 -0
- data/spec/http/request_put_spec.rb +7 -0
- data/spec/http/request_spec.rb +114 -0
- data/spec/http/request_types_spec.rb +253 -0
- data/spec/http/send_request_spec.rb +123 -0
- data/spec/http/set_debug_output_spec.rb +34 -0
- data/spec/http/shared/request_get.rb +49 -0
- data/spec/http/shared/request_head.rb +49 -0
- data/spec/http/shared/request_post.rb +49 -0
- data/spec/http/shared/request_put.rb +49 -0
- data/spec/http/shared/started.rb +28 -0
- data/spec/http/shared/version_1_1.rb +19 -0
- data/spec/http/shared/version_1_2.rb +6 -0
- data/spec/http/socket_type_spec.rb +7 -0
- data/spec/http/start_spec.rb +115 -0
- data/spec/http/started_spec.rb +7 -0
- data/spec/http/trace_spec.rb +29 -0
- data/spec/http/unlock_spec.rb +29 -0
- data/spec/http/use_ssl_spec.rb +8 -0
- data/spec/http/version_1_1_spec.rb +21 -0
- data/spec/http/version_1_2_spec.rb +19 -0
- data/spec/httpexceptions/fixtures/classes.rb +5 -0
- data/spec/httpexceptions/initialize_spec.rb +16 -0
- data/spec/httpexceptions/response_spec.rb +9 -0
- data/spec/httpgenericrequest/body_exist_spec.rb +26 -0
- data/spec/httpgenericrequest/body_spec.rb +29 -0
- data/spec/httpgenericrequest/body_stream_spec.rb +31 -0
- data/spec/httpgenericrequest/exec_spec.rb +135 -0
- data/spec/httpgenericrequest/inspect_spec.rb +24 -0
- data/spec/httpgenericrequest/method_spec.rb +14 -0
- data/spec/httpgenericrequest/path_spec.rb +11 -0
- data/spec/httpgenericrequest/request_body_permitted_spec.rb +11 -0
- data/spec/httpgenericrequest/response_body_permitted_spec.rb +11 -0
- data/spec/httpgenericrequest/set_body_internal_spec.rb +20 -0
- data/spec/httpheader/add_field_spec.rb +30 -0
- data/spec/httpheader/basic_auth_spec.rb +13 -0
- data/spec/httpheader/canonical_each_spec.rb +7 -0
- data/spec/httpheader/chunked_spec.rb +21 -0
- data/spec/httpheader/content_length_spec.rb +53 -0
- data/spec/httpheader/content_range_spec.rb +33 -0
- data/spec/httpheader/content_type_spec.rb +25 -0
- data/spec/httpheader/delete_spec.rb +29 -0
- data/spec/httpheader/each_capitalized_name_spec.rb +44 -0
- data/spec/httpheader/each_capitalized_spec.rb +8 -0
- data/spec/httpheader/each_header_spec.rb +7 -0
- data/spec/httpheader/each_key_spec.rb +7 -0
- data/spec/httpheader/each_name_spec.rb +7 -0
- data/spec/httpheader/each_spec.rb +7 -0
- data/spec/httpheader/each_value_spec.rb +45 -0
- data/spec/httpheader/element_reference_spec.rb +38 -0
- data/spec/httpheader/element_set_spec.rb +40 -0
- data/spec/httpheader/fetch_spec.rb +68 -0
- data/spec/httpheader/fixtures/classes.rb +11 -0
- data/spec/httpheader/form_data_spec.rb +7 -0
- data/spec/httpheader/get_fields_spec.rb +38 -0
- data/spec/httpheader/initialize_http_header_spec.rb +28 -0
- data/spec/httpheader/key_spec.rb +20 -0
- data/spec/httpheader/length_spec.rb +7 -0
- data/spec/httpheader/main_type_spec.rb +23 -0
- data/spec/httpheader/proxy_basic_auth_spec.rb +13 -0
- data/spec/httpheader/range_length_spec.rb +31 -0
- data/spec/httpheader/range_spec.rb +47 -0
- data/spec/httpheader/set_content_type_spec.rb +7 -0
- data/spec/httpheader/set_form_data_spec.rb +7 -0
- data/spec/httpheader/set_range_spec.rb +7 -0
- data/spec/httpheader/shared/each_capitalized.rb +42 -0
- data/spec/httpheader/shared/each_header.rb +42 -0
- data/spec/httpheader/shared/each_name.rb +39 -0
- data/spec/httpheader/shared/set_content_type.rb +20 -0
- data/spec/httpheader/shared/set_form_data.rb +27 -0
- data/spec/httpheader/shared/set_range.rb +89 -0
- data/spec/httpheader/shared/size.rb +18 -0
- data/spec/httpheader/size_spec.rb +7 -0
- data/spec/httpheader/sub_type_spec.rb +31 -0
- data/spec/httpheader/to_hash_spec.rb +24 -0
- data/spec/httpheader/type_params_spec.rb +23 -0
- data/spec/httprequest/initialize_spec.rb +44 -0
- data/spec/httpresponse/body_permitted_spec.rb +12 -0
- data/spec/httpresponse/body_spec.rb +6 -0
- data/spec/httpresponse/code_spec.rb +23 -0
- data/spec/httpresponse/code_type_spec.rb +23 -0
- data/spec/httpresponse/entity_spec.rb +6 -0
- data/spec/httpresponse/error_spec.rb +23 -0
- data/spec/httpresponse/error_type_spec.rb +23 -0
- data/spec/httpresponse/exception_type_spec.rb +12 -0
- data/spec/httpresponse/header_spec.rb +8 -0
- data/spec/httpresponse/http_version_spec.rb +11 -0
- data/spec/httpresponse/initialize_spec.rb +10 -0
- data/spec/httpresponse/inspect_spec.rb +14 -0
- data/spec/httpresponse/message_spec.rb +8 -0
- data/spec/httpresponse/msg_spec.rb +8 -0
- data/spec/httpresponse/read_body_spec.rb +85 -0
- data/spec/httpresponse/read_header_spec.rb +8 -0
- data/spec/httpresponse/read_new_spec.rb +21 -0
- data/spec/httpresponse/reading_body_spec.rb +57 -0
- data/spec/httpresponse/response_spec.rb +8 -0
- data/spec/httpresponse/shared/body.rb +18 -0
- data/spec/httpresponse/to_ary_spec.rb +25 -0
- data/spec/httpresponse/value_spec.rb +23 -0
- metadata +366 -88
- data/lib/rubysl-net-http.rb +0 -9
@@ -0,0 +1,20 @@
|
|
1
|
+
describe :net_httpheader_set_content_type, :shared => true do
|
2
|
+
describe "when passed type, params" do
|
3
|
+
before(:each) do
|
4
|
+
@headers = NetHTTPHeaderSpecs::Example.new
|
5
|
+
end
|
6
|
+
|
7
|
+
it "sets the 'Content-Type' header entry based on the passed type and params" do
|
8
|
+
@headers.send(@method, "text/html")
|
9
|
+
@headers["Content-Type"].should == "text/html"
|
10
|
+
|
11
|
+
@headers.send(@method, "text/html", "charset" => "utf-8")
|
12
|
+
@headers["Content-Type"].should == "text/html; charset=utf-8"
|
13
|
+
|
14
|
+
@headers.send(@method, "text/html", "charset" => "utf-8", "rubyspec" => "rocks")
|
15
|
+
@headers["Content-Type"].should =~ %r[text/html]
|
16
|
+
@headers["Content-Type"].should =~ %r[charset=utf-8]
|
17
|
+
@headers["Content-Type"].should =~ %r[rubyspec=rocks]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
describe :net_httpheader_set_form_data, :shared => true do
|
2
|
+
before(:each) do
|
3
|
+
@headers = NetHTTPHeaderSpecs::Example.new
|
4
|
+
end
|
5
|
+
|
6
|
+
describe "when passed params" do
|
7
|
+
it "automatically set the 'Content-Type' to 'application/x-www-form-urlencoded'" do
|
8
|
+
@headers.send(@method, "cmd" => "search", "q" => "ruby", "max" => "50")
|
9
|
+
@headers["Content-Type"].should == "application/x-www-form-urlencoded"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "sets self's body based on the passed form parameters" do
|
13
|
+
@headers.send(@method, "cmd" => "search", "q" => "ruby", "max" => "50")
|
14
|
+
@headers.body.split("&").sort.should == ["cmd=search", "max=50", "q=ruby"]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "when passed params, separator" do
|
19
|
+
it "sets self's body based on the passed form parameters and the passed separator" do
|
20
|
+
@headers.send(@method, {"cmd" => "search", "q" => "ruby", "max" => "50"}, "&")
|
21
|
+
@headers.body.split("&").sort.should == ["cmd=search", "max=50", "q=ruby"]
|
22
|
+
|
23
|
+
@headers.send(@method, {"cmd" => "search", "q" => "ruby", "max" => "50"}, ";")
|
24
|
+
@headers.body.split(";").sort.should == ["cmd=search", "max=50", "q=ruby"]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
describe :net_httpheader_set_range, :shared => true do
|
2
|
+
before(:each) do
|
3
|
+
@headers = NetHTTPHeaderSpecs::Example.new
|
4
|
+
end
|
5
|
+
|
6
|
+
describe "when passed nil" do
|
7
|
+
it "returns nil" do
|
8
|
+
@headers.send(@method, nil).should be_nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it "deletes the 'Range' header entry" do
|
12
|
+
@headers["Range"] = "bytes 0-499/1234"
|
13
|
+
@headers.send(@method, nil)
|
14
|
+
@headers["Range"].should be_nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "when passed Numeric" do
|
19
|
+
it "sets the 'Range' header entry based on the passed Numeric" do
|
20
|
+
@headers.send(@method, 10)
|
21
|
+
@headers["Range"].should == "bytes=0-9"
|
22
|
+
|
23
|
+
@headers.send(@method, -10)
|
24
|
+
@headers["Range"].should == "bytes=-10"
|
25
|
+
|
26
|
+
@headers.send(@method, 10.9)
|
27
|
+
@headers["Range"].should == "bytes=0-9"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "when passed Range" do
|
32
|
+
it "sets the 'Range' header entry based on the passed Range" do
|
33
|
+
@headers.send(@method, 10..200)
|
34
|
+
@headers["Range"].should == "bytes=10-200"
|
35
|
+
|
36
|
+
@headers.send(@method, 1..5)
|
37
|
+
@headers["Range"].should == "bytes=1-5"
|
38
|
+
|
39
|
+
@headers.send(@method, 1...5)
|
40
|
+
@headers["Range"].should == "bytes=1-4"
|
41
|
+
|
42
|
+
@headers.send(@method, 234..567)
|
43
|
+
@headers["Range"].should == "bytes=234-567"
|
44
|
+
|
45
|
+
@headers.send(@method, -5..-1)
|
46
|
+
@headers["Range"].should == "bytes=-5"
|
47
|
+
|
48
|
+
@headers.send(@method, 1..-1)
|
49
|
+
@headers["Range"].should == "bytes=1-"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "raises a Net::HTTPHeaderSyntaxError when the first Range element is negative" do
|
53
|
+
lambda { @headers.send(@method, -10..5) }.should raise_error(Net::HTTPHeaderSyntaxError)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "raises a Net::HTTPHeaderSyntaxError when the last Range element is negative" do
|
57
|
+
lambda { @headers.send(@method, 10..-5) }.should raise_error(Net::HTTPHeaderSyntaxError)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "raises a Net::HTTPHeaderSyntaxError when the last Range element is smaller than the first" do
|
61
|
+
lambda { @headers.send(@method, 10..5) }.should raise_error(Net::HTTPHeaderSyntaxError)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "when passed start, end" do
|
66
|
+
it "sets the 'Range' header entry based on the passed start and length values" do
|
67
|
+
@headers.send(@method, 10, 200)
|
68
|
+
@headers["Range"].should == "bytes=10-209"
|
69
|
+
|
70
|
+
@headers.send(@method, 1, 5)
|
71
|
+
@headers["Range"].should == "bytes=1-5"
|
72
|
+
|
73
|
+
@headers.send(@method, 234, 567)
|
74
|
+
@headers["Range"].should == "bytes=234-800"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "raises a Net::HTTPHeaderSyntaxError when start is negative" do
|
78
|
+
lambda { @headers.send(@method, -10, 5) }.should raise_error(Net::HTTPHeaderSyntaxError)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "raises a Net::HTTPHeaderSyntaxError when start + length is negative" do
|
82
|
+
lambda { @headers.send(@method, 10, -15) }.should raise_error(Net::HTTPHeaderSyntaxError)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "raises a Net::HTTPHeaderSyntaxError when length is negative" do
|
86
|
+
lambda { @headers.send(@method, 10, -4) }.should raise_error(Net::HTTPHeaderSyntaxError)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
describe :net_httpheader_size, :shared => true do
|
2
|
+
before(:each) do
|
3
|
+
@headers = NetHTTPHeaderSpecs::Example.new
|
4
|
+
end
|
5
|
+
|
6
|
+
it "returns the number of header entries in self" do
|
7
|
+
@headers.send(@method).should eql(0)
|
8
|
+
|
9
|
+
@headers["a"] = "b"
|
10
|
+
@headers.send(@method).should eql(1)
|
11
|
+
|
12
|
+
@headers["b"] = "b"
|
13
|
+
@headers.send(@method).should eql(2)
|
14
|
+
|
15
|
+
@headers["c"] = "c"
|
16
|
+
@headers.send(@method).should eql(3)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
|
4
|
+
describe "Net::HTTPHeader#sub_type" do
|
5
|
+
before(:each) do
|
6
|
+
@headers = NetHTTPHeaderSpecs::Example.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns the 'sub-content-type', as per 'Content-Type' header entry" do
|
10
|
+
@headers["Content-Type"] = "text/html"
|
11
|
+
@headers.sub_type.should == "html"
|
12
|
+
|
13
|
+
@headers["Content-Type"] = "application/pdf"
|
14
|
+
@headers.sub_type.should == "pdf"
|
15
|
+
|
16
|
+
@headers["Content-Type"] = "text/html;charset=utf-8"
|
17
|
+
@headers.sub_type.should == "html"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns nil if no 'sub-content-type' is set" do
|
21
|
+
@headers["Content-Type"] = "text"
|
22
|
+
@headers.sub_type.should be_nil
|
23
|
+
|
24
|
+
@headers["Content-Type"] = "text;charset=utf-8"
|
25
|
+
@headers.sub_type.should be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns nil if the 'Content-Type' header entry does not exist" do
|
29
|
+
@headers.sub_type.should be_nil
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
|
4
|
+
describe "Net::HTTPHeader#to_hash" do
|
5
|
+
before(:each) do
|
6
|
+
@headers = NetHTTPHeaderSpecs::Example.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns a Hash representing all Header entries (keys in lower case, values as arrays)" do
|
10
|
+
@headers.to_hash.should == {}
|
11
|
+
|
12
|
+
@headers["My-Header"] = "test"
|
13
|
+
@headers.to_hash.should == { "my-header" => ["test"] }
|
14
|
+
|
15
|
+
@headers.add_field("My-Header", "another test")
|
16
|
+
@headers.to_hash.should == { "my-header" => ["test", "another test"] }
|
17
|
+
end
|
18
|
+
|
19
|
+
it "does not allow modifying the headers from the returned hash" do
|
20
|
+
@headers.to_hash["my-header"] = ["test"]
|
21
|
+
@headers.to_hash.should == {}
|
22
|
+
@headers.key?("my-header").should be_false
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
|
4
|
+
describe "Net::HTTPHeader#type_params" do
|
5
|
+
before(:each) do
|
6
|
+
@headers = NetHTTPHeaderSpecs::Example.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns additional 'Content-Type' information as a Hash" do
|
10
|
+
@headers["Content-Type"] = "text/html;charset=utf-8"
|
11
|
+
@headers.type_params.should == {"charset" => "utf-8"}
|
12
|
+
|
13
|
+
@headers["Content-Type"] = "text/html; charset=utf-8; rubyspec=rocks"
|
14
|
+
@headers.type_params.should == {"charset" => "utf-8", "rubyspec" => "rocks"}
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns an empty Hash when no additional 'Content-Type' information is set" do
|
18
|
+
@headers.type_params.should == {}
|
19
|
+
|
20
|
+
@headers["Content-Type"] = "text/html"
|
21
|
+
@headers.type_params.should == {}
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module NetHTTPRequestSpecs
|
4
|
+
class TestRequest < Net::HTTPRequest
|
5
|
+
METHOD = "TEST"
|
6
|
+
REQUEST_HAS_BODY = false
|
7
|
+
RESPONSE_HAS_BODY = true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "Net::HTTPRequest#initialize" do
|
12
|
+
before(:each) do
|
13
|
+
@req = NetHTTPRequestSpecs::TestRequest.allocate
|
14
|
+
end
|
15
|
+
|
16
|
+
it "uses the METHOD constants to set the request method" do
|
17
|
+
@req.send(:initialize, "/some/path")
|
18
|
+
@req.method.should == "TEST"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "uses the REQUEST_HAS_BODY to set whether the Request has a body or not" do
|
22
|
+
@req.send(:initialize, "/some/path")
|
23
|
+
@req.request_body_permitted?.should be_false
|
24
|
+
end
|
25
|
+
|
26
|
+
it "uses the RESPONSE_HAS_BODY to set whether the Response can have a body or not" do
|
27
|
+
@req.send(:initialize, "/some/path")
|
28
|
+
@req.response_body_permitted?.should be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "when passed path" do
|
32
|
+
it "sets self's path to the passed path" do
|
33
|
+
@req.send(:initialize, "/some/path")
|
34
|
+
@req.path.should == "/some/path"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "when passed path, headers" do
|
39
|
+
it "uses the passed headers Hash to initialize self's header entries" do
|
40
|
+
@req.send(:initialize, "/some/path", "Content-Type" => "text/html")
|
41
|
+
@req["Content-Type"].should == "text/html"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
describe "Net::HTTPResponse.body_permitted?" do
|
4
|
+
it "returns true if this response type can have a response body" do
|
5
|
+
Net::HTTPUnknownResponse.body_permitted?.should == true
|
6
|
+
Net::HTTPInformation.body_permitted?.should == false
|
7
|
+
Net::HTTPSuccess.body_permitted?.should == true
|
8
|
+
Net::HTTPRedirection.body_permitted?.should == true
|
9
|
+
Net::HTTPClientError.body_permitted?.should == true
|
10
|
+
Net::HTTPServerError.body_permitted?.should == true
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
describe "Net::HTTPResponse#code" do
|
4
|
+
it "returns the result code string" do
|
5
|
+
res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
|
6
|
+
res.code.should == "???"
|
7
|
+
|
8
|
+
res = Net::HTTPInformation.new("1.0", "1xx", "test response")
|
9
|
+
res.code.should == "1xx"
|
10
|
+
|
11
|
+
res = Net::HTTPSuccess.new("1.0", "2xx", "test response")
|
12
|
+
res.code.should == "2xx"
|
13
|
+
|
14
|
+
res = Net::HTTPRedirection.new("1.0", "3xx", "test response")
|
15
|
+
res.code.should == "3xx"
|
16
|
+
|
17
|
+
res = Net::HTTPClientError.new("1.0", "4xx", "test response")
|
18
|
+
res.code.should == "4xx"
|
19
|
+
|
20
|
+
res = Net::HTTPServerError.new("1.0", "5xx", "test response")
|
21
|
+
res.code.should == "5xx"
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
describe "Net::HTTPResponse#code_type" do
|
4
|
+
it "returns self's class" do
|
5
|
+
res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
|
6
|
+
res.code_type.should == Net::HTTPUnknownResponse
|
7
|
+
|
8
|
+
res = Net::HTTPInformation.new("1.0", "1xx", "test response")
|
9
|
+
res.code_type.should == Net::HTTPInformation
|
10
|
+
|
11
|
+
res = Net::HTTPSuccess.new("1.0", "2xx", "test response")
|
12
|
+
res.code_type.should == Net::HTTPSuccess
|
13
|
+
|
14
|
+
res = Net::HTTPRedirection.new("1.0", "3xx", "test response")
|
15
|
+
res.code_type.should == Net::HTTPRedirection
|
16
|
+
|
17
|
+
res = Net::HTTPClientError.new("1.0", "4xx", "test response")
|
18
|
+
res.code_type.should == Net::HTTPClientError
|
19
|
+
|
20
|
+
res = Net::HTTPServerError.new("1.0", "5xx", "test response")
|
21
|
+
res.code_type.should == Net::HTTPServerError
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
describe "Net::HTTPResponse#error!" do
|
4
|
+
it "raises self's class 'EXCEPTION_TYPE' Exception" do
|
5
|
+
res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
|
6
|
+
lambda { res.error! }.should raise_error(Net::HTTPError)
|
7
|
+
|
8
|
+
res = Net::HTTPInformation.new("1.0", "1xx", "test response")
|
9
|
+
lambda { res.error! }.should raise_error(Net::HTTPError)
|
10
|
+
|
11
|
+
res = Net::HTTPSuccess.new("1.0", "2xx", "test response")
|
12
|
+
lambda { res.error! }.should raise_error(Net::HTTPError)
|
13
|
+
|
14
|
+
res = Net::HTTPRedirection.new("1.0", "3xx", "test response")
|
15
|
+
lambda { res.error! }.should raise_error(Net::HTTPRetriableError)
|
16
|
+
|
17
|
+
res = Net::HTTPClientError.new("1.0", "4xx", "test response")
|
18
|
+
lambda { res.error! }.should raise_error(Net::HTTPServerException)
|
19
|
+
|
20
|
+
res = Net::HTTPServerError.new("1.0", "5xx", "test response")
|
21
|
+
lambda { res.error! }.should raise_error(Net::HTTPFatalError)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
describe "Net::HTTPResponse#error_type" do
|
4
|
+
it "returns self's class 'EXCEPTION_TYPE' constant" do
|
5
|
+
res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
|
6
|
+
res.error_type.should == Net::HTTPError
|
7
|
+
|
8
|
+
res = Net::HTTPInformation.new("1.0", "1xx", "test response")
|
9
|
+
res.error_type.should == Net::HTTPError
|
10
|
+
|
11
|
+
res = Net::HTTPSuccess.new("1.0", "2xx", "test response")
|
12
|
+
res.error_type.should == Net::HTTPError
|
13
|
+
|
14
|
+
res = Net::HTTPRedirection.new("1.0", "3xx", "test response")
|
15
|
+
res.error_type.should == Net::HTTPRetriableError
|
16
|
+
|
17
|
+
res = Net::HTTPClientError.new("1.0", "4xx", "test response")
|
18
|
+
res.error_type.should == Net::HTTPServerException
|
19
|
+
|
20
|
+
res = Net::HTTPServerError.new("1.0", "5xx", "test response")
|
21
|
+
res.error_type.should == Net::HTTPFatalError
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
describe "Net::HTTPResponse.exception_type" do
|
4
|
+
it "returns self's 'EXCEPTION_TYPE' constant" do
|
5
|
+
Net::HTTPUnknownResponse.exception_type.should == Net::HTTPError
|
6
|
+
Net::HTTPInformation.exception_type.should == Net::HTTPError
|
7
|
+
Net::HTTPSuccess.exception_type.should == Net::HTTPError
|
8
|
+
Net::HTTPRedirection.exception_type.should == Net::HTTPRetriableError
|
9
|
+
Net::HTTPClientError.exception_type.should == Net::HTTPServerException
|
10
|
+
Net::HTTPServerError.exception_type.should == Net::HTTPFatalError
|
11
|
+
end
|
12
|
+
end
|