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.
Files changed (162) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +0 -1
  3. data/.travis.yml +7 -0
  4. data/README.md +2 -2
  5. data/Rakefile +0 -1
  6. data/lib/net/http.rb +1 -0
  7. data/lib/rubysl/net/http.rb +2 -0
  8. data/lib/rubysl/net/http/http.rb +2290 -0
  9. data/lib/rubysl/net/http/https.rb +173 -0
  10. data/lib/{rubysl-net-http → rubysl/net/http}/version.rb +2 -2
  11. data/rubysl-net-http.gemspec +18 -18
  12. data/spec/HTTPBadResponse_spec.rb +7 -0
  13. data/spec/HTTPError_spec.rb +11 -0
  14. data/spec/HTTPFatalError_spec.rb +11 -0
  15. data/spec/HTTPHeaderSyntaxError_spec.rb +7 -0
  16. data/spec/HTTPRetriableError_spec.rb +11 -0
  17. data/spec/HTTPServerException_spec.rb +11 -0
  18. data/spec/http/Proxy_spec.rb +34 -0
  19. data/spec/http/active_spec.rb +7 -0
  20. data/spec/http/address_spec.rb +8 -0
  21. data/spec/http/close_on_empty_response_spec.rb +9 -0
  22. data/spec/http/copy_spec.rb +26 -0
  23. data/spec/http/default_port_spec.rb +7 -0
  24. data/spec/http/delete_spec.rb +26 -0
  25. data/spec/http/finish_spec.rb +30 -0
  26. data/spec/http/fixtures/http_server.rb +97 -0
  27. data/spec/http/get2_spec.rb +7 -0
  28. data/spec/http/get_print_spec.rb +28 -0
  29. data/spec/http/get_response_spec.rb +28 -0
  30. data/spec/http/get_spec.rb +52 -0
  31. data/spec/http/head2_spec.rb +8 -0
  32. data/spec/http/head_spec.rb +30 -0
  33. data/spec/http/http_default_port_spec.rb +7 -0
  34. data/spec/http/https_default_port_spec.rb +7 -0
  35. data/spec/http/initialize_spec.rb +45 -0
  36. data/spec/http/inspect_spec.rb +25 -0
  37. data/spec/http/is_version_1_1_spec.rb +6 -0
  38. data/spec/http/is_version_1_2_spec.rb +6 -0
  39. data/spec/http/lock_spec.rb +26 -0
  40. data/spec/http/mkcol_spec.rb +26 -0
  41. data/spec/http/move_spec.rb +30 -0
  42. data/spec/http/new_spec.rb +96 -0
  43. data/spec/http/newobj_spec.rb +47 -0
  44. data/spec/http/open_timeout_spec.rb +23 -0
  45. data/spec/http/options_spec.rb +30 -0
  46. data/spec/http/port_spec.rb +8 -0
  47. data/spec/http/post2_spec.rb +7 -0
  48. data/spec/http/post_form_spec.rb +20 -0
  49. data/spec/http/post_spec.rb +43 -0
  50. data/spec/http/propfind_spec.rb +29 -0
  51. data/spec/http/proppatch_spec.rb +29 -0
  52. data/spec/http/proxy_address_spec.rb +30 -0
  53. data/spec/http/proxy_class_spec.rb +8 -0
  54. data/spec/http/proxy_pass_spec.rb +38 -0
  55. data/spec/http/proxy_port_spec.rb +38 -0
  56. data/spec/http/proxy_user_spec.rb +38 -0
  57. data/spec/http/put2_spec.rb +7 -0
  58. data/spec/http/put_spec.rb +29 -0
  59. data/spec/http/read_timeout_spec.rb +23 -0
  60. data/spec/http/request_get_spec.rb +7 -0
  61. data/spec/http/request_head_spec.rb +7 -0
  62. data/spec/http/request_post_spec.rb +7 -0
  63. data/spec/http/request_put_spec.rb +7 -0
  64. data/spec/http/request_spec.rb +114 -0
  65. data/spec/http/request_types_spec.rb +253 -0
  66. data/spec/http/send_request_spec.rb +123 -0
  67. data/spec/http/set_debug_output_spec.rb +34 -0
  68. data/spec/http/shared/request_get.rb +49 -0
  69. data/spec/http/shared/request_head.rb +49 -0
  70. data/spec/http/shared/request_post.rb +49 -0
  71. data/spec/http/shared/request_put.rb +49 -0
  72. data/spec/http/shared/started.rb +28 -0
  73. data/spec/http/shared/version_1_1.rb +19 -0
  74. data/spec/http/shared/version_1_2.rb +6 -0
  75. data/spec/http/socket_type_spec.rb +7 -0
  76. data/spec/http/start_spec.rb +115 -0
  77. data/spec/http/started_spec.rb +7 -0
  78. data/spec/http/trace_spec.rb +29 -0
  79. data/spec/http/unlock_spec.rb +29 -0
  80. data/spec/http/use_ssl_spec.rb +8 -0
  81. data/spec/http/version_1_1_spec.rb +21 -0
  82. data/spec/http/version_1_2_spec.rb +19 -0
  83. data/spec/httpexceptions/fixtures/classes.rb +5 -0
  84. data/spec/httpexceptions/initialize_spec.rb +16 -0
  85. data/spec/httpexceptions/response_spec.rb +9 -0
  86. data/spec/httpgenericrequest/body_exist_spec.rb +26 -0
  87. data/spec/httpgenericrequest/body_spec.rb +29 -0
  88. data/spec/httpgenericrequest/body_stream_spec.rb +31 -0
  89. data/spec/httpgenericrequest/exec_spec.rb +135 -0
  90. data/spec/httpgenericrequest/inspect_spec.rb +24 -0
  91. data/spec/httpgenericrequest/method_spec.rb +14 -0
  92. data/spec/httpgenericrequest/path_spec.rb +11 -0
  93. data/spec/httpgenericrequest/request_body_permitted_spec.rb +11 -0
  94. data/spec/httpgenericrequest/response_body_permitted_spec.rb +11 -0
  95. data/spec/httpgenericrequest/set_body_internal_spec.rb +20 -0
  96. data/spec/httpheader/add_field_spec.rb +30 -0
  97. data/spec/httpheader/basic_auth_spec.rb +13 -0
  98. data/spec/httpheader/canonical_each_spec.rb +7 -0
  99. data/spec/httpheader/chunked_spec.rb +21 -0
  100. data/spec/httpheader/content_length_spec.rb +53 -0
  101. data/spec/httpheader/content_range_spec.rb +33 -0
  102. data/spec/httpheader/content_type_spec.rb +25 -0
  103. data/spec/httpheader/delete_spec.rb +29 -0
  104. data/spec/httpheader/each_capitalized_name_spec.rb +44 -0
  105. data/spec/httpheader/each_capitalized_spec.rb +8 -0
  106. data/spec/httpheader/each_header_spec.rb +7 -0
  107. data/spec/httpheader/each_key_spec.rb +7 -0
  108. data/spec/httpheader/each_name_spec.rb +7 -0
  109. data/spec/httpheader/each_spec.rb +7 -0
  110. data/spec/httpheader/each_value_spec.rb +45 -0
  111. data/spec/httpheader/element_reference_spec.rb +38 -0
  112. data/spec/httpheader/element_set_spec.rb +40 -0
  113. data/spec/httpheader/fetch_spec.rb +68 -0
  114. data/spec/httpheader/fixtures/classes.rb +11 -0
  115. data/spec/httpheader/form_data_spec.rb +7 -0
  116. data/spec/httpheader/get_fields_spec.rb +38 -0
  117. data/spec/httpheader/initialize_http_header_spec.rb +28 -0
  118. data/spec/httpheader/key_spec.rb +20 -0
  119. data/spec/httpheader/length_spec.rb +7 -0
  120. data/spec/httpheader/main_type_spec.rb +23 -0
  121. data/spec/httpheader/proxy_basic_auth_spec.rb +13 -0
  122. data/spec/httpheader/range_length_spec.rb +31 -0
  123. data/spec/httpheader/range_spec.rb +47 -0
  124. data/spec/httpheader/set_content_type_spec.rb +7 -0
  125. data/spec/httpheader/set_form_data_spec.rb +7 -0
  126. data/spec/httpheader/set_range_spec.rb +7 -0
  127. data/spec/httpheader/shared/each_capitalized.rb +42 -0
  128. data/spec/httpheader/shared/each_header.rb +42 -0
  129. data/spec/httpheader/shared/each_name.rb +39 -0
  130. data/spec/httpheader/shared/set_content_type.rb +20 -0
  131. data/spec/httpheader/shared/set_form_data.rb +27 -0
  132. data/spec/httpheader/shared/set_range.rb +89 -0
  133. data/spec/httpheader/shared/size.rb +18 -0
  134. data/spec/httpheader/size_spec.rb +7 -0
  135. data/spec/httpheader/sub_type_spec.rb +31 -0
  136. data/spec/httpheader/to_hash_spec.rb +24 -0
  137. data/spec/httpheader/type_params_spec.rb +23 -0
  138. data/spec/httprequest/initialize_spec.rb +44 -0
  139. data/spec/httpresponse/body_permitted_spec.rb +12 -0
  140. data/spec/httpresponse/body_spec.rb +6 -0
  141. data/spec/httpresponse/code_spec.rb +23 -0
  142. data/spec/httpresponse/code_type_spec.rb +23 -0
  143. data/spec/httpresponse/entity_spec.rb +6 -0
  144. data/spec/httpresponse/error_spec.rb +23 -0
  145. data/spec/httpresponse/error_type_spec.rb +23 -0
  146. data/spec/httpresponse/exception_type_spec.rb +12 -0
  147. data/spec/httpresponse/header_spec.rb +8 -0
  148. data/spec/httpresponse/http_version_spec.rb +11 -0
  149. data/spec/httpresponse/initialize_spec.rb +10 -0
  150. data/spec/httpresponse/inspect_spec.rb +14 -0
  151. data/spec/httpresponse/message_spec.rb +8 -0
  152. data/spec/httpresponse/msg_spec.rb +8 -0
  153. data/spec/httpresponse/read_body_spec.rb +85 -0
  154. data/spec/httpresponse/read_header_spec.rb +8 -0
  155. data/spec/httpresponse/read_new_spec.rb +21 -0
  156. data/spec/httpresponse/reading_body_spec.rb +57 -0
  157. data/spec/httpresponse/response_spec.rb +8 -0
  158. data/spec/httpresponse/shared/body.rb +18 -0
  159. data/spec/httpresponse/to_ary_spec.rb +25 -0
  160. data/spec/httpresponse/value_spec.rb +23 -0
  161. metadata +366 -88
  162. data/lib/rubysl-net-http.rb +0 -9
