From b07608f2807cf43f3b06350ea9140e5dbcc43a22 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Tue, 19 Feb 2019 13:43:49 +0300 Subject: [PATCH] Set timeout for web requests. --- .../GitHub/Documents/GithubDocumentStore.cs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentStore.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentStore.cs index fbfb02961b..59f19f6198 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentStore.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentStore.cs @@ -150,7 +150,7 @@ namespace Volo.Docs.GitHub.Documents { Logger.LogInformation("Downloading content from Github (DownloadWebContentAsStringAsync): " + rawUrl); - using (var webClient = new WebClient()) + using (var webClient = new GithubWebClient()) { if (!token.IsNullOrWhiteSpace()) { @@ -158,6 +158,8 @@ namespace Volo.Docs.GitHub.Documents } webClient.Headers.Add("User-Agent", userAgent ?? ""); + + //TODO: SET TIMEOUT? return await webClient.DownloadStringTaskAsync(new Uri(rawUrl)); } @@ -176,7 +178,7 @@ namespace Volo.Docs.GitHub.Documents { Logger.LogInformation("Downloading content from Github (DownloadWebContentAsByteArrayAsync): " + rawUrl); - using (var webClient = new WebClient()) + using (var webClient = new GithubWebClient()) { if (!token.IsNullOrWhiteSpace()) { @@ -234,5 +236,21 @@ namespace Volo.Docs.GitHub.Documents .Replace("github.com", "raw.githubusercontent.com") .ReplaceFirst("/tree/", "/"); } + + private class GithubWebClient : WebClient + { + protected override WebRequest GetWebRequest(Uri address) + { + var webRequest = base.GetWebRequest(address); + if (webRequest == null) + { + return null; + } + + webRequest.Timeout = 15000; + + return webRequest; + } + } } } \ No newline at end of file