Active Resource can make use of HTTP authentication set at the class level. For instance:
class Resource < ActiveResource::Base
end
Resource.user = 'user'
Resource.password = 'password'
or
Resource.site = "http://user:password@site.com/"
But what if I use different HTTP authentication based on which user is logged in? If I change Resource.user and Resource.password, is that going to cause a race condition where requests from one thread suddenly start using the authentication of a user whose requests are running simultaneously in a different thread? Or is this a non-issue (as long as I reset the authentication between requests) because rails servers are not multithreaded?
Even if there's no thread safety problem, it still seems risky that if I fail to reset them, the previous user's credentials will be used automatically by future requests.
Update: After being frustrated with ActiveResource, I wrote my own REST library: https://github.com/DeepWebTechnologies/well_rested
Monkey patch the
host
,user
andpassword
methods ofActiveResource::Base
class:Now set the credentials in every request
As of Active Resource 4.1.0, those settings are thread local, so this example would not cause a race condition anymore.
This is the relevant commit if anyone is interested: https://github.com/rails/activeresource/commit/538588ddba9ffc9bf356790e9186dc7e6adad12f