Internal: Creates a Net::HTTP connection and yields to a block with
 the connection.

 Yields the Net::HTTP connection.

 Returns the return value (if any) of the block.
 Raises ConnectionError if any common HTTP errors are raised.
320179
def connect
      http = Net::HTTP.new(host, port)
      http.use_ssl = ssl

      begin
        yield http
      rescue *HTTP_ERRORS => exception
        raise ConnectionError, "#{exception.class.name}: #{exception.message}"
      end
    end
73040
def blocks
      RelationProxy.new(self, Block, [Operations::Create, Operations::List, Operations::Delete]) do
        def from_response(response, client)
          response['url'] ||= "#{base.url}#{resource_type.url}/#{response['user_id']}"
          super
        end

        def create(attributes, client = self.client)
          response = client.post(url, attributes)
          from_response({ 'user_id' => attributes['user_id'] }, client)
        end
      end
    end
292485
def connection_wrapper(&block)
        begin
          response = block.call
          raise ClientError.new(response.body['error']) if response.body.has_key?('error')
        rescue Faraday::ParsingError => e
          # Has gotten a response, but it is not formatted with JSON
          raise ClientError.new(e.message)
        rescue Faraday::ClientError => e
          # Failed to build a connection
          raise ConnectionError.new(e.message)
        end

        response
      end
263617
def connection
      @connection ||= Faraday.new(conn_opts) do |http|
        http.url_prefix = endpoint
        if @access_token
          http.authorization :Bearer, @access_token
        end
      end
    end
1039450
def create_new_connection(options, &block)
      if @connection
        logger.debug("[WinRM] shutting previous connection #{@connection}")
        @connection.close
      end

      @connection_options = options
      @connection = Connection.new(options, &block)
    end
130100
def perform(*all_args)
      return yield if block_given?
      op, key, *args = *all_args

      key = key.to_s
      key = validate_key(key)
      begin
        server = ring.server_for_key(key)
        ret = server.request(op, key, *args)
        ret
      rescue NetworkError => e
        Dalli.logger.debug { e.inspect }
        Dalli.logger.debug { "retrying request with new server" }
        retry
      end
    end
424312
def app(&block)
      raise ArgumentError, "Block is required" unless block_given?
      lambda do |env|
        Rango::Router.set_rack_env(env)
        request = Rango::Request.new(env)
        response = Rack::Response.new
        body = block.call(request, response)
        # TODO: check how rack test if object is stringable, probably not this way
        raise ArgumentError, "It has to return a valid rack body, #{body.inspect} returned" unless body.respond_to?(:each) || body.is_a?(String)
        response.write(body)
        array = response.finish
        [array[0], array[1], body] # we don't want to have Rack::Response instance instead body, it's mess!
      end
    end
1118796
def _create_connection(self):
        
        transport = SSL if self.ssl else TCP
        return transport(self.server, self.port)
321557
def connection
      @connection ||= Faraday.new(url) do |conn|
        conn.response(:parse_json)
        # Request compressed responses from ES and decompress them
        conn.use(:gzip)
        conn.request(:encode_json)
        conn.request(:opaque_id) if @opaque_id
        conn.request(:limit_size, max_request_size: max_request_size) if max_request_size
        conn.request(:elastomer_compress, compression: compression) if compress_body

        if @adapter.is_a?(Array)
          conn.adapter(*@adapter)
        else
          conn.adapter(@adapter)
        end

        conn.options[:timeout]      = read_timeout
        conn.options[:open_timeout] = open_timeout
      end
    end
629109
def retrieve_connection(klass) #:nodoc:
      self.ensure_ready
      pool = self.retrieve_connection_pool(klass)
      (pool && pool.connection) or raise ActiveRecord::ConnectionNotEstablished
    end
1140088
def use(conn = nil)
      conn_given = !!conn
      conn = conn_given ? conn : @pool.checkout
      begin
        yield Thread.current[:squirm_connection] = conn
      ensure
        Thread.current[:squirm_connection] = nil
        @pool.checkin conn unless conn_given
      end
    end
375232
def connection(self):
        
        connection = getattr(self.state, "connection", None)
        if connection is None:
            connection = self.state.connection = pika.BlockingConnection(
                parameters=self.parameters)
            self.connections.add(connection)
        return connection
253095
def connection(self):
        
        conn = self.session(**self.options)
        try:
            for item in self.middlewares:
                item(conn)
            yield conn
        finally:
            conn.teardown()
297695
def post_request(url)
      do_request(url, Net::HTTP::Post) do |request|
        yield(request) if block_given?
      end
    end
1194115
async def create_http_connection(loop, protocol_factory, host, port=25105,
                                 auth=None):
    """"""
    protocol = protocol_factory()
    transport = HttpTransport(loop, protocol, host, port, auth)
    _LOGGER.debug("create_http_connection Finished creating connection")
    return (transport, protocol)
1206474
def get_connection(self, *args, **kwargs):
        
        conn = super(SSLHTTPAdapter, self).get_connection(*args, **kwargs)
        if conn.assert_hostname != self.assert_hostname:
            conn.assert_hostname = self.assert_hostname
        return conn
708391
def configure(&block)
      @config = Logger::Config.new
      @config.abort_on_failed_reconnect = false

      # provide legacy support for old configuration syntax
      (block.arity > 0) ? yield(@config) : @config.instance_eval(&block)

      ensure_required_options_exist
      initialize_connection unless disabled?
      @configured = true
    end