summaryrefslogtreecommitdiff
path: root/lib/net/http.rb
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-06-12 16:42:46 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-06-12 16:42:46 +0000
commit9f32fd3e9a0566e9258dda883e3ecf6f5474096d (patch)
tree3594690de77e31bad8bd108ea699117f3b7e9ddc /lib/net/http.rb
parentb0ed08600a71784085b9b4621a4c4fcdbe0ae1cd (diff)
o protocol.rb, smtp.rb, pop.rb, http.rb: define all#inspect()
o protocol.rb, smtp.rb, pop.rb, http.rb: modify/add documents git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@746 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net/http.rb')
-rw-r--r--lib/net/http.rb73
1 files changed, 54 insertions, 19 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb
index d364237..40f6238 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -8,16 +8,6 @@ This file is derived from "http-access.rb".
This library is distributed under the terms of the Ruby license.
You can freely distribute/modify this library.
-=end
-
-require 'net/protocol'
-
-
-module Net
-
- class HTTPBadResponse < StandardError; end
-
-=begin
= class HTTP
@@ -50,7 +40,10 @@ module Net
get data from "path" on connecting host.
"header" must be a Hash like { 'Accept' => '*/*', ... }.
Data is written to "dest" by using "<<" method.
- This method returns Net::HTTPResponse object and "dest".
+ This method returns Net::HTTPResponse object, and "dest".
+
+ # example
+ response, body = http.get( '/index.html' )
If called as iterator, give a part String of entity body.
@@ -59,15 +52,15 @@ module Net
raised. At that time, you can get Response object from
execption object. (same in head/post)
- ex.
-
+ # example
begin
- head, body = http.get(...)
- rescue ProtoRetriableError
+ response, body = http.get(...)
+ rescue Net::ProtoRetriableError
response = $!.data
...
end
+
: head( path, header = nil )
get only header from "path" on connecting host.
"header" is a Hash like { 'Accept' => '*/*', ... }.
@@ -94,25 +87,46 @@ module Net
"header" must be a Hash like { 'Accept' => '*/*', ... }.
This method gives HTTPReadAdapter object to block.
+ ex.
+
+ http.get2( '/index.html' ) do |f|
+ # f is a HTTPReadAdapter object
+ f.header
+ f.body
+ end
+
: head2( path, header = nil )
send HEAD request for "path".
"header" must be a Hash like { 'Accept' => '*/*', ... }.
The difference between "head" method is that
"head2" does not raise exceptions.
+ ex.
+
+ http.head2( '/index.html' ) do |f|
+ f.header
+ end
+
: post2( path, data, header = nil ) {|adapter| .... }
post "data"(must be String now) to "path".
"header" must be a Hash like { 'Accept' => '*/*', ... }.
This method gives HTTPReadAdapter object to block.
+ ex.
+
+ http.post2( '/index.html', 'data data data...' ) do |f|
+ f.header
+ f.body
+ end
+
= class HTTPResponse
-== Methods
-
HTTP response object.
All "key" is case-insensitive.
+== Methods
+
: code
HTTP result code. For example, '302'
@@ -134,6 +148,9 @@ All "key" is case-insensitive.
: each {|name,value| .... }
iterate for each field name and value pair
+: body
+ "dest" argument for HTTP#get, post, put
+
= class HTTPReadAdapter
@@ -154,6 +171,14 @@ All "key" is case-insensitive.
=end
+require 'net/protocol'
+
+
+module Net
+
+ class HTTPBadResponse < StandardError; end
+
+
class HTTP < Protocol
protocol_param :port, '80'
@@ -320,6 +345,10 @@ All "key" is case-insensitive.
@header = @body = nil
end
+ def inspect
+ "#<#{type}>"
+ end
+
def header
unless @header then
@header = @command.get_response
@@ -358,6 +387,10 @@ All "key" is case-insensitive.
attr_reader :http_body_exist
attr_accessor :body
+ def inspect
+ "#<Net::HTTPResponse #{code}>"
+ end
+
def []( key )
@data[ key.downcase ]
end
@@ -463,10 +496,12 @@ All "key" is case-insensitive.
super sock
end
-
attr_reader :http_version
-
+ def inspect
+ "#<Net::HTTPCommand>"
+ end
+
def get( path, u_header )
return unless begin_critical
request sprintf('GET %s HTTP/%s', path, HTTPVersion), u_header