protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { if (!IsAuthenticated()) { return(Task.FromResult(request.CreateResponse(HttpStatusCode.Unauthorized))); } stopWatch.Start(); try { var swaggerProvider = _config.GetSwaggerProvider(request); var rootUrl = _config.GetRootUrl(request); var apiVersion = request.GetRouteData().Values["apiVersion"].ToString(); var swaggerDoc = swaggerProvider.GetSwagger(rootUrl, apiVersion); var content = ContentFor(request, swaggerDoc); return(cancellationToken.IsCancellationRequested ? Task.FromResult(default(HttpResponseMessage)) : Task.FromResult(new HttpResponseMessage { Content = content })); } catch (UnknownApiVersion ex) { return(Task.FromResult(request.CreateErrorResponse(HttpStatusCode.NotFound, ex))); } catch (Exception ex) { LogAdapter.LogError("Could not create swagger specification file", ex); return(Task.FromResult(default(HttpResponseMessage))); } finally { stopWatch.Stop(); LogAdapter.LogInfo($"Swagger specification generation took: {stopWatch.ElapsedMilliseconds} ms"); } }