-
Notifications
You must be signed in to change notification settings - Fork 557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make the ALLOWED_HOSTS threadsafe #1054
Comments
@nhorton Thank you for the suggestion. I believe this would be a useful feature. One of the things I would like to change in WebMock over time is to move away from globals, including stub declarations. My main concern is that the configuration should be intuitive. I wonder how the I'm also considering whether What are your thoughts on that? |
@bblimke - sorry for being insanely late in responding. I missed your note at the time and am coming back to this because we are getting bitten by it severely now. The point about how Thread.current won't work with some of the gems that use threads for async requests is a very good one. I have been trying to figure out a way around that, and I don't see a reasonable one. You can't do anything like looking up parent threads so there is not a reasonable way I can see on that. I admit I am a little stumped on that. The only thing I can see is trying to stub out the behavior of the client libraries pre-thread-spawning, which is obviously a pretty big change. I wish I had better ideas. |
Right now, the
ALLOW
list is global and meant to be set in initialization. We have some very good reasons we want to dynamically allow and disallow some hosts, namely with only a few tests needing to hit that endpoint, and not wanting others to do it accidentally.I would be game to add the APIs myself for this, but I wanted to confirm that you are good with my approach first before I put in the time.
Proposal
WebMock.disable_net_connect!(allow:)
declaration unaltered fullyallow
on config with a version that joins the static variable with the thread variableWorkaround
The alternative I see is a workaround of using a proc as an arg to the static allow list, and having that check the Thread.current store for additional values and comparing. That is what I am about to do for now, but it feels pretty janky.
The text was updated successfully, but these errors were encountered: