/**
   * Sets cookies according to uri and responseHeaders
   *
   * @param uri the specified uri
   * @param responseHeaders a list of request headers
   * @throws IOException if some error of I/O operation occurs
   */
  @Override
  public void put(URI uri, Map<String, List<String>> responseHeaders) throws IOException {
    if (uri == null || responseHeaders == null) {
      throw new IllegalArgumentException();
    }

    // parse and construct cookies according to the map
    List<HttpCookie> cookies = parseCookie(responseHeaders);
    for (HttpCookie cookie : cookies) {

      // if the cookie doesn't have a domain, set one. The policy will do validation.
      if (cookie.getDomain() == null) {
        cookie.setDomain(uri.getHost());
      }

      // if the cookie doesn't have a path, set one. If it does, validate it.
      if (cookie.getPath() == null) {
        cookie.setPath(pathToCookiePath(uri.getPath()));
      } else if (!HttpCookie.pathMatches(cookie, uri)) {
        continue;
      }

      // if the cookie has the placeholder port list "", set the port. Otherwise validate it.
      if ("".equals(cookie.getPortlist())) {
        cookie.setPortlist(Integer.toString(uri.getEffectivePort()));
      } else if (cookie.getPortlist() != null && !HttpCookie.portMatches(cookie, uri)) {
        continue;
      }

      // if the cookie conforms to the policy, add it into the store
      if (policy.shouldAccept(uri, cookie)) {
        store.add(uri, cookie);
      }
    }
  }
 public Address(URI uri) {
   this.proxy = null;
   this.requiresTunnel = false;
   this.uriHost = uri.getHost();
   this.uriPort = uri.getEffectivePort();
   this.socketHost = uriHost;
   this.socketPort = uriPort;
 }
    /**
     * @param requiresTunnel true if the HTTP connection needs to tunnel one protocol over another,
     *     such as when using HTTPS through an HTTP proxy. When doing so, we must avoid buffering
     *     bytes intended for the higher-level protocol.
     */
    public Address(URI uri, Proxy proxy, boolean requiresTunnel) {
      this.proxy = proxy;
      this.requiresTunnel = requiresTunnel;
      this.uriHost = uri.getHost();
      this.uriPort = uri.getEffectivePort();

      SocketAddress proxyAddress = proxy.address();
      if (!(proxyAddress instanceof InetSocketAddress)) {
        throw new IllegalArgumentException(
            "Proxy.address() is not an InetSocketAddress: " + proxyAddress.getClass());
      }
      InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress;
      this.socketHost = proxySocketAddress.getHostName();
      this.socketPort = proxySocketAddress.getPort();
    }