estately / rets

A pure-ruby library for fetching data from RETS servers
https://github.com/estately/rets
127 stars 94 forks source link

improve cookie caching code to not depend on local storage #105

Open dougcole opened 9 years ago

dougcole commented 9 years ago

Right now the cookie caching code assumes the cookie storage is on a local disk. This works fine if you run all your rets interactions on a single machine or have some sort of shared filesystem, but it's not terribly flexible.

I'd prefer a caching mechanism that accepts an object that responds to read(name) and write(name) or something similar, then we can write plugins for this for nearly any storage system and simplify the process of running rets clients on multiple machines.

hfaulds commented 9 years ago

We use http-client which uses the http-cookie gem. I looked into what work would need to be done to use non-filesystem cookie stores with those gems:

http-cookie supports different cookie storing backends (their README at https://github.com/sparklemotion/http-cookie shows how to use alternate stores and they have a sqlite store implementation: https://github.com/sparklemotion/http-cookie/blob/master/lib/http/cookie_jar/mozilla_store.rb)

However HTTPClient's CookieManager code is set up to use the filesystem store (https://github.com/nahi/httpclient/blob/e11c7805c07d13989583aca91d9232231aafcd1e/lib/httpclient/cookie.rb#L22 would be unnecessary with the sqlite store, although I don't think it will necessarily break) and it doesn't expose the @jar instance var to set our own CookieJar implementation.

My take is that we'd need to write a custom CookieManager (which we can set on the HTTPClient object https://github.com/nahi/httpclient/blob/master/lib/httpclient.rb#L312) which instantiates a CookieJar with an arbitrary store (set by options).

There is another snag that http-cookie uses a java-esq system for loading cookiejar implementation and as far as I can tell one would probably have to either do some monkeypatch or instace var setting to get custom CookieJar implementations to load (https://github.com/sparklemotion/http-cookie/blob/master/lib/http/cookie_jar/abstract_store.rb#L18).

hfaulds commented 9 years ago

I was incorrect about that last paragraph. They handle passing in symbols or classes as the implementation (https://github.com/sparklemotion/http-cookie/blob/master/lib/http/cookie_jar.rb#L42-L47).