diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2019-01-11 18:34:21 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2019-01-11 18:55:40 +0300 |
commit | 2199d803e4f80553448795f979836fe6aa3a353d (patch) | |
tree | 886721e64b75c0fa5b0fb3b06ecab25c9355c773 /ruby/vendor/gitlab-shell/lib/httpunix.rb | |
parent | b9b83e36794a9f01a33e0efa2b3b32392750faf6 (diff) |
Vendor gitlab-shell at 6c5b195353a632095d7f6
Diffstat (limited to 'ruby/vendor/gitlab-shell/lib/httpunix.rb')
-rw-r--r-- | ruby/vendor/gitlab-shell/lib/httpunix.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/ruby/vendor/gitlab-shell/lib/httpunix.rb b/ruby/vendor/gitlab-shell/lib/httpunix.rb new file mode 100644 index 000000000..7d00f71d5 --- /dev/null +++ b/ruby/vendor/gitlab-shell/lib/httpunix.rb @@ -0,0 +1,54 @@ +# support for http+unix://... connection scheme +# +# The URI scheme has the same structure as the similar one for python requests. See: +# http://fixall.online/theres-no-need-to-reinvent-the-wheelhttpsgithubcommsabramorequests-unixsocketurl/241810/ +# https://github.com/msabramo/requests-unixsocket + +require 'uri' +require 'net/http' + +module URI + class HTTPUNIX < HTTP + def hostname + # decode %XX from path to file + v = host + URI.decode(v) + end + + # port is not allowed in URI + DEFAULT_PORT = nil + def set_port(v) + return v unless v + raise InvalidURIError, "http+unix:// cannot contain port" + end + end + @@schemes['HTTP+UNIX'] = HTTPUNIX +end + +# Based on: +# - http://stackoverflow.com/questions/15637226/ruby-1-9-3-simple-get-request-to-unicorn-through-socket +# - Net::HTTP::connect +module Net + class HTTPUNIX < HTTP + def initialize(socketpath, port = nil) + super(socketpath, port) + @port = nil # HTTP will set it to default - override back -> set DEFAULT_PORT + end + + # override to prevent ":<port>" being appended to HTTP_HOST + def addr_port + address + end + + def connect + D "opening connection to #{address} ..." + s = UNIXSocket.new(address) + D "opened" + @socket = BufferedIO.new(s) + @socket.read_timeout = @read_timeout + @socket.continue_timeout = @continue_timeout + @socket.debug_output = @debug_output + on_connect + end + end +end |