oesmith / puffing-billy

A rewriting web proxy for testing interactions between your browser and external sites. Works with ruby + rspec.
MIT License
656 stars 170 forks source link

How do I ignore/block/whatever domains? #257

Closed brandoncc closed 5 years ago

brandoncc commented 5 years ago

I am getting a ton of cached calls to update.googleapis.com and a couple of others. I would like to either block the connection to those urls (optimal) or just not cache them with billy. I'm having a hard time figuring out the right way to do that. One of the urls has a dynamic subdomain, the only part that is consistent is .gvt1.com.

I would like to do this in my rspec config if possible so it affects all tests. I tried using proxy.stub in my rspec config but it didn't seem to have any effect.

Thanks

ronwsmith commented 5 years ago

There isn't a way to block domains entirely, but you can use ignore_params to limit caching to one cache file for each domain.

brandoncc commented 5 years ago

Thanks @ronwsmith. Does that also include across different domains? My big problem is that Google is redirecting me to a.gvt1.com, b.gvt1.com, c.gvt1.com, etc for the same content (trying to update chrome during the test). If I add gvt1.com to the ignore_params list, will all of these get the same response? It seems like each subdomain would get its own still in puffing billy. Also, does ignore_params ignore different URL paths? Does a.gvt1.com/path1 and a.gvt1.com/path2 get the same response if I add gvt1.com to the list?

Thanks!

ronwsmith commented 5 years ago

ignore_params doesn't do what you want for sub-domains but looks like merge_cached_responses_whitelist will handle that with regexes.

c.merge_cached_responses_whitelist = [] is used to group together the cached responses for specific uri regexes that match any part of the url. This is useful for ensuring that any kind of analytics and various social buttons that have slightly different urls each time can be recorded once and reused nicely. Note that the request body is ignored for requests that contain a body.

brandoncc commented 5 years ago

Ah okay, thanks! I think I actually got it working with proxy.stub as well. I had tried it in the Billy.configure block, rather than where it belonged in a before hook in the Rspec config. This is really useful information though, I appreciate it!

brandoncc commented 5 years ago

Scratch that, it isn't working after all lol.Scratch that, it isn't working after all lol.

zedtux commented 2 years ago

I'm also looking for this feature too. I have requests to sentry, google analytics and more I'd like to completely block. Maybe adding a c.blacklist_domains options as an Array of String to specify domains that Billy should just respond with a 200/404 without routing the request would be great ?

Or, regarding the option name, not to collide with existing / not to confuse more users, something like c.blocked_domains would be better ?