Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Net::HTTP::get statis of a chunked response

Reply
Thread Tools

Net::HTTP::get statis of a chunked response

 
 
AnÝbal
Guest
Posts: n/a
 
      12-27-2006
Hello,

I am using a code like:

# using block
File.open('result.txt', 'w') {|f|
resp, data = http.get('/~foo/') do |str|
f.write str
end
}

To read a chunked response from a server (a large file) Docs say:
"In version 1.2, this method never raises exception."

How can I know if the transfer was Ok? Just checking the size
reported by the content-length header against the size of the file
written to disk? Or is there any other recommended way?

Thanks in advance,

--
Anibal Rojas
http://www.rubycorner.com
http://www.hasmanydevelopers.com

 
Reply With Quote
 
 
 
 
ara.t.howard@noaa.gov
Guest
Posts: n/a
 
      12-27-2006
On Wed, 27 Dec 2006, [iso-8859-1] An=EDbal wrote:

> Hello,
>
> I am using a code like:
>
> # using block
> File.open('result.txt', 'w') {|f|
> resp, data =3D http.get('/~foo/') do |str|
> f.write str
> end
> }
>
> To read a chunked response from a server (a large file) Docs say:
> "In version 1.2, this method never raises exception."
>
> How can I know if the transfer was Ok? Just checking the size
> reported by the content-length header against the size of the file
> written to disk? Or is there any other recommended way?
>
> Thanks in advance,



harp:~ > cat a.rb
require 'net/http'
require 'uri'
require 'yaml'

%w[
http://www.google.com/index.html
http://www.google.com/non-index.html
].each do |uri|

uri =3D URI.parse uri
http =3D Net::HTTP.new uri.host
r =3D http.get(uri.path){|s| s}
y uri.to_s =3D> r.code
r.value # this will raise an error iff code is not=
200
end


harp:~ > ruby a.rb
http://www.google.com/index.html: "200"
http://www.google.com/non-index.html: "404"
/home/ahoward//lib/ruby/1.8/net/http.rb:2065:in `error!': 404 "Not Found" (=
Net::HTTPServerException)
from /home/ahoward//lib/ruby/1.8/net/http.rb:2074:in `value'
from a.rb:14
from a.rb:7



-a
--=20
if you find yourself slandering anybody, first imagine that your mouth is
filled with excrement. it will break you of the habit quickly enough. - th=
e
dalai lama

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chunked GZIP processing using Java Sockets aztechnology@gmail.com Java 10 03-29-2006 07:26 AM
Re: httplib raises ValueError reading chunked content Philip Semanchuk Python 0 03-09-2006 02:00 AM
httplib raises ValueError reading chunked content philip20060308@gmail.com Python 0 03-08-2006 11:21 PM
HttpURLConnection receiving chunked encoded responses d_cymbal@hotmail.com Java 0 04-13-2005 09:02 PM
transfer encoding: chunked CW ASP .Net 0 02-15-2005 09:41 AM



Advertisments