HTTP client

 @return [Sawyer::Agent]
435763
def agent
      @agent ||= Sawyer::Agent.new(api_endpoint, sawyer_options) do |http|
        http.headers['content-type'] = 'application/json'
        if basic_authenticated?
          http.basic_auth(@login, @password)
        end
      end
    end
106625
def get_stream(path, response_block, params = nil, headers = {}, auth = true)
      request(path: path, query: params, headers: headers, response_block: response_block, auth: auth, gzip: false)
    end
569409
public HttpClientActionBuilder client(HttpClient httpClient) {
		HttpClientActionBuilder clientAction = new HttpClientActionBuilder(action, httpClient)
				.withApplicationContext(applicationContext);
		return clientAction;
	}
1312528
function Agent(options) {
  if (!(this instanceof Agent)) return new Agent(options);

  EventEmitter.call(this);

  this.defaultPort = 80;
  this.protocol    = 'http:';

  this.options = util._extend({}, options);
  // don't confuse net and make it think that we're connecting to a pipe
  this.options.path = null;

  this.requests    = {};
  this.sockets     = {};
  this.freeSockets = {};

  this.keepAliveMsecs = this.options.keepAliveMsecs || 1000;
  this.keepAlive      = this.options.keepAlive || false;

  this.maxSockets     = this.options.maxSockets || Agent.defaultMaxSockets;
  this.maxFreeSockets = this.options.maxFreeSockets || 256;

  var self = this;
  this.on('free', function(socket, options) {
    var name = self.getName(options);
    debug('agent.on(free)', name);

    if (!self.isSocketDestroyed(socket) && self.requests[name] && self.requests[name].length) {
      self.requests[name].shift().onSocket(socket);
      if (self.requests[name].length === 0) {
        // don't leak
        delete self.requests[name];
      }
    }
    else {
      // If there are no pending requests, then put it in
      // the freeSockets pool, but only if we're allowed to do so.
      var req = socket._httpMessage;
      if (req && req.shouldKeepAlive && !self.isSocketDestroyed(socket) && self.options.keepAlive) {
        var freeSockets = self.freeSockets[name];
        var freeLen     = freeSockets ? freeSockets.length : 0;
        var count       = freeLen;

        if (self.sockets[name]) count += self.sockets[name].length;

        debug('potentially pooling', freeLen, count);

        if (count > self.maxSockets || freeLen >= self.maxFreeSockets) {
          debug('destroying socket', name);
          self.removeSocket(socket, options);
          socket.destroy();
        } else {
          debug('pooling socket', name);
          freeSockets = freeSockets || [];
          self.freeSockets[name] = freeSockets;
          socket.setKeepAlive(true, self.keepAliveMsecs);

          if (socket.unref) {
            socket.unref();
          }
          else if (socket.socket &&
                   socket.socket._handle &&
                   socket.socket._handle.unref) {
            socket.socket._handle.unref();
          }

          socket._httpMessage = null;
          self.removeSocket(socket, options);
          freeSockets.push(socket);

          // set timeout on idle sockets
          if (options.keepAliveTimeoutMsecs !== undefined) {
            socket._yakaa_timeout = setTimeout(function () {
              self.emit('yakaa_destroy');
              socket.destroySoon();
            }, options.keepAliveTimeoutMsecs);
          }

        }
      } else {
        self.removeSocket(socket, options);
        socket.destroy();
      }
    }
  });
}
1312673
def request(method:, url_path:, body: nil, params: {}, header_overrides: {})
      spec = body.nil? ? {} : {body_type: :json}
      endpoint_spec = Smartsheet::API::EndpointSpec.new(method, [url_path], **spec)
      request_spec = Smartsheet::API::RequestSpec.new(
          header_overrides: header_overrides,
          body: body,
          params: params
      )
      client.make_request(endpoint_spec, request_spec)
    end
581464
function Agent (id) {
  this.id = id ? id.toString() : uuid();

  // a list with all connected transports
  this.connections = [];
  this.defaultConnection = null;
  this.ready = Promise.resolve([]);
}
137757
def request
      http_segments = @segments.clone
      @params.each do |key,value|
        http_segments[key] = value
      end
      uri = URI::HTTP.build(
        :host => HOST,
        :path => @action_path,
        :query => URI.encode_www_form(http_segments)
      ).to_s
      result = JSON.parse(HTTParty.get(uri).parsed_response)
      Baidumap::Response.new(result,self)
    end