@@ -0,0 +1,173 @@
1
+ =begin
2
+
3
+ = $RCSfile$ -- SSL/TLS enhancement for Net::HTTP.
4
+
5
+ == Info
6
+ 'OpenSSL for Ruby 2' project
7
+ Copyright (C) 2001 GOTOU Yuuzou <gotoyuzo@notwork.org>
8
+ All rights reserved.
9
+
10
+ == Licence
11
+ This program is licenced under the same licence as Ruby.
12
+ (See the file 'LICENCE'.)
13
+
14
+ == Requirements
15
+ This program requires Net 1.2.0 or higher version.
16
+ You can get it from RAA or Ruby's CVS repository.
17
+
18
+ == Version
19
+ $Id$
20
+
21
+ 2001-11-06: Contiributed to Ruby/OpenSSL project.
22
+ 2004-03-06: Some code is merged in to net/http.
23
+
24
+ == Example
25
+
26
+ Here is a simple HTTP client:
27
+
28
+ require 'net/http'
29
+ require 'uri'
30
+
31
+ uri = URI.parse(ARGV[0] || 'http://localhost/')
32
+ http = Net::HTTP.new(uri.host, uri.port)
33
+ http.start {
34
+ http.request_get(uri.path) {|res|
35
+ print res.body
36
+ }
37
+ }
38
+
39
+ It can be replaced by the following code:
40
+
41
+ require 'net/https'
42
+ require 'uri'
43
+
44
+ uri = URI.parse(ARGV[0] || 'https://localhost/')
45
+ http = Net::HTTP.new(uri.host, uri.port)
46
+ http.use_ssl = true if uri.scheme == "https" # enable SSL/TLS
47
+ http.start {
48
+ http.request_get(uri.path) {|res|
49
+ print res.body
50
+ }
51
+ }
52
+
53
+ == class Net::HTTP
54
+
55
+ === Instance Methods
56
+
57
+ : use_ssl?
58
+ returns true if use SSL/TLS with HTTP.
59
+
60
+ : use_ssl=((|true_or_false|))
61
+ sets use_ssl.
62
+
63
+ : peer_cert
64
+ return the X.509 certificates the server presented.
65
+
66
+ : key, key=((|key|))
67
+ Sets an OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object.
68
+ (This method is appeared in Michal Rokos's OpenSSL extension.)
69
+
70
+ : cert, cert=((|cert|))
71
+ Sets an OpenSSL::X509::Certificate object as client certificate
72
+ (This method is appeared in Michal Rokos's OpenSSL extension).
73
+
74
+ : ca_file, ca_file=((|path|))
75
+ Sets path of a CA certification file in PEM format.
76
+ The file can contrain several CA certificats.
77
+
78
+ : ca_path, ca_path=((|path|))
79
+ Sets path of a CA certification directory containing certifications
80
+ in PEM format.
81
+
82
+ : verify_mode, verify_mode=((|mode|))
83
+ Sets the flags for server the certification verification at
84
+ begining of SSL/TLS session.
85
+ OpenSSL::SSL::VERIFY_NONE or OpenSSL::SSL::VERIFY_PEER is acceptable.
86
+
87
+ : verify_callback, verify_callback=((|proc|))
88
+ Sets the verify callback for the server certification verification.
89
+
90
+ : verify_depth, verify_depth=((|num|))
91
+ Sets the maximum depth for the certificate chain verification.
92
+
93
+ : cert_store, cert_store=((|store|))
94
+ Sets the X509::Store to verify peer certificate.
95
+
96
+ : ssl_timeout, ssl_timeout=((|sec|))
97
+ Sets the SSL timeout seconds.
98
+
99
+ =end
100
+
101
+ require 'net/http'
102
+ require 'openssl'
103
+
104
+ module Net
105
+
106
+ class HTTP
107
+ remove_method :use_ssl?
108
+ def use_ssl?
109
+ @use_ssl
110
+ end
111
+
112
+ # For backward compatibility.
113
+ alias use_ssl use_ssl?
114
+
115
+ # Turn on/off SSL.
116
+ # This flag must be set before starting session.
117
+ # If you change use_ssl value after session started,
118
+ # a Net::HTTP object raises IOError.
119
+ def use_ssl=(flag)
120
+ flag = (flag ? true : false)
121
+ raise IOError, "use_ssl value changed, but session already started" \
122
+ if started? and @use_ssl != flag
123
+ if flag and not @ssl_context
124
+ @ssl_context = OpenSSL::SSL::SSLContext.new
125
+ end
126
+ @use_ssl = flag
127
+ end
128
+
129
+ def self.ssl_context_accessor(name)
130
+ module_eval(<<-End, __FILE__, __LINE__ + 1)
131
+ def #{name}
132
+ return nil unless @ssl_context
133
+ @ssl_context.#{name}
134
+ end
135
+
136
+ def #{name}=(val)
137
+ @ssl_context ||= OpenSSL::SSL::SSLContext.new
138
+ @ssl_context.#{name} = val
139
+ end
140
+ End
141
+ end
142
+
143
+ ssl_context_accessor :key
144
+ ssl_context_accessor :cert
145
+ ssl_context_accessor :ca_file
146
+ ssl_context_accessor :ca_path
147
+ ssl_context_accessor :verify_mode
148
+ ssl_context_accessor :verify_callback
149
+ ssl_context_accessor :verify_depth
150
+ ssl_context_accessor :cert_store
151
+
152
+ def ssl_timeout
153
+ return nil unless @ssl_context
154
+ @ssl_context.timeout
155
+ end
156
+
157
+ def ssl_timeout=(sec)
158
+ raise ArgumentError, 'Net::HTTP#ssl_timeout= called but use_ssl=false' \
159
+ unless use_ssl?
160
+ @ssl_context ||= OpenSSL::SSL::SSLContext.new
161
+ @ssl_context.timeout = sec
162
+ end
163
+
164
+ # For backward compatibility
165
+ alias timeout= ssl_timeout=
166
+
167
+ def peer_cert
168
+ return nil if not use_ssl? or not @socket
169
+ @socket.io.peer_cert
170
+ end
171
+ end
172
+
173
+ end
@@ -1,7 +1,7 @@
1
1
  module RubySL
2
2
  module Net
3
- module Http
4
- VERSION = "0.0.1"
3
+ module HTTP
4
+ VERSION = "1.0.0"
5
5
  end
6
6
  end
7
7
  end
@@ -1,22 +1,22 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/rubysl-net-http/version', __FILE__)
1
+ # coding: utf-8
2
+ require './lib/rubysl/net/http/version'
3
3
 
4
- Gem::Specification.new do |gem|
5
- gem.authors = ["Brian Shirai"]
6
- gem.email = ["brixen@gmail.com"]
7
- gem.description = %q{Ruby Standard Library - net-http}
8
- gem.summary = %q{Ruby Standard Library - net-http}
9
- gem.homepage = ""
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "rubysl-net-http"
6
+ spec.version = RubySL::Net::HTTP::VERSION
7
+ spec.authors = ["Brian Shirai"]
8
+ spec.email = ["brixen@gmail.com"]
9
+ spec.description = %q{Ruby standard library net-http.}
10
+ spec.summary = %q{Ruby standard library net-http.}
11
+ spec.homepage = "https://github.com/rubysl/rubysl-net-http"
12
+ spec.license = "BSD"
10
13
 
11
- gem.files = `git ls-files`.split($\)
12
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = "rubysl-net-http"
15
- gem.require_paths = ["lib"]
16
- gem.version = RubySL::Net::Http::VERSION
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
17
18
 
18
- gem.add_runtime_dependency "redcard", "~> 1.0"
19
-
20
- gem.add_development_dependency "rake", "~> 10.0"
21
- gem.add_development_dependency "mspec", "~> 1.5"
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "mspec", "~> 1.5"
22
22
  end
@@ -0,0 +1,7 @@
1
+ require 'net/http'
2
+
3
+ describe "Net::HTTPBadResponse" do
4
+ it "is a subclass of StandardError" do
5
+ Net::HTTPBadResponse.should < StandardError
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'net/http'
2
+
3
+ describe "Net::HTTPError" do
4
+ it "is a subclass of Net::ProtocolError" do
5
+ Net::HTTPError.should < Net::ProtocolError
6
+ end
7
+
8
+ it "includes the Net::HTTPExceptions module" do
9
+ Net::HTTPError.should < Net::HTTPExceptions
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'net/http'
2
+
3
+ describe "Net::HTTPFatalError" do
4
+ it "is a subclass of Net::ProtoFatalError" do
5
+ Net::HTTPFatalError.should < Net::ProtoFatalError
6
+ end
7
+
8
+ it "includes the Net::HTTPExceptions module" do
9
+ Net::HTTPFatalError.should < Net::HTTPExceptions
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ require 'net/http'
2
+
3
+ describe "Net::HTTPHeaderSyntaxError" do
4
+ it "is a subclass of StandardError" do
5
+ Net::HTTPHeaderSyntaxError.should < StandardError
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'net/http'
2
+
3
+ describe "Net::HTTPRetriableError" do
4
+ it "is a subclass of Net::ProtoRetriableError" do
5
+ Net::HTTPRetriableError.should < Net::ProtoRetriableError
6
+ end
7
+
8
+ it "includes the Net::HTTPExceptions module" do
9
+ Net::HTTPRetriableError.should < Net::HTTPExceptions
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'net/http'
2
+
3
+ describe "Net::HTTPServerException" do
4
+ it "is a subclass of Net::ProtoServerError" do
5
+ Net::HTTPServerException.should < Net::ProtoServerError
6
+ end
7
+
8
+ it "includes the Net::HTTPExceptions module" do
9
+ Net::HTTPServerException.should < Net::HTTPExceptions
10
+ end
11
+ end
@@ -0,0 +1,34 @@
1
+ require 'net/http'
2
+
3
+ describe "Net::HTTP.Proxy" do
4
+ it "returns a new subclass of Net::HTTP" do
5
+ Net::HTTP.Proxy("localhost").should < Net::HTTP
6
+ end
7
+
8
+ it "returns Net::HTTP when the passed address is nil" do
9
+ Net::HTTP.Proxy(nil).should == Net::HTTP
10
+ end
11
+
12
+ it "sets the returned subclasses' proxy options based on the passed arguments" do
13
+ http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
14
+ http_with_proxy.proxy_address.should == "localhost"
15
+ http_with_proxy.proxy_port.should eql(1234)
16
+ http_with_proxy.proxy_user.should == "rspec"
17
+ http_with_proxy.proxy_pass.should == "rocks"
18
+ end
19
+ end
20
+
21
+ describe "Net::HTTP#proxy?" do
22
+ describe "when self is no proxy class instance" do
23
+ it "returns false" do
24
+ Net::HTTP.new("localhost", 3333).proxy?.should be_false
25
+ end
26
+ end
27
+
28
+ describe "when self is a proxy class instance" do
29
+ it "returns false" do
30
+ http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
31
+ http_with_proxy.new("localhost", 3333).proxy?.should be_true
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/http_server', __FILE__)
3
+ require File.expand_path('../shared/started', __FILE__)
4
+
5
+ describe "Net::HTTP#active?" do
6
+ it_behaves_like :net_http_started_p, :active?
7
+ end
@@ -0,0 +1,8 @@
1
+ require 'net/http'
2
+
3
+ describe "Net::HTTP#address" do
4
+ it "returns the current host name" do
5
+ net = Net::HTTP.new("localhost")
6
+ net.address.should == "localhost"
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ require 'net/http'
2
+
3
+ describe "Net::HTTP#close_on_empty_response" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
6
+
7
+ describe "Net::HTTP#close_on_empty_response=" do
8
+ it "needs to be reviewed for spec completeness"
9
+ end
@@ -0,0 +1,26 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/http_server', __FILE__)
3
+
4
+ describe "Net::HTTP#copy" do
5
+ before(:all) do
6
+ NetHTTPSpecs.start_server
7
+ end
8
+
9
+ after(:all) do
10
+ NetHTTPSpecs.stop_server
11
+ end
12
+
13
+ before(:each) do
14
+ @http = Net::HTTP.start("localhost", 3333)
15
+ end
16
+
17
+ after(:each) do
18
+ @http.finish if @http.started?
19
+ end
20
+
21
+ it "sends a COPY request to the passed path and returns the response" do
22
+ response = @http.copy("/request")
23
+ response.should be_kind_of(Net::HTTPResponse)
24
+ response.body.should == "Request type: COPY"
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ require 'net/http'
2
+
3
+ describe "Net::HTTP.default_port" do
4
+ it "returns 80" do
5
+ Net::HTTP.http_default_port.should eql(80)
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/http_server', __FILE__)
3
+
4
+ describe "Net::HTTP#delete" do
5
+ before(:all) do
6
+ NetHTTPSpecs.start_server
7
+ end
8
+
9
+ after(:all) do
10
+ NetHTTPSpecs.stop_server
11
+ end
12
+
13
+ before(:each) do
14
+ @http = Net::HTTP.start("localhost", 3333)
15
+ end
16
+
17
+ after(:each) do
18
+ @http.finish if @http.started?
19
+ end
20
+
21
+ it "sends a DELETE request to the passed path and returns the response" do
22
+ response = @http.delete("/request")
23
+ response.should be_kind_of(Net::HTTPResponse)
24
+ response.body.should == "Request type: DELETE"
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/http_server', __FILE__)
3
+
4
+ describe "Net::HTTP#finish" do
5
+ before(:all) do
6
+ NetHTTPSpecs.start_server
7
+ end
8
+
9
+ after(:all) do
10
+ NetHTTPSpecs.stop_server
11
+ end
12
+
13
+ before(:each) do
14
+ @http = Net::HTTP.new("localhost", 3333)
15
+ end
16
+
17
+ describe "when self has been started" do
18
+ it "closes the tcp connection" do
19
+ @http.start
20
+ @http.finish
21
+ @http.started?.should be_false
22
+ end
23
+ end
24
+
25
+ describe "when self has not been started yet" do
26
+ it "raises an IOError" do
27
+ lambda { @http.finish }.should raise_error(IOError)
28
+ end
29
+ end
30
+ end