Sha256: a16841c6bbabfbbfd71f1a1bd20fd373dc1eb61200811fe9be80bc8097584639

Contents?: true

Size: 1.75 KB

Versions: 25

Compression:

Stored size: 1.75 KB

Contents

require 'net/http'
require 'ddtrace/transport/http/adapters/net'

module Datadog
  module Transport
    module HTTP
      module Adapters
        # Adapter for Unix sockets
        class UnixSocket < Adapters::Net
          DEFAULT_TIMEOUT = 1

          attr_reader \
            :filepath,
            :timeout

          def initialize(filepath, options = {})
            @filepath = filepath
            @timeout = options.fetch(:timeout, DEFAULT_TIMEOUT)
          end

          def open
            # Open connection
            connection = HTTP.new(
              filepath,
              read_timeout: timeout,
              continue_timeout: timeout
            )

            connection.start do |http|
              yield(http)
            end
          end

          # Re-implements Net:HTTP with underlying Unix socket
          class HTTP < ::Net::HTTP
            DEFAULT_TIMEOUT = 1

            attr_reader \
              :filepath,
              :unix_socket

            def initialize(filepath, options = {})
              super('localhost', 80)
              @filepath = filepath
              @read_timeout = options.fetch(:read_timeout, DEFAULT_TIMEOUT)
              @continue_timeout = options.fetch(:continue_timeout, DEFAULT_TIMEOUT)
              @debug_output = options[:debug_output] if options.key?(:debug_output)
            end

            def connect
              @unix_socket = UNIXSocket.open(filepath)
              @socket = ::Net::BufferedIO.new(@unix_socket).tap do |socket|
                socket.read_timeout = @read_timeout
                socket.continue_timeout = @continue_timeout
                socket.debug_output = @debug_output
              end
              on_connect
            end
          end
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
ddtrace-0.37.0 lib/ddtrace/transport/http/adapters/unix_socket.rb
ddtrace-0.36.0 lib/ddtrace/transport/http/adapters/unix_socket.rb
ls-trace-0.1.2 lib/ddtrace/transport/http/adapters/unix_socket.rb
ddtrace-0.35.2 lib/ddtrace/transport/http/adapters/unix_socket.rb
ddtrace-0.35.1 lib/ddtrace/transport/http/adapters/unix_socket.rb
ddtrace-0.35.0 lib/ddtrace/transport/http/adapters/unix_socket.rb
ddtrace-0.34.2 lib/ddtrace/transport/http/adapters/unix_socket.rb
ddtrace-0.34.1 lib/ddtrace/transport/http/adapters/unix_socket.rb
ddtrace-0.34.0 lib/ddtrace/transport/http/adapters/unix_socket.rb
ddtrace-0.33.1 lib/ddtrace/transport/http/adapters/unix_socket.rb
ddtrace-0.33.0 lib/ddtrace/transport/http/adapters/unix_socket.rb
ddtrace-0.32.0 lib/ddtrace/transport/http/adapters/unix_socket.rb
ddtrace-0.31.1 lib/ddtrace/transport/http/adapters/unix_socket.rb
ddtrace-0.31.0 lib/ddtrace/transport/http/adapters/unix_socket.rb
ddtrace-0.30.1 lib/ddtrace/transport/http/adapters/unix_socket.rb
ddtrace-0.30.0 lib/ddtrace/transport/http/adapters/unix_socket.rb
ddtrace-0.29.1 lib/ddtrace/transport/http/adapters/unix_socket.rb
ddtrace-0.26.1 lib/ddtrace/transport/http/adapters/unix_socket.rb
ls-trace-0.1.1 lib/ddtrace/transport/http/adapters/unix_socket.rb
ddtrace-0.29.0 lib/ddtrace/transport/http/adapters/unix_socket.rb