package org.chenyang.http.impl.client;

import org.chenyang.http.Header;
import org.chenyang.http.HttpResponse;
import org.chenyang.http.annotation.Contract;
import org.chenyang.http.annotation.ThreadingBehavior;
import org.chenyang.http.auth.MalformedChallengeException;
import org.chenyang.http.protocol.HttpContext;
import org.chenyang.http.util.Args;
import java.util.List;
import java.util.Map;

/** @deprecated */
@Deprecated
@Contract(
   threading = ThreadingBehavior.IMMUTABLE
)
public class DefaultProxyAuthenticationHandler extends AbstractAuthenticationHandler {
   public boolean isAuthenticationRequested(HttpResponse response, HttpContext context) {
      Args.notNull(response, "HTTP response");
      int status = response.getStatusLine().getStatusCode();
      return status == 407;
   }

   public Map<String, Header> getChallenges(HttpResponse response, HttpContext context) throws MalformedChallengeException {
      Args.notNull(response, "HTTP response");
      Header[] headers = response.getHeaders("Proxy-Authenticate");
      return this.parseChallenges(headers);
   }

   protected List<String> getAuthPreferences(HttpResponse response, HttpContext context) {
      List<String> authpref = (List)response.getParams().getParameter("http.auth.proxy-scheme-pref");
      return authpref != null ? authpref : super.getAuthPreferences(response, context);
   }
}