79507
def do_request method, endpoint, data = {}
      url = get_url(endpoint, method)
      options = {
        format: :json
      }

      # Allow custom HTTParty args.
      options = options.merge(@httparty_args)

      # Set headers.
      options[:headers] = {
        "User-Agent" => "WooCommerce API Client-Ruby/#{WooCommerce::VERSION}",
        "Accept" => "application/json"
      }
      options[:headers]["Content-Type"] = "application/json;charset=utf-8" if !data.empty?

      # Set basic authentication.
      if @is_ssl
        options[:verify] = @verify_ssl

        if @query_string_auth
          options.merge!(query: {
            consumer_key: @consumer_key,
            consumer_secret: @consumer_secret
          })
        else
          options.merge!(basic_auth: {
            username: @consumer_key,
            password: @consumer_secret
          })
        end
      end

      options.merge!(debug_output: $stdout) if @debug_mode
      options.merge!(body: data.to_json) if !data.empty?

      HTTParty.send(method, url, options)
    end
786113
def http_proxy(addr = nil, port = nil, user = nil, pass = nil)
      default_options[:http_proxyaddr] = addr
      default_options[:http_proxyport] = port
      default_options[:http_proxyuser] = user
      default_options[:http_proxypass] = pass
    end
865677
function HTTPClient(options) {
  if (!(this instanceof HTTPClient))
    return new HTTPClient(options);

  if (!options)
    options = {};

  if (typeof options === 'string')
    options = { uri: options };

  AsyncObject.call(this);

  this.options = options;
  this.network = Network.get(options.network);

  this.uri = options.uri || `http://localhost:${this.network.rpcPort}`;
  this.socket = null;
  this.apiKey = options.apiKey;
  this.auth = options.auth;
  this.rpc = new RPCClient(options);
}
1180465
def client
      return @client unless @client.nil?
      @client = ::Elasticsearch::Client.new(
        hosts: hosts,
        retry_on_failure: true,
        log: true,
        logger: ::Logger.new('es_client.log', 10, 1_024_000)
      )
    end
576480
def use_proxy(uri, port, user=nil, pass=nil)
      @http_class = Net::HTTP::Proxy(uri, port, user, pass)
    end
266647
def retrieve_http(options)
        file_size = options.fetch(:file_size)
        headers = options.fetch(:headers)
        url = options.fetch(:url)
        retrieved = 0

        request = Typhoeus::Request.new(url.to_s, method: :get, headers: headers)
        request.on_headers do |response|
          raise DownloadError.new("#{self.class}: Failed to download #{url}: Status Code: #{response.code}", response) unless response.code == 200
        end
        request.on_body do |chunk|
          retrieved += chunk.bytesize
          yield(chunk, retrieved, file_size)
        end
        request.run
      end
767395
def get(path, params = nil, headers = {}, auth = true)
      request(path: path, query: params, headers: headers, auth: auth)
    end
174704
def connection
      @options[:path] =API_VERSION1+ @options[:path]
      @options[:headers] = HEADERS.merge(@options[:headers])

      Megam::Log.debug("HTTP Request Data:")
      Megam::Log.debug("> HTTP #{@options[:scheme]}://#{@options[:host]}")
      @options.each do |key, value|
        Megam::Log.debug("> #{key}: #{value}")
      end
      Megam::Log.debug("End HTTP Request Data.")
      @connection = Excon.new("#{@options[:scheme]}://#{@options[:host]}",@options)
    end
308041
def get_api_results(url)
      uri = URI.parse(url)
      puts "URL: #{url}" if self.verbose
      http = Net::HTTP.new(uri.host, uri.port)
      http.use_ssl = true

      request = Net::HTTP::Get.new(uri.request_uri)
      response = http.request(request)

      JSON.parse(response.body)
    end
448139
def request(*args)
      response = make_request(*args)
      # binding.pry unless response.kind_of?(Net::HTTPSuccess)
      raise HTTPError, response unless response.is_a?(Net::HTTPSuccess)
      response
    end