summaryrefslogtreecommitdiff
path: root/lib/net/http.rb
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-11-07 11:27:16 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-11-07 11:27:16 +0000
commit41e41d34d14ef3595a54148368b89b6c75d0fe4d (patch)
treeccbe4dd866bfcaeb2bc493b0938578746cd531f7 /lib/net/http.rb
parentfaeb1701cea992f5fb98c6d6c543e62f260b31c2 (diff)
aamine
* lib/net/protocol.rb, smtp.rb, pop.rb, http.rb: 1.1.30 * lib/net/protocol.rb, smtp.rb: Command#critical_ok -> error_ok * lib/net/http.rb: read header when also "100 Continue" git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net/http.rb')
-rw-r--r--lib/net/http.rb152
1 files changed, 89 insertions, 63 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb
index bf6cf981e4..13135d13d9 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -1,6 +1,6 @@
=begin
-= net/http.rb version 1.1.29
+= net/http.rb version 1.1.30
maintained by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
This file is derived from "http-access.rb".
@@ -670,6 +670,12 @@ SRC
end
+ ###
+ ### request
+ ###
+
+ public
+
def get( path, u_header )
return unless begin_critical
request sprintf('GET %s HTTP/%s', path, HTTPVersion), u_header
@@ -703,9 +709,39 @@ SRC
end
+ private
+
+ def request( req, u_header )
+ @socket.writeline req
+ if u_header then
+ header = @in_header.dup.update( u_header )
+ else
+ header = @in_header
+ end
+ header.each do |n,v|
+ @socket.writeline n + ': ' + v
+ end
+ @socket.writeline ''
+ end
+
+
+ ###
+ ### response line & header
+ ###
+
+ public
+
def get_response
+ resp = get_resp0
+ resp = get_resp0 while ContinueCode === resp
+ resp
+ end
+
+
+ private
+
+ def get_resp0
resp = get_reply
- resp = get_reply while ContinueCode === resp
while true do
line = @socket.readline
@@ -727,56 +763,22 @@ SRC
resp
end
-
- def get_body( resp, dest )
- if chunked? resp then
- read_chunked( dest, resp )
- else
- clen = content_length( resp )
- if clen then
- @socket.read clen, dest
- else
- clen = range_length( resp )
- if clen then
- @socket.read clen, dest
- else
- tmp = resp['connection']
- if tmp and /close/i === tmp then
- @socket.read_all dest
- else
- tmp = resp['proxy-connection']
- if tmp and /close/i === tmp then
- @socket.read_all dest
- end
- end
- end
- end
- end
- end_critical
- end
-
- def no_body
- end_critical
- end
-
-
- private
-
-
- def request( req, u_header )
- @socket.writeline req
- if u_header then
- header = @in_header.dup.update( u_header )
- else
- header = @in_header
- end
- header.each do |n,v|
- @socket.writeline n + ': ' + v
+ def get_reply
+ str = @socket.readline
+ m = /\AHTTP\/(\d+\.\d+)?\s+(\d\d\d)\s*(.*)\z/i.match( str )
+ unless m then
+ raise HTTPBadResponse, "wrong status line: #{str}"
end
- @socket.writeline ''
+ @http_version = m[1]
+ status = m[2]
+ discrip = m[3]
+
+ code = HTTPCODE_TO_OBJ[status] ||
+ HTTPCODE_CLASS_TO_OBJ[status[0,1]] ||
+ UnknownCode
+ HTTPResponse.new( code, status, discrip )
end
-
HTTPCODE_CLASS_TO_OBJ = {
'1' => HTTPInformationCode,
'2' => HTTPSuccessCode,
@@ -829,22 +831,47 @@ SRC
'505' => HTTPVersionNotSupported
}
- def get_reply
- str = @socket.readline
- m = /\AHTTP\/(\d+\.\d+)?\s+(\d\d\d)\s*(.*)\z/i.match( str )
- unless m then
- raise HTTPBadResponse, "wrong status line: #{str}"
+
+ ###
+ ### body
+ ###
+
+ public
+
+ def get_body( resp, dest )
+ if chunked? resp then
+ read_chunked( dest, resp )
+ else
+ clen = content_length( resp )
+ if clen then
+ @socket.read clen, dest
+ else
+ clen = range_length( resp )
+ if clen then
+ @socket.read clen, dest
+ else
+ tmp = resp['connection']
+ if tmp and /close/i === tmp then
+ @socket.read_all dest
+ else
+ tmp = resp['proxy-connection']
+ if tmp and /close/i === tmp then
+ @socket.read_all dest
+ end
+ end
+ end
+ end
end
- @http_version = m[1]
- status = m[2]
- discrip = m[3]
-
- code = HTTPCODE_TO_OBJ[status] ||
- HTTPCODE_CLASS_TO_OBJ[status[0,1]] ||
- UnknownCode
- HTTPResponse.new( code, status, discrip )
+ end_critical
end
+ def no_body
+ end_critical
+ end
+
+
+ private
+
def read_chunked( ret, header )
len = nil
total = 0
@@ -865,7 +892,6 @@ SRC
end
end
-
def content_length( header )
if header.key? 'content-length' then
m = /\d+/.match( header['content-length'] )