package org.chenyang.http.client.protocol;

import org.chenyang.http.HttpException;
import org.chenyang.http.HttpRequest;
import org.chenyang.http.annotation.Contract;
import org.chenyang.http.annotation.ThreadingBehavior;
import org.chenyang.http.auth.AuthState;
import org.chenyang.http.protocol.HttpContext;
import org.chenyang.http.util.Args;
import java.io.IOException;

/** @deprecated */
@Deprecated
@Contract(
   threading = ThreadingBehavior.IMMUTABLE
)
public class RequestTargetAuthentication extends RequestAuthenticationBase {
   public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
      Args.notNull(request, "HTTP request");
      Args.notNull(context, "HTTP context");
      String method = request.getRequestLine().getMethod();
      if (!method.equalsIgnoreCase("CONNECT")) {
         if (!request.containsHeader("Authorization")) {
            AuthState authState = (AuthState)context.getAttribute("http.auth.target-scope");
            if (authState == null) {
               this.log.debug("Target auth state not set in the context");
            } else {
               if (this.log.isDebugEnabled()) {
                  this.log.debug("Target auth state: " + authState.getState());
               }

               this.process(authState, request, context);
            }
         }
      }
   }
}
