public BandHttpMessageHandler(BandClient fitbitClient, IBandInterceptor 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 BandClient client, List <IBandInterceptor> interceptors) { if (interceptors.Count > 0) { // inspired by the code referenced from the web api source; this creates the russian doll effect BandHttpMessageHandler innerHandler = new BandHttpMessageHandler(client, interceptors[0]); var innerHandlers = interceptors.GetRange(1, interceptors.Count - 1); foreach (var handler in innerHandlers) { var messageHandler = new BandHttpMessageHandler(client, handler); messageHandler.InnerHandler = innerHandler; innerHandler = messageHandler; } return(innerHandler); } return(null); }