tenderlove/mechanize — Issue #203: Exception triggered when body_io is File:null
Author: jhund
Created: 2012-02-19 05:54:32+00:00
State: open

If I run this in the console:

```ruby
agent = Mechanize.new
agent.redirect_ok = :all
agent.follow_meta_refresh = true
agent.user_agent = "my user agent"
agent.keep_alive = false
agent.open_timeout = 20
agent.read_timeout = 20
agent.robots = false

agent.get("http://www.bbc.co.uk/nature/17073830")
```

It raises

```
NoMethodError: undefined method `path' for nil:NilClass
from org/jruby/RubyKernel.java:238:in `method_missing'
from /Users/johund/.rvm/gems/jruby-1.6.3/gems/activesupport-3.0.9/lib/active_support/whiny_nil.rb:48:in `method_missing'
from /Users/johund/.rvm/gems/jruby-1.6.3/gems/mechanize-2.2.1/lib/mechanize/http/agent.rb:742:in `response_content_encoding'
from /Users/johund/.rvm/gems/jruby-1.6.3/gems/mechanize-2.2.1/lib/mechanize/http/agent.rb:238:in `fetch'
from /Users/johund/.rvm/gems/jruby-1.6.3/gems/mechanize-2.2.1/lib/mechanize.rb:403:in `get'
from (irb):10:in `evaluate'
```

I did some poking around and found that the actual problem appears to be in agent.rb, line 713.

In my case `body_io.inspect` yields `File:null`, so I figure an exception is raised when calling `body_io.stat.size` in line 713.

This jumps to the `ensure` block, where another exception is raised (the one shown in the stack trace above)

Should the call to `body_io.stat.size` be guarded somehow?

Environment:

* Mechanize 2.2.1
* jruby 1.6.3 (ruby-1.8.7-p330)
* Rails 3.0.9
* OS X Snow Leopard