summaryrefslogtreecommitdiff
path: root/lib/net/http.rb
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-09 08:58:30 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-09 08:58:30 +0000
commitfa6dc283cd81445d4220018f49f5c82a572101fe (patch)
treefbb338267eb6b1d0fc9f88483542d19053b8ef38 /lib/net/http.rb
parenta20863ff41b0493da0d16597b693e88b54731c03 (diff)
aamine
* lib/net/protocol.rb: calls on_connect before conn_command git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1891 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net/http.rb')
-rw-r--r--lib/net/http.rb60
1 files changed, 30 insertions, 30 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb
index 730ea8eafc..5fb2e299a0 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -43,8 +43,8 @@ This is required for compatibility.
require 'net/http'
Net::HTTP.start( 'some.www.server', 80 ) {|http|
- response , = http.post( '/cgi-bin/any.rhtml',
- 'querytype=subject&target=ruby' )
+ response , = http.post( '/cgi-bin/any.rhtml',
+ 'querytype=subject&target=ruby' )
}
=== Accessing via Proxy
@@ -94,9 +94,9 @@ URI class will be included in ruby standard library.
require 'net/http'
Net::HTTP.start( 'auth.some.domain' ) {|http|
- response , = http.get( '/need-auth.cgi',
- 'Authentication' => ["#{account}:#{password}"].pack('m').strip )
- print response.body
+ response , = http.get( '/need-auth.cgi',
+ 'Authentication' => ["#{account}:#{password}"].pack('m').strip )
+ print response.body
}
In version 1.2 (Ruby 1.7 or later), you can write like this:
@@ -106,8 +106,8 @@ In version 1.2 (Ruby 1.7 or later), you can write like this:
req = Net::HTTP::Get.new('/need-auth.cgi')
req.basic_auth 'account', 'password'
Net::HTTP.start( 'auth.some.domain' ) {|http|
- response = http.request( req )
- print response.body
+ response = http.request(req)
+ print response.body
}
== Switching Net::HTTP versions
@@ -157,11 +157,11 @@ Yes, this is not thread-safe.
# example
proxy_class = Net::HTTP::Proxy( 'proxy.foo.org', 8080 )
- :
- proxy_class.start( 'www.ruby-lang.org' ) do |http|
- # connecting proxy.foo.org:8080
- :
- end
+ :
+ proxy_class.start( 'www.ruby-lang.org' ) {|http|
+ # connecting proxy.foo.org:8080
+ :
+ }
: proxy_class?
If self is HTTP, false.
@@ -242,13 +242,13 @@ Yes, this is not thread-safe.
# using block
File.open( 'save.txt', 'w' ) {|f|
- http.get( '/~foo/', nil ) do |str|
- f.write str
- end
+ http.get( '/~foo/', nil ) do |str|
+ f.write str
+ end
}
# same effect
File.open( 'save.txt', 'w' ) {|f|
- http.get '/~foo/', nil, f
+ http.get '/~foo/', nil, f
}
: head( path, header = nil )
@@ -263,7 +263,7 @@ Yes, this is not thread-safe.
response = nil
Net::HTTP.start( 'some.www.server', 80 ) {|http|
- response = http.head( '/index.html' )
+ response = http.head( '/index.html' )
}
p response['content-type']
@@ -290,13 +290,13 @@ Yes, this is not thread-safe.
# using block
File.open( 'save.html', 'w' ) {|f|
- http.post( '/cgi-bin/search.rb', 'querytype=subject&target=ruby' ) do |str|
- f.write str
- end
+ http.post( '/cgi-bin/search.rb', 'querytype=subject&target=ruby' ) do |str|
+ f.write str
+ end
}
# same effect
File.open( 'save.html', 'w' ) {|f|
- http.post '/cgi-bin/search.rb', 'querytype=subject&target=ruby', nil, f
+ http.post '/cgi-bin/search.rb', 'querytype=subject&target=ruby', nil, f
}
: get2( path, header = nil )
@@ -315,10 +315,10 @@ Yes, this is not thread-safe.
# using block
http.get2( '/index.html' ) {|response|
- p response['content-type']
- response.read_body do |str| # read body now
- print str
- end
+ p response['content-type']
+ response.read_body do |str| # read body now
+ print str
+ end
}
: post2( path, header = nil )
@@ -335,11 +335,11 @@ Yes, this is not thread-safe.
# 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
+ p response.status
+ p response['content-type']
+ response.read_body do |str| # read body now
+ print str
+ end
}
: request( request [, data] )