From 9f32fd3e9a0566e9258dda883e3ecf6f5474096d Mon Sep 17 00:00:00 2001 From: aamine Date: Mon, 12 Jun 2000 16:42:46 +0000 Subject: 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 --- lib/net/http.rb | 73 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 19 deletions(-) (limited to 'lib/net/http.rb') diff --git a/lib/net/http.rb b/lib/net/http.rb index d364237956..40f6238d50 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 + "#" + 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 + "#" + end + def get( path, u_header ) return unless begin_critical request sprintf('GET %s HTTP/%s', path, HTTPVersion), u_header -- cgit v1.2.3