httpclient icon indicating copy to clipboard operation
httpclient copied to clipboard

Does not support unix sockets

Open phemmer opened this issue 11 years ago • 1 comments

I was looking to use this gem for talking to the Docker API, but Docker listens on a named unix socket which the gem does not support.

Unfortunately this means I won't be using the httpclient gem, but I wanted to file the issue so that it might one day be supported.

phemmer avatar Feb 17 '14 01:02 phemmer

Well, I ended up using httpclient anyway. Was the only gem that had most of what I needed. I also came up with a fairly simple monkey patch to add unix socket support. It is by no means the "right" way of doing it, but it's simple and cleanish.

class HTTPClient
    attr_accessor :session_manager
end
class HTTPClient::Session
    alias_method :create_socket_nounix, :create_socket
    def create_socket(*args)
        if @socket_local.is_a?(String) and @socket_local.match(/^unix:\/\/(.*)/) then
            UNIXSocket.new($1)
        else
            create_socket_nounix(*args)
        end
    end
end

Usage:

client = HTTPClient.new
client.session_manager.socket_local = 'unix:///path/to/sock'
client.get('http:///foo?bar=baz')

Been using it a bit and it seems to be working just fine.

phemmer avatar Feb 17 '14 09:02 phemmer