public FitbitHttpMessageHandler(FitbitClient fitbitClient, IFitbitInterceptor interceptor) { this.FitbitClient = fitbitClient; this.interceptor = interceptor; responseHandler = ResponseHandler; //Define the inner must handler. Otherwise exception is thrown. InnerHandler = new HttpClientHandler(); }
/// <summary> /// Creates the processing request pipeline using the message handlers /// </summary> /// <param name="authorization"></param> /// <param name="interceptors"></param> /// <returns></returns> internal static HttpMessageHandler CreatePipeline(this FitbitClient client, List <IFitbitInterceptor> interceptors) { if (interceptors.Count > 0) { // inspired by the code referenced from the web api source; this creates the russian doll effect FitbitHttpMessageHandler innerHandler = new FitbitHttpMessageHandler(client, interceptors[0]); var innerHandlers = interceptors.GetRange(1, interceptors.Count - 1); foreach (var handler in innerHandlers) { var messageHandler = new FitbitHttpMessageHandler(client, handler); messageHandler.InnerHandler = innerHandler; innerHandler = messageHandler; } return(innerHandler); } return(null); }