What's the RIGHT way to accomplish controlling the source IP and port with Mechanize? #597
Replies: 1 comment
-
Hi @astounding, thanks for asking this question. As you have already discovered, Mechanize wraps Net::HTTP::Persistent which is itself a wrapper around Net::HTTP. However, Net::HTTP::Persistent doesn't expose the exact same API as Net::HTTP and so some attributes (like I'd like to suggest that you could either ask about this or send a pull request to https://github.com/drbrain/net-http-persistent. Once NHP has exposed them, then we can likewise expose them in Mechanize. If you want to create a PR my suggestion would be to follow the pattern provided by the I hope this response was helpful! Let me know if you have any more questions, I'm happy to provide mentorship or review a PR to Mechanize and/or NHP! |
Beta Was this translation helpful? Give feedback.
-
I didn't see anything obvious in documentation showing how to control the SOURCE IP and PORT that Mechanize binds to. I know Net::HTTP has #local_port and #local_host methods to set and control source IP and PORT binding, but I don't know how to tell my Mechanize agent to set those. Instead I resorted to this UGLY kludge:
Is there a way to pass parameters or options to Mechanize either upon agent creation OR when executing the agent's #get or #post methods so that it sets @http.local_host instead of me having to resort to using this nasty kludge just to force the TCP HTTP socket to bind to the local IP I choose for the outgoing client connection(s)?
Thanks in advance for any pointers/tips/suggestions!
--Aaron out.
Beta Was this translation helpful? Give feedback.
All reactions