halorgium / rack-client

A client wrapper around a rack app or live-http
http://halorgium.github.com/rack-client
MIT License
99 stars 28 forks source link

Requests through Rack::Cache are unsuccessful when cached #6

Closed benschwarz closed 11 years ago

benschwarz commented 13 years ago

The setup:

HTTPClient = Rack::Client.new do
  use Rack::Cache,
    :metastore   => 'memcached://localhost:11211/meta',
    :entitystore => 'memcached://localhost:11211/body'
  run Rack::Client::Handler::NetHTTP
end

HTTPClient.get "http://google.com" => success, gets stored in memcached HTTPClient.get "http://google.com" => Kaboom.

NoMethodError: undefined method strip' for nil:NilClass from /Users/ben/.rvm/gems/ruby-1.9.2-p0@hoard/gems/activesupport-3.0.0/lib/active_support/whiny_nil.rb:48:inmethod_missing' from /Users/ben/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/http.rb:1296:in block in initialize_http_header' from /Users/ben/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/http.rb:1294:ineach' from /Users/ben/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/http.rb:1294:in initialize_http_header' from /Users/ben/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/http.rb:1662:ininitialize' from /Users/ben/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/http.rb:1779:in initialize' from /Users/ben/.rvm/gems/ruby-1.9.2-p0@hoard/bundler/gems/rack-client-a7c0e06f2ca4/lib/rack/client/handler/net_http.rb:51:innew' from /Users/ben/.rvm/gems/ruby-1.9.2-p0@hoard/bundler/gems/rack-client-a7c0e06f2ca4/lib/rack/client/handler/net_http.rb:51:in net_request_for' from /Users/ben/.rvm/gems/ruby-1.9.2-p0@hoard/bundler/gems/rack-client-a7c0e06f2ca4/lib/rack/client/handler/net_http.rb:18:insync_call' from /Users/ben/.rvm/gems/ruby-1.9.2-p0@hoard/bundler/gems/rack-client-a7c0e06f2ca4/lib/rack/client/core/dual_band.rb:8:in call' from /Users/ben/.rvm/gems/ruby-1.9.2-p0@hoard/gems/rack-cache-0.5.3/lib/rack/cache/context.rb:129:inforward' from /Users/ben/.rvm/gems/ruby-1.9.2-p0@hoard/gems/rack-cache-0.5.3/lib/rack/cache/context.rb:200:in validate' from /Users/ben/.rvm/gems/ruby-1.9.2-p0@hoard/gems/rack-cache-0.5.3/lib/rack/cache/context.rb:174:inlookup' from /Users/ben/.rvm/gems/ruby-1.9.2-p0@hoard/gems/rack-cache-0.5.3/lib/rack/cache/context.rb:65:in call!' from /Users/ben/.rvm/gems/ruby-1.9.2-p0@hoard/gems/rack-cache-0.5.3/lib/rack/cache/context.rb:50:incall' from /Users/ben/.rvm/gems/ruby-1.9.2-p0@hoard/bundler/gems/rack-client-a7c0e06f2ca4/lib/rack/client/adapter/base.rb:24:in request' from /Users/ben/.rvm/gems/ruby-1.9.2-p0@hoard/bundler/gems/rack-client-a7c0e06f2ca4/lib/rack/client/adapter/simple.rb:56:inrequest' from /Users/ben/.rvm/gems/ruby-1.9.2-p0@hoard/bundler/gems/rack-client-a7c0e06f2ca4/lib/rack/client/adapter/simple.rb:38:in get' from (irb):3 from /Users/ben/.rvm/gems/ruby-1.9.2-p0@hoard/gems/railties-3.0.0/lib/rails/commands/console.rb:44:instart' from /Users/ben/.rvm/gems/ruby-1.9.2-p0@hoard/gems/railties-3.0.0/lib/rails/commands/console.rb:8:in start' from /Users/ben/.rvm/gems/ruby-1.9.2-p0@hoard/gems/railties-3.0.0/lib/rails/commands.rb:23:in<top (required)>' from script/rails:9:in require' from script/rails:9:in

'ruby-1.9.2-p0 >

benburkert commented 13 years ago

I wasn't able to reproduce this. I switched to http://www.google.com, and it it was not storing anything in memcached on the first request.

Also, you might want to look at the caching code in rack-client, it's intended to be used for client side caching.

benschwarz commented 13 years ago

If you don't have the memcached gem in your gemfile, it simply won't do anything.

Also, the request won't get written to memcached if you're hitting a resource that is Cache-Control: Private'd

From there, it should be pretty reproducible.

In the mean time I'll checkout the stuff you guys have implemented, I didn't realise it existed.