mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
aamine
* lib/net/http.rb: rename HTTP#request_by_name to send_request. * lib/net/protocol.rb (ProtoSocket#read): modify typo. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1577 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7f326a3988
commit
2b67bb576a
5 changed files with 67 additions and 23 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Sun Jul 8 16:04:35 2001 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
|
* lib/net/http.rb: rename HTTP#request_by_name to send_request.
|
||||||
|
|
||||||
|
* lib/net/protocol.rb (ProtoSocket#read): modify typo.
|
||||||
|
|
||||||
Fri Jul 6 02:15:06 2001 Akinori MUSHA <knu@iDaemons.org>
|
Fri Jul 6 02:15:06 2001 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
* lib/tempfile.rb: a tempfile must be created with mode 0600.
|
* lib/tempfile.rb: a tempfile must be created with mode 0600.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
= net/http.rb version 1.2.2
|
= net/http.rb version 1.2.3
|
||||||
|
|
||||||
Copyright (c) 1999-2001 Yukihiro Matsumoto
|
Copyright (c) 1999-2001 Yukihiro Matsumoto
|
||||||
|
|
||||||
|
@ -266,10 +266,7 @@ Yes, this is not thread-safe.
|
||||||
Net::HTTP.start( 'some.www.server', 80 ) {|http|
|
Net::HTTP.start( 'some.www.server', 80 ) {|http|
|
||||||
response = http.head( '/index.html' )
|
response = http.head( '/index.html' )
|
||||||
}
|
}
|
||||||
response['content-length'] #-> '2554'
|
p response['content-type']
|
||||||
response['content-type'] #-> 'text/html'
|
|
||||||
response['Content-Type'] #-> 'text/html'
|
|
||||||
response['CoNtEnT-tYpe'] #-> 'text/html'
|
|
||||||
|
|
||||||
: post( path, data, header = nil, dest = '' )
|
: post( path, data, header = nil, dest = '' )
|
||||||
: post( path, data, header = nil ) {|str| .... }
|
: post( path, data, header = nil ) {|str| .... }
|
||||||
|
@ -286,32 +283,74 @@ Yes, this is not thread-safe.
|
||||||
by "anException.response".
|
by "anException.response".
|
||||||
|
|
||||||
# version 1.1
|
# version 1.1
|
||||||
response, body = http.post( '/index.html', 'querytype=subject&target=ruby' )
|
response, body = http.post( '/cgi-bin/search.rb', 'querytype=subject&target=ruby' )
|
||||||
# version 1.2
|
# version 1.2
|
||||||
response = http.post( '/index.html', 'querytype=subject&target=ruby' )
|
response = http.post( '/cgi-bin/search.rb', 'querytype=subject&target=ruby' )
|
||||||
# compatible for both version
|
# compatible for both version
|
||||||
response , = http.post( '/index.html', 'querytype=subject&target=ruby' )
|
response , = http.post( '/cgi-bin/search.rb', 'querytype=subject&target=ruby' )
|
||||||
|
|
||||||
# using block
|
# using block
|
||||||
File.open( 'save.html', 'w' ) {|f|
|
File.open( 'save.html', 'w' ) {|f|
|
||||||
http.post( '/index.html', 'querytype=subject&target=ruby' ) do |str|
|
http.post( '/cgi-bin/search.rb', 'querytype=subject&target=ruby' ) do |str|
|
||||||
f.write str
|
f.write str
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
# same effect
|
# same effect
|
||||||
File.open( 'save.html', 'w' ) {|f|
|
File.open( 'save.html', 'w' ) {|f|
|
||||||
http.post '/index.html', 'querytype=subject&target=ruby', nil, f
|
http.post '/cgi-bin/search.rb', 'querytype=subject&target=ruby', nil, f
|
||||||
|
}
|
||||||
|
|
||||||
|
: get2( path, header = nil )
|
||||||
|
: get2( path, header = nil ) {|response| .... }
|
||||||
|
gets entity from PATH. This method returns a HTTPResponse object.
|
||||||
|
|
||||||
|
When called with block, keep connection while block is executed
|
||||||
|
and gives a HTTPResponse object to the block.
|
||||||
|
|
||||||
|
This method never raise any ProtocolErrors.
|
||||||
|
|
||||||
|
# example
|
||||||
|
response = http.get2( '/index.html' )
|
||||||
|
p response['content-type']
|
||||||
|
puts response.body # body is already read
|
||||||
|
|
||||||
|
# using block
|
||||||
|
http.get2( '/index.html' ) {|response|
|
||||||
|
p response['content-type']
|
||||||
|
response.read_body do |str| # read body now
|
||||||
|
print str
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
: post2( path, header = nil )
|
||||||
|
: post2( path, header = nil ) {|response| .... }
|
||||||
|
posts data to PATH. This method returns a HTTPResponse object.
|
||||||
|
|
||||||
|
When called with block, gives a HTTPResponse object to the block
|
||||||
|
before reading entity body, with keeping connection.
|
||||||
|
|
||||||
|
# example
|
||||||
|
response = http.post2( '/cgi-bin/nice.rb', 'datadatadata...' )
|
||||||
|
p response.status
|
||||||
|
puts response.body # body is already read
|
||||||
|
|
||||||
|
# using block
|
||||||
|
http.post2( '/cgi-bin/nice.rb', 'datadatadata...' ) {|response|
|
||||||
|
p response.status
|
||||||
|
p response['content-type']
|
||||||
|
response.read_body do |str| # read body now
|
||||||
|
print str
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
: request( request [, data] )
|
: request( request [, data] )
|
||||||
: request( request [, data] ) {|response| .... }
|
: request( request [, data] ) {|response| .... }
|
||||||
sends a HTTPRequest object REQUEST to (remote) http server.
|
sends a HTTPRequest object REQUEST to the (remote) http server.
|
||||||
This method also writes string from DATA string if REQUEST is
|
This method also writes DATA string if REQUEST is a post/put request.
|
||||||
a post/put request. Giving DATA for get/head request causes
|
Giving DATA for get/head request causes ArgumentError.
|
||||||
ArgumentError.
|
|
||||||
|
|
||||||
If called with block, gives a HTTPResponse object to the block
|
If called with block, passes a HTTPResponse object to the block
|
||||||
with connecting server.
|
before reading entity body.
|
||||||
|
|
||||||
== class Net::HTTP::Get, Head, Post
|
== class Net::HTTP::Get, Head, Post
|
||||||
|
|
||||||
|
@ -397,7 +436,6 @@ All arguments named KEY is case-insensitive.
|
||||||
response body. If #read_body has been called, this method returns
|
response body. If #read_body has been called, this method returns
|
||||||
arg of #read_body DEST. Else gets body as String and returns it.
|
arg of #read_body DEST. Else gets body as String and returns it.
|
||||||
|
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
require 'net/protocol'
|
require 'net/protocol'
|
||||||
|
@ -610,7 +648,7 @@ module Net
|
||||||
req.response
|
req.response
|
||||||
end
|
end
|
||||||
|
|
||||||
def request_by_name( name, path, body = nil, header = nil )
|
def send_request( name, path, body = nil, header = nil )
|
||||||
r = ::Net::NetPrivate::HTTPGenericRequest.new(
|
r = ::Net::NetPrivate::HTTPGenericRequest.new(
|
||||||
name, (body ? true : false), true,
|
name, (body ? true : false), true,
|
||||||
path, header )
|
path, header )
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
= net/pop.rb version 1.2.2
|
= net/pop.rb version 1.2.3
|
||||||
|
|
||||||
Copyright (c) 1999-2001 Yukihiro Matsumoto
|
Copyright (c) 1999-2001 Yukihiro Matsumoto
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
= net/protocol.rb version 1.2.2
|
= net/protocol.rb version 1.2.3
|
||||||
|
|
||||||
Copyright (c) 1999-2001 Yukihiro Matsumoto
|
Copyright (c) 1999-2001 Yukihiro Matsumoto
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ module Net
|
||||||
|
|
||||||
class Protocol
|
class Protocol
|
||||||
|
|
||||||
Version = '1.2.2'
|
Version = '1.2.3'
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
|
@ -532,7 +532,7 @@ module Net
|
||||||
|
|
||||||
CRLF = "\r\n"
|
CRLF = "\r\n"
|
||||||
|
|
||||||
def read( len, dest = '', ignerr = false )
|
def read( len, dest = '', igneof = false )
|
||||||
D_off "reading #{len} bytes..."
|
D_off "reading #{len} bytes..."
|
||||||
|
|
||||||
rsize = 0
|
rsize = 0
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
= net/smtp.rb version 1.2.2
|
= net/smtp.rb version 1.2.3
|
||||||
|
|
||||||
Copyright (c) 1999-2001 Yukihiro Matsumoto
|
Copyright (c) 1999-2001 Yukihiro Matsumoto
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue