public function setProxy($host, $port, $type = CURLPROXY_HTTP)
  {
    static $types_str = [
      'HTTP', 'SOCKS4', 'SOCKS5', 'SOCKS4A', 'SOCKS5_HOSTNAME'
    ];
    $types = [];
    foreach ($types_str as $type_str) {
      if (defined('CURLPROXY_' . $type_str)) {
        $types[] = constant('CURLPROXY_' . $type_str);
      }
    }
    if (! in_array($type, $types)) {
      throw new \Exception('Invalid proxy type specified.');
    }

    $this->_proxy['host'] = $host;
    $this->_proxy['port'] = (int) $port;
    $this->_proxy['type'] = $type;
  }