/// <summary>
        /// Handles the authentication hand-shake for Tfs
        /// </summary>
        /// <param name="request">The HTTP request message</param>
        /// <param name="cancellationToken">The cancellation token used for cooperative cancellation</param>
        /// <returns>A new <c>Task&lt;HttpResponseMessage&gt;</c> which wraps the response from the remote service</returns>
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            HttpResponseMessage response = null;

            for (int i = 3; i > 0; i--)
            {
                response = await this.innerHandler.SendAsync(request, cancellationToken);

                if (response.StatusCode != HttpStatusCode.Found)
                {
                    // Make sure that once we can authenticate with the service that we turn off the
                    // Expect100Continue behavior to increase performance.
                    this.ExpectContinue = false;
                    break;
                }

                // If we have to change properties about the handler we need to instantiate a new
                // one or else the underlying APIs barf
                this.innerHandler             = new TfsHttpClientHandler(this.Settings);
                request.Headers.Authorization = new AuthenticationHeaderValue("Basic", FormatBasicAuthHeader(this.Credentials));
            }

            return(response);
        }
        /// <summary>
        /// Handles the authentication hand-shake for Tfs
        /// </summary>
        /// <param name="request">The HTTP request message</param>
        /// <param name="cancellationToken">The cancellation token used for cooperative cancellation</param>
        /// <returns>A new <c>Task&lt;HttpResponseMessage&gt;</c> which wraps the response from the remote service</returns>
        protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            HttpResponseMessage response = null;
            for (int i = 3; i > 0; i--)
            {
                response = await this.innerHandler.SendAsync(request, cancellationToken);
                if (response.StatusCode != HttpStatusCode.Found)
                {
                    // Make sure that once we can authenticate with the service that we turn off the 
                    // Expect100Continue behavior to increase performance.
                    this.ExpectContinue = false;
                    break;
                }

                // If we have to change properties about the handler we need to instantiate a new
                // one or else the underlying APIs barf
                this.innerHandler = new TfsHttpClientHandler(this.Settings);
                request.Headers.Authorization = new AuthenticationHeaderValue("Basic", FormatBasicAuthHeader(this.Credentials));
            }

            return response;
        }
 /// <summary>
 /// Initializes a new <c>TfsHttpMessageHandler</c> instance with the specified credentials and request
 /// settings.
 /// </summary>
 /// <param name="credentials">The credentials which should be used</param>
 /// <param name="settings">The request settings which should be used</param>
 public TfsHttpMessageHandler(NetworkCredential credentials, TfsHttpRequestSettings settings)
 {
     this.Credentials  = credentials;
     this.Settings     = settings;
     this.innerHandler = new TfsHttpClientHandler(settings);
 }
 /// <summary>
 /// Initializes a new <c>TfsHttpMessageHandler</c> instance with the specified credentials and request 
 /// settings.
 /// </summary>
 /// <param name="credentials">The credentials which should be used</param>
 /// <param name="settings">The request settings which should be used</param>
 public TfsHttpMessageHandler(NetworkCredential credentials, TfsHttpRequestSettings settings)
 {
     this.Credentials = credentials;
     this.Settings = settings;
     this.innerHandler = new TfsHttpClientHandler(settings);
 }