4343
4444 . PARAMETER outputCacheFile
4545 Path to a file that the script will output all the validated links after running all checks.
46+
47+ . PARAMETER requestTimeoutSec
48+ The number of seconds before we timeout when sending an individual web request. Default is 15 seconds.
4649
4750 . EXAMPLE
4851 PS> .\Verify-Links.ps1 C:\README.md
@@ -67,7 +70,8 @@ param (
6770 [bool ] $checkLinkGuidance = $false ,
6871 [string ] $userAgent ,
6972 [string ] $inputCacheFile ,
70- [string ] $outputCacheFile
73+ [string ] $outputCacheFile ,
74+ [string ] $requestTimeoutSec = 15
7175)
7276
7377$ProgressPreference = " SilentlyContinue" ; # Disable invoke-webrequest progress dialog
@@ -220,14 +224,14 @@ function CheckLink ([System.Uri]$linkUri, $allowRetry=$true)
220224 $headRequestSucceeded = $true
221225 try {
222226 # Attempt HEAD request first
223- $response = Invoke-WebRequest - Uri $linkUri - Method HEAD - UserAgent $userAgent
227+ $response = Invoke-WebRequest - Uri $linkUri - Method HEAD - UserAgent $userAgent - TimeoutSec $requestTimeoutSec
224228 }
225229 catch {
226230 $headRequestSucceeded = $false
227231 }
228232 if (! $headRequestSucceeded ) {
229233 # Attempt a GET request if the HEAD request failed.
230- $response = Invoke-WebRequest - Uri $linkUri - Method GET - UserAgent $userAgent
234+ $response = Invoke-WebRequest - Uri $linkUri - Method GET - UserAgent $userAgent - TimeoutSec $requestTimeoutSec
231235 }
232236 $statusCode = $response.StatusCode
233237 if ($statusCode -ne 200 ) {
@@ -328,7 +332,7 @@ function GetLinks([System.Uri]$pageUri)
328332{
329333 if ($pageUri.Scheme.StartsWith (" http" )) {
330334 try {
331- $response = Invoke-WebRequest - Uri $pageUri - UserAgent $userAgent
335+ $response = Invoke-WebRequest - Uri $pageUri - UserAgent $userAgent - TimeoutSec $requestTimeoutSec
332336 $content = $response.Content
333337
334338 if ($pageUri.ToString ().EndsWith(" .md" )) {
@@ -392,7 +396,7 @@ if ($inputCacheFile)
392396 $cacheContent = " "
393397 if ($inputCacheFile.StartsWith (" http" )) {
394398 try {
395- $response = Invoke-WebRequest - Uri $inputCacheFile
399+ $response = Invoke-WebRequest - Uri $inputCacheFile - TimeoutSec $requestTimeoutSec
396400 $cacheContent = $response.Content
397401 }
398402 catch {
0 commit comments