0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Net::HTTP::Local binds Net::HTTP requests to a local address and port.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Net::HTTP::Local

Net::HTTP::Local binds a Net::HTTP request to a specified local address and port.

Installation

gem install net-http-local

Usage

A contrived example:

require 'json'
require 'net/http/local'
require 'uri'


ip = -> do
  uri = URI.parse 'http://jsonip.com'
  res = Net::HTTP.get_response uri

  JSON.parse(res.body)['ip']
end
 
# The default IP address.
p ip.call # => 10.1.1.2

# Bind to 10.1.1.3 in a block.
Net::HTTP.bind '10.1.1.3' do
  p ip.call # => 10.1.1.3
end

# Bind and unbind without a block.
Net::HTTP.bind '10.1.1.3'
p ip.call # => 10.1.1.3
Net::HTTP.unbind