private static void ExtractCorrelationId(HttpResponseMessage response, ref XboxLiveHttpResponse xblResponse)
 {
     if (response != null)
     {
         if (response.Headers.TryGetValues("X-XblCorrelationId", out IEnumerable <string> correlationIds))
         {
             if (correlationIds != null && !string.IsNullOrEmpty(correlationIds.First()))
             {
                 xblResponse.CorrelationId = correlationIds.First();
             }
         }
     }
 }
예제 #2
0
        // Take a Func<HttpRequestMessage> so that HttpRequestMessage will be constructed in caller scope.
        // It is needed for retry as HttpRequestMessage will be disposed after send; cannot be reused.
        public async Task <XboxLiveHttpResponse> SendAsync(Func <HttpRequestMessage> requestGenerator)
        {
            XboxLiveHttpResponse xblResponse = new XboxLiveHttpResponse();

            HttpResponseMessage response = await this.SendInternalAsync(requestGenerator(), false);

            if (response != null)
            {
                ExtractCorrelationId(response, ref xblResponse);
            }

            if (response.StatusCode == HttpStatusCode.Forbidden)
            {
                // Force refresh the token if gets 403, then resend the request.
                response = await this.SendInternalAsync(requestGenerator(), true);
            }

            xblResponse.Response = response;
            return(xblResponse);
        }