Exemplo n.º 1
0
  /**
   * Add the content related headers. These headers contain user private data and is not used when
   * we are proxying an untrusted request.
   */
  private void populateHeaders() {

    if (mReferrer != null) mHeaders.put("Referer", mReferrer);
    if (mContentType != null) mHeaders.put(CONTENT_TYPE, mContentType);

    // if we have an active proxy and have proxy credentials, do pre-emptive
    // authentication to avoid an extra round-trip:
    if (mNetwork.isValidProxySet()) {
      String username;
      String password;
      /* The proxy credentials can be set in the Network thread */
      synchronized (mNetwork) {
        username = mNetwork.getProxyUsername();
        password = mNetwork.getProxyPassword();
      }
      if (username != null && password != null) {
        // we collect credentials ONLY if the proxy scheme is BASIC!!!
        String proxyHeader = RequestHandle.authorizationHeader(true);
        mHeaders.put(
            proxyHeader, "Basic " + RequestHandle.computeBasicAuthResponse(username, password));
      }
    }

    // Set cookie header
    String cookie = CookieManager.getInstance().getCookie(mListener.getWebAddress());
    if (cookie != null && cookie.length() > 0) {
      mHeaders.put("Cookie", cookie);
    }
  }