   (:import (java.net URI)
            (java.util ArrayList)
            (org.apache.commons.codec.binary Base64)
-           (org.eclipse.jetty.client HttpClient WWWAuthenticationProtocolHandler)
+           (org.eclipse.jetty.client HttpClient HttpProxy ProxyConfiguration WWWAuthenticationProtocolHandler)
            (org.eclipse.jetty.client.api Authentication$Result Request)
            (org.eclipse.jetty.http HttpField HttpHeader)
            (org.eclipse.jetty.http2.client HTTP2Client)


(def ^Base64 base64 (Base64.))

(defn spnego-authentication
  "Returns an Authentication$Result for endpoint which will use SPNEGO to generate an Authorization header"
  [^URI endpoint]
  (reify Authentication$Result
    (getURI [_] endpoint)


              _ (.requestMutualAuth gss-context true)
              token (.initSecContext gss-context (make-array Byte/TYPE 0) 0 0)
              header (str "Negotiate " (String. (.encode base64 token)))]
          (.header request auth-header-field header))
        (catch Exception e
          (log/warn e "failure during spnego authentication"))))))

(defn spnego-authentication
  "Returns an Authentication$Result for endpoint which will use SPNEGO to generate an Authorization header"
  [^URI endpoint]
  (create-spnego-authentication-result-factory endpoint HttpHeader/AUTHORIZATION))

(defn spnego-proxy-authentication
  "Returns an Authentication$Result for endpoint which will use SPNEGO to generate a Proxy-Authorization header"
  [^URI endpoint]
  (create-spnego-authentication-result-factory endpoint HttpHeader/PROXY_AUTHORIZATION))

(defn status-2XX?
  "Returns true if the status is in the range [200, 299]."
