Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync eng/common directory with azure-sdk-tools for PR 2768 #23120

Merged
merged 1 commit into from
Feb 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions eng/common/scripts/Verify-Links.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@

.PARAMETER outputCacheFile
Path to a file that the script will output all the validated links after running all checks.

.PARAMETER requestTimeoutSec
The number of seconds before we timeout when sending an individual web request. Default is 15 seconds.

.EXAMPLE
PS> .\Verify-Links.ps1 C:\README.md
Expand All @@ -67,7 +70,8 @@ param (
[bool] $checkLinkGuidance = $false,
[string] $userAgent,
[string] $inputCacheFile,
[string] $outputCacheFile
[string] $outputCacheFile,
[string] $requestTimeoutSec = 15
)

$ProgressPreference = "SilentlyContinue"; # Disable invoke-webrequest progress dialog
Expand Down Expand Up @@ -220,14 +224,14 @@ function CheckLink ([System.Uri]$linkUri, $allowRetry=$true)
$headRequestSucceeded = $true
try {
# Attempt HEAD request first
$response = Invoke-WebRequest -Uri $linkUri -Method HEAD -UserAgent $userAgent
$response = Invoke-WebRequest -Uri $linkUri -Method HEAD -UserAgent $userAgent -TimeoutSec $requestTimeoutSec
}
catch {
$headRequestSucceeded = $false
}
if (!$headRequestSucceeded) {
# Attempt a GET request if the HEAD request failed.
$response = Invoke-WebRequest -Uri $linkUri -Method GET -UserAgent $userAgent
$response = Invoke-WebRequest -Uri $linkUri -Method GET -UserAgent $userAgent -TimeoutSec $requestTimeoutSec
}
$statusCode = $response.StatusCode
if ($statusCode -ne 200) {
Expand Down Expand Up @@ -328,7 +332,7 @@ function GetLinks([System.Uri]$pageUri)
{
if ($pageUri.Scheme.StartsWith("http")) {
try {
$response = Invoke-WebRequest -Uri $pageUri -UserAgent $userAgent
$response = Invoke-WebRequest -Uri $pageUri -UserAgent $userAgent -TimeoutSec $requestTimeoutSec
$content = $response.Content

if ($pageUri.ToString().EndsWith(".md")) {
Expand Down Expand Up @@ -392,7 +396,7 @@ if ($inputCacheFile)
$cacheContent = ""
if ($inputCacheFile.StartsWith("http")) {
try {
$response = Invoke-WebRequest -Uri $inputCacheFile
$response = Invoke-WebRequest -Uri $inputCacheFile -TimeoutSec $requestTimeoutSec
$cacheContent = $response.Content
}
catch {
Expand Down