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

**URL:** <https://www.ruby-forum.com/t/net-get-statis-of-a-chunked-response/80478>\
**Category:** Ruby\
**Created:** [December 27, 2006, 3:20pm UTC](https://www.ruby-forum.com/t/net-get-statis-of-a-chunked-response/80478 "2006-12-27T15:20:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnSSS\_bal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c77e96/32.png) [@AnSSS\_bal](https://www.ruby-forum.com/u/AnSSS_bal)\
**Post date:** [December 27, 2006, 3:20pm UTC](https://www.ruby-forum.com/t/net-get-statis-of-a-chunked-response/80478/1 "2006-12-27T15:20:38Z")

</div>

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,
```

---

<div class="post-metadata">

**Author:** ![AnSSS\_bal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c77e96/32.png) [@AnSSS\_bal](https://www.ruby-forum.com/u/AnSSS_bal)\
**Post date:** [December 27, 2006, 3:50pm UTC](https://www.ruby-forum.com/t/net-get-statis-of-a-chunked-response/80478/2 "2006-12-27T15:50:44Z")

</div>

On Wed, 27 Dec 2006, [iso-8859-1] Aníbal wrote:

> 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[  
[Google](http://www.google.com/index.html)  
[http://www.google.com/non-index.html](http://www.google.com/non-index.html)  
].each do |uri|

uri = URI.parse uri  
http = Net::HTTP.new uri.host  
r = http.get(uri.path){|s| s}  
y uri.to\_s =\> 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:](http://www.google.com/index.html:) “200”  
[http://www.google.com/non-index.html:](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
