https://github.com/puppetlabs/net_http_unix
AF_UNIX domain socket support on top of Ruby's Net::HTTP libraries
https://github.com/puppetlabs/net_http_unix
Last synced: 3 months ago
JSON representation
AF_UNIX domain socket support on top of Ruby's Net::HTTP libraries
- Host: GitHub
- URL: https://github.com/puppetlabs/net_http_unix
- Owner: puppetlabs
- License: apache-2.0
- Created: 2014-09-11T17:41:38.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2025-02-04T02:14:37.000Z (10 months ago)
- Last Synced: 2025-07-28T05:38:58.808Z (5 months ago)
- Language: Ruby
- Size: 19.5 KB
- Stars: 21
- Watchers: 73
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# NetX::HTTPUnix
This gem is a small wrapper around Ruby's `Net::HTTP` interface that provides
support for unix domain sockets. If you need to issue HTTP requests to a HTTP
server listening on a local unix domain socket then this library is for you.
Simply `require 'net_x/http_unix'` in place of `require 'net/http'` and use
`NetX::HTTPUnix` as you would `Net::HTTP`. Address strings starting with
'unix://' will automatically be handled by a unix domain socket instead of a
TCP socket.
## Installation
Add this line to your application's Gemfile:
gem 'net_http_unix'
And then execute:
$ bundle
Or install it yourself as:
$ gem install net_http_unix
## Usage
Use the library just like you would `Net::HTTP.start` and `Net::HTTP.new`, but
with `NetX::HTTPUnix.start` and `NetX::HTTPUnix.new`.
For example a traditional SSL client works as expected:
```ruby
require 'net_http_unix'
req = Net::HTTP::Get.new("/status.json")
client = NetX::HTTPUnix.new('github.com', 443)
client.use_ssl = true
client.verify_mode = OpenSSL::SSL::VERIFY_NONE
resp = client.request(req)
puts resp.body
{"status":"ok","configuration_id":0}
```
And the corresponding `unix:///path/to/foo.sock` URI syntax:
```ruby
require 'net_http_unix'
req = Net::HTTP::Get.new("/status.json")
client = NetX::HTTPUnix.new('unix:///tmp/unicorn.sock')
resp = client.request(req)
puts resp.body
{"status":"ok","configuration_id":0,"socket":true}
```
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request