* lib/net/http.rb: update document.
* lib/net/pop.rb: ditto. * lib/net/protocol.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4335 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e6c23c67e9
commit
5ae5596491
@ -1,3 +1,11 @@
|
|||||||
|
Wed Aug 6 01:18:50 2003 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
|
* lib/net/http.rb: update document.
|
||||||
|
|
||||||
|
* lib/net/pop.rb: ditto.
|
||||||
|
|
||||||
|
* lib/net/protocol.rb: ditto.
|
||||||
|
|
||||||
Tue Aug 5 17:58:57 2003 WATANABE Hirofumi <eban@ruby-lang.org>
|
Tue Aug 5 17:58:57 2003 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||||
|
|
||||||
* lib/fileutils.rb (install): should preserve timestamp only.
|
* lib/fileutils.rb (install): should preserve timestamp only.
|
||||||
|
@ -308,7 +308,7 @@ module Net
|
|||||||
80
|
80
|
||||||
end
|
end
|
||||||
|
|
||||||
def HTTP.socket_type #:nodoc:
|
def HTTP.socket_type #:nodoc: obsolete
|
||||||
InternetMessageIO
|
InternetMessageIO
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -358,8 +358,17 @@ module Net
|
|||||||
"#<#{self.class} #{@address}:#{@port} open=#{started?}>"
|
"#<#{self.class} #{@address}:#{@port} open=#{started?}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_debug_output( arg ) # :nodoc:
|
# *WARNING* This method causes serious security hole.
|
||||||
@debug_output = arg
|
# Never use this method in product code.
|
||||||
|
#
|
||||||
|
# Set an output stream for debugging.
|
||||||
|
#
|
||||||
|
# http = Net::HTTP.new
|
||||||
|
# http.set_debug_output $stderr
|
||||||
|
# http.start { .... }
|
||||||
|
#
|
||||||
|
def set_debug_output( output )
|
||||||
|
@debug_output = output
|
||||||
end
|
end
|
||||||
|
|
||||||
# The host name to connect to.
|
# The host name to connect to.
|
||||||
@ -389,7 +398,7 @@ module Net
|
|||||||
@started
|
@started
|
||||||
end
|
end
|
||||||
|
|
||||||
alias active? started? #:nodoc:
|
alias active? started? #:nodoc: obsolete
|
||||||
|
|
||||||
attr_accessor :close_on_empty_response
|
attr_accessor :close_on_empty_response
|
||||||
|
|
||||||
@ -521,8 +530,8 @@ module Net
|
|||||||
self.class.proxy_pass
|
self.class.proxy_pass
|
||||||
end
|
end
|
||||||
|
|
||||||
alias proxyaddr proxy_address #:nodoc:
|
alias proxyaddr proxy_address #:nodoc: obsolete
|
||||||
alias proxyport proxy_port #:nodoc:
|
alias proxyport proxy_port #:nodoc: obsolete
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
@ -540,7 +549,7 @@ module Net
|
|||||||
path
|
path
|
||||||
end
|
end
|
||||||
|
|
||||||
module ProxyDelta #:nodoc:
|
module ProxyDelta #:nodoc: internal use only
|
||||||
private
|
private
|
||||||
|
|
||||||
# with proxy
|
# with proxy
|
||||||
@ -687,7 +696,7 @@ module Net
|
|||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
|
||||||
def put( path, data, initheader = nil ) #:nodoc:
|
def put( path, data, initheader = nil ) #:nodoc:
|
||||||
res = request(Put.new(path, initheader), data)
|
res = request(Put.new(path, initheader), data)
|
||||||
@newimpl or res.value
|
@newimpl or res.value
|
||||||
res
|
res
|
||||||
@ -769,10 +778,10 @@ module Net
|
|||||||
request Put.new(path, initheader), data, &block
|
request Put.new(path, initheader), data, &block
|
||||||
end
|
end
|
||||||
|
|
||||||
alias get2 request_get #:nodoc:
|
alias get2 request_get #:nodoc: obsolete
|
||||||
alias head2 request_head #:nodoc:
|
alias head2 request_head #:nodoc: obsolete
|
||||||
alias post2 request_post #:nodoc:
|
alias post2 request_post #:nodoc: obsolete
|
||||||
alias put2 request_put #:nodoc:
|
alias put2 request_put #:nodoc: obsolete
|
||||||
|
|
||||||
|
|
||||||
# Sends an HTTP request to the HTTP server.
|
# Sends an HTTP request to the HTTP server.
|
||||||
@ -904,11 +913,11 @@ module Net
|
|||||||
#
|
#
|
||||||
module HTTPHeader
|
module HTTPHeader
|
||||||
|
|
||||||
def size #:nodoc:
|
def size #:nodoc: obsolete
|
||||||
@header.size
|
@header.size
|
||||||
end
|
end
|
||||||
|
|
||||||
alias length size #:nodoc:
|
alias length size #:nodoc: obsolete
|
||||||
|
|
||||||
# Returns the header field corresponding to the case-insensitive key.
|
# Returns the header field corresponding to the case-insensitive key.
|
||||||
# For example, a key of "Content-Type" might return "text/html"
|
# For example, a key of "Content-Type" might return "text/html"
|
||||||
@ -1122,8 +1131,7 @@ module Net
|
|||||||
# write
|
# write
|
||||||
#
|
#
|
||||||
|
|
||||||
# internal use only
|
def exec( sock, ver, path, body ) #:nodoc: internal use only
|
||||||
def exec( sock, ver, path, body ) #:nodoc:
|
|
||||||
if body
|
if body
|
||||||
check_body_permitted
|
check_body_permitted
|
||||||
send_request_with_body sock, ver, path, body
|
send_request_with_body sock, ver, path, body
|
||||||
@ -1221,7 +1229,7 @@ module Net
|
|||||||
@response = res
|
@response = res
|
||||||
end
|
end
|
||||||
attr_reader :response
|
attr_reader :response
|
||||||
alias data response
|
alias data response #:nodoc: obsolete
|
||||||
end
|
end
|
||||||
class HTTPError < ProtocolError
|
class HTTPError < ProtocolError
|
||||||
include HTTPExceptions
|
include HTTPExceptions
|
||||||
@ -1306,7 +1314,7 @@ module Net
|
|||||||
self::HAS_BODY
|
self::HAS_BODY
|
||||||
end
|
end
|
||||||
|
|
||||||
def HTTPResponse.exception_type # :nodoc:
|
def HTTPResponse.exception_type # :nodoc: internal use only
|
||||||
self::EXCEPTION_TYPE
|
self::EXCEPTION_TYPE
|
||||||
end
|
end
|
||||||
end # redefined after
|
end # redefined after
|
||||||
@ -1524,7 +1532,7 @@ module Net
|
|||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
def read_new( sock ) #:nodoc:
|
def read_new( sock ) #:nodoc: internal use only
|
||||||
httpv, code, msg = read_status_line(sock)
|
httpv, code, msg = read_status_line(sock)
|
||||||
res = response_class(code).new(httpv, code, msg)
|
res = response_class(code).new(httpv, code, msg)
|
||||||
each_response_header(sock) do |k,v|
|
each_response_header(sock) do |k,v|
|
||||||
@ -1571,7 +1579,7 @@ module Net
|
|||||||
|
|
||||||
include HTTPHeader
|
include HTTPHeader
|
||||||
|
|
||||||
def initialize( httpv, code, msg ) #:nodoc:
|
def initialize( httpv, code, msg ) #:nodoc: internal use only
|
||||||
@http_version = httpv
|
@http_version = httpv
|
||||||
@code = code
|
@code = code
|
||||||
@message = msg
|
@message = msg
|
||||||
@ -1591,7 +1599,7 @@ module Net
|
|||||||
|
|
||||||
# HTTP result message. For example, 'Not Found'.
|
# HTTP result message. For example, 'Not Found'.
|
||||||
attr_reader :message
|
attr_reader :message
|
||||||
alias msg message # :nodoc:
|
alias msg message # :nodoc: obsolete
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
"#<#{self.class} #{@code} readbody=#{@read}>"
|
"#<#{self.class} #{@code} readbody=#{@read}>"
|
||||||
@ -1623,7 +1631,8 @@ module Net
|
|||||||
self.class::EXCEPTION_TYPE
|
self.class::EXCEPTION_TYPE
|
||||||
end
|
end
|
||||||
|
|
||||||
def value #:nodoc:
|
# Raises HTTP error if the response is not 2xx.
|
||||||
|
def value
|
||||||
error! unless HTTPSuccess === self
|
error! unless HTTPSuccess === self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1642,7 +1651,7 @@ module Net
|
|||||||
# body
|
# body
|
||||||
#
|
#
|
||||||
|
|
||||||
def reading_body( sock, reqmethodallowbody ) #:nodoc:
|
def reading_body( sock, reqmethodallowbody ) #:nodoc: internal use only
|
||||||
@socket = sock
|
@socket = sock
|
||||||
@body_exist = reqmethodallowbody && self.class.body_permitted?
|
@body_exist = reqmethodallowbody && self.class.body_permitted?
|
||||||
begin
|
begin
|
||||||
@ -1712,7 +1721,7 @@ module Net
|
|||||||
read_body()
|
read_body()
|
||||||
end
|
end
|
||||||
|
|
||||||
alias entity body #:nodoc:
|
alias entity body #:nodoc: obsolete
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
@ -1774,7 +1783,7 @@ module Net
|
|||||||
class HTTP
|
class HTTP
|
||||||
ProxyMod = ProxyDelta
|
ProxyMod = ProxyDelta
|
||||||
end
|
end
|
||||||
module NetPrivate #:nodoc:
|
module NetPrivate #:nodoc:
|
||||||
HTTPRequest = ::Net::HTTPRequest
|
HTTPRequest = ::Net::HTTPRequest
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -165,13 +165,14 @@
|
|||||||
# The POPMail#unique_id() method returns the unique-id of the message as a
|
# The POPMail#unique_id() method returns the unique-id of the message as a
|
||||||
# String. Normally the unique-id is a hash of the message.
|
# String. Normally the unique-id is a hash of the message.
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'net/protocol'
|
require 'net/protocol'
|
||||||
require 'digest/md5'
|
require 'digest/md5'
|
||||||
|
|
||||||
module Net
|
module Net
|
||||||
|
|
||||||
# Non-authentication POP3 protocol error (reply code "-ERR", except
|
# Non-authentication POP3 protocol error
|
||||||
# authentication.
|
# (reply code "-ERR", except authentication).
|
||||||
class POPError < ProtocolError; end
|
class POPError < ProtocolError; end
|
||||||
|
|
||||||
# POP3 authentication error.
|
# POP3 authentication error.
|
||||||
@ -199,8 +200,7 @@ module Net
|
|||||||
110
|
110
|
||||||
end
|
end
|
||||||
|
|
||||||
# obsolete
|
def POP3.socket_type #:nodoc: obsolete
|
||||||
def POP3.socket_type # :nodoc:
|
|
||||||
Net::InternetMessageIO
|
Net::InternetMessageIO
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -218,6 +218,7 @@ module Net
|
|||||||
# Net::POP3::APOP($is_apop).start(addr, port) {|pop|
|
# Net::POP3::APOP($is_apop).start(addr, port) {|pop|
|
||||||
# ....
|
# ....
|
||||||
# }
|
# }
|
||||||
|
#
|
||||||
def POP3.APOP( isapop )
|
def POP3.APOP( isapop )
|
||||||
isapop ? APOP : POP3
|
isapop ? APOP : POP3
|
||||||
end
|
end
|
||||||
@ -240,6 +241,7 @@ module Net
|
|||||||
# file.write m.pop
|
# file.write m.pop
|
||||||
# m.delete if $DELETE
|
# m.delete if $DELETE
|
||||||
# end
|
# end
|
||||||
|
#
|
||||||
def POP3.foreach( address, port = nil,
|
def POP3.foreach( address, port = nil,
|
||||||
account = nil, password = nil,
|
account = nil, password = nil,
|
||||||
isapop = false, &block ) # :yields: message
|
isapop = false, &block ) # :yields: message
|
||||||
@ -259,6 +261,7 @@ module Net
|
|||||||
# 'YourAccount', 'YourPassword') do |m|
|
# 'YourAccount', 'YourPassword') do |m|
|
||||||
# file.write m.pop
|
# file.write m.pop
|
||||||
# end
|
# end
|
||||||
|
#
|
||||||
def POP3.delete_all( address, port = nil,
|
def POP3.delete_all( address, port = nil,
|
||||||
account = nil, password = nil,
|
account = nil, password = nil,
|
||||||
isapop = false, &block )
|
isapop = false, &block )
|
||||||
@ -278,6 +281,7 @@ module Net
|
|||||||
# # Example 2: APOP
|
# # Example 2: APOP
|
||||||
# Net::POP3.auth_only('pop.example.com', 110,
|
# Net::POP3.auth_only('pop.example.com', 110,
|
||||||
# 'YourAccount', 'YourPassword', true)
|
# 'YourAccount', 'YourPassword', true)
|
||||||
|
#
|
||||||
def POP3.auth_only( address, port = nil,
|
def POP3.auth_only( address, port = nil,
|
||||||
account = nil, password = nil,
|
account = nil, password = nil,
|
||||||
isapop = false )
|
isapop = false )
|
||||||
@ -363,6 +367,7 @@ module Net
|
|||||||
# pop.start(account, passwd) {
|
# pop.start(account, passwd) {
|
||||||
# ....
|
# ....
|
||||||
# }
|
# }
|
||||||
|
#
|
||||||
def set_debug_output( arg )
|
def set_debug_output( arg )
|
||||||
@debug_output = arg
|
@debug_output = arg
|
||||||
end
|
end
|
||||||
@ -394,7 +399,7 @@ module Net
|
|||||||
@started
|
@started
|
||||||
end
|
end
|
||||||
|
|
||||||
alias active? started? # obsolete
|
alias active? started? #:nodoc: obsolete
|
||||||
|
|
||||||
# Starts a POP3 session.
|
# Starts a POP3 session.
|
||||||
#
|
#
|
||||||
@ -540,8 +545,7 @@ module Net
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# internal use only (called from POPMail#uidl).
|
def set_all_uids #:nodoc: internal use only (called from POPMail#uidl)
|
||||||
def set_all_uids
|
|
||||||
command().uidl.each do |num, uid|
|
command().uidl.each do |num, uid|
|
||||||
@mails.find {|m| m.number == num }.uid = uid
|
@mails.find {|m| m.number == num }.uid = uid
|
||||||
end
|
end
|
||||||
@ -554,23 +558,27 @@ module Net
|
|||||||
POPSession = POP3
|
POPSession = POP3
|
||||||
POP3Session = POP3
|
POP3Session = POP3
|
||||||
|
|
||||||
|
#
|
||||||
# This class is equivalent to POP3, except that it uses APOP authentication.
|
# This class is equivalent to POP3, except that it uses APOP authentication.
|
||||||
|
#
|
||||||
class APOP < POP3
|
class APOP < POP3
|
||||||
|
|
||||||
# Always returns true.
|
# Always returns true.
|
||||||
def apop?
|
def apop?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# class aliases
|
||||||
APOPSession = APOP
|
APOPSession = APOP
|
||||||
|
|
||||||
|
#
|
||||||
# This class represents a message which exists on the POP server.
|
# This class represents a message which exists on the POP server.
|
||||||
# Instances of this class are created by the POP3 class; they should
|
# Instances of this class are created by the POP3 class; they should
|
||||||
# not be directly created by the user.
|
# not be directly created by the user.
|
||||||
|
#
|
||||||
class POPMail
|
class POPMail
|
||||||
|
|
||||||
def initialize( num, len, pop, cmd ) # :nodoc:
|
def initialize( num, len, pop, cmd ) #:nodoc:
|
||||||
@number = num
|
@number = num
|
||||||
@length = len
|
@length = len
|
||||||
@pop = pop
|
@pop = pop
|
||||||
@ -637,8 +645,8 @@ module Net
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
alias all pop # backward compatibility
|
alias all pop #:nodoc: obsolete
|
||||||
alias mail pop # backward compatibility
|
alias mail pop #:nodoc: obsolete
|
||||||
|
|
||||||
# Fetches the message header and +lines+ lines of body.
|
# Fetches the message header and +lines+ lines of body.
|
||||||
# The optional +dest+ argument is obsolete.
|
# The optional +dest+ argument is obsolete.
|
||||||
@ -677,12 +685,13 @@ module Net
|
|||||||
# n += 1
|
# n += 1
|
||||||
# end
|
# end
|
||||||
# }
|
# }
|
||||||
|
#
|
||||||
def delete
|
def delete
|
||||||
@command.dele @number
|
@command.dele @number
|
||||||
@deleted = true
|
@deleted = true
|
||||||
end
|
end
|
||||||
|
|
||||||
alias delete! delete # backward compatibility
|
alias delete! delete #:nodoc: obsolete
|
||||||
|
|
||||||
# True if the mail has been deleted.
|
# True if the mail has been deleted.
|
||||||
def deleted?
|
def deleted?
|
||||||
@ -701,15 +710,14 @@ module Net
|
|||||||
|
|
||||||
alias uidl unique_id
|
alias uidl unique_id
|
||||||
|
|
||||||
# internal use only (used from POP3#set_all_uids).
|
def uid=( uid ) #:nodoc: internal use only (used from POP3#set_all_uids)
|
||||||
def uid=( uid )
|
|
||||||
@uid = uid
|
@uid = uid
|
||||||
end
|
end
|
||||||
|
|
||||||
end # class POPMail
|
end # class POPMail
|
||||||
|
|
||||||
|
|
||||||
class POP3Command # :nodoc:
|
class POP3Command #:nodoc: internal use only
|
||||||
|
|
||||||
def initialize( sock )
|
def initialize( sock )
|
||||||
@socket = sock
|
@socket = sock
|
||||||
@ -718,7 +726,6 @@ module Net
|
|||||||
@apop_stamp = res.slice(/<.+>/)
|
@apop_stamp = res.slice(/<.+>/)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Provide human-readable stringification of class state.
|
|
||||||
def inspect
|
def inspect
|
||||||
"#<#{self.class} socket=#{@socket}>"
|
"#<#{self.class} socket=#{@socket}>"
|
||||||
end
|
end
|
||||||
|
@ -1,30 +1,29 @@
|
|||||||
=begin
|
#
|
||||||
|
# = net/protocol.rb
|
||||||
= net/protocol.rb
|
#
|
||||||
|
#--
|
||||||
Copyright (c) 1999-2003 Yukihiro Matsumoto
|
# Copyright (c) 1999-2003 Yukihiro Matsumoto
|
||||||
Copyright (c) 1999-2003 Minero Aoki
|
# Copyright (c) 1999-2003 Minero Aoki
|
||||||
|
#
|
||||||
written and maintained by Minero Aoki <aamine@loveruby.net>
|
# written and maintained by Minero Aoki <aamine@loveruby.net>
|
||||||
|
#
|
||||||
This program is free software. You can re-distribute and/or
|
# This program is free software. You can re-distribute and/or
|
||||||
modify this program under the same terms as Ruby itself,
|
# modify this program under the same terms as Ruby itself,
|
||||||
Ruby Distribute License or GNU General Public License.
|
# Ruby Distribute License or GNU General Public License.
|
||||||
|
#
|
||||||
$Id$
|
# $Id$
|
||||||
|
#++
|
||||||
WARNING: This file is going to remove.
|
#
|
||||||
Do not rely on the implementation written in this file.
|
# WARNING: This file is going to remove.
|
||||||
|
# Do not rely on the implementation written in this file.
|
||||||
=end
|
#
|
||||||
|
|
||||||
require 'socket'
|
require 'socket'
|
||||||
require 'timeout'
|
require 'timeout'
|
||||||
|
|
||||||
|
|
||||||
module Net
|
module Net
|
||||||
|
|
||||||
class Protocol
|
class Protocol #:nodoc: internal use only
|
||||||
private
|
private
|
||||||
def Protocol.protocol_param( name, val )
|
def Protocol.protocol_param( name, val )
|
||||||
module_eval(<<-End, __FILE__, __LINE__ + 1)
|
module_eval(<<-End, __FILE__, __LINE__ + 1)
|
||||||
@ -46,7 +45,7 @@ module Net
|
|||||||
ProtocRetryError = ProtoRetriableError
|
ProtocRetryError = ProtoRetriableError
|
||||||
|
|
||||||
|
|
||||||
class InternetMessageIO
|
class InternetMessageIO #:nodoc: internal use only
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
alias open new
|
alias open new
|
||||||
@ -415,10 +414,7 @@ module Net
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
#
|
class ReadAdapter #:nodoc: internal use only
|
||||||
# The reader adapter class for internal use only.
|
|
||||||
#
|
|
||||||
class ReadAdapter
|
|
||||||
|
|
||||||
def initialize( block )
|
def initialize( block )
|
||||||
@block = block
|
@block = block
|
||||||
@ -446,8 +442,7 @@ module Net
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# For backward compatibility
|
module NetPrivate #:nodoc: obsolete
|
||||||
module NetPrivate
|
|
||||||
Socket = ::Net::InternetMessageIO
|
Socket = ::Net::InternetMessageIO
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user