Skip to content

Commit 0d70f57

Browse files
azure-sdksima-zhu
andauthored
Sync eng/common directory with azure-sdk-tools for PR 1302 (Azure#16009)
* Make the user agent configurable. * Address comments * Default to current Chrome version * Revert the yaml file changes Co-authored-by: Sima Zhu <sizhu@microsoft.com>
1 parent b6bc150 commit 0d70f57

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

eng/common/scripts/Verify-Links.ps1

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ param (
1818
# the substitute branch name or SHA commit
1919
[string] $branchReplacementName = "",
2020
# flag to allow checking against azure sdk link guidance. Check link guidance here: https://aka.ms/azsdk/guideline/links
21-
[bool] $checkLinkGuidance = $false
21+
[bool] $checkLinkGuidance = $false,
22+
# UserAgent to be configured for web request. Default to current Chrome version.
23+
[string] $userAgent
2224
)
2325

2426
$ProgressPreference = "SilentlyContinue"; # Disable invoke-webrequest progress dialog
2527
# Regex of the locale keywords.
2628
$locale = "/en-us/"
2729
$emptyLinkMessage = "There is at least one empty link in the page. Please replace with absolute link. Check here for more information: https://aka.ms/azsdk/guideline/links"
30+
if (!$userAgent) {
31+
$userAgent = "Chrome/87.0.4280.88"
32+
}
2833
function NormalizeUrl([string]$url){
2934
if (Test-Path $url) {
3035
$url = "file://" + (Resolve-Path $url).ToString();
@@ -162,14 +167,14 @@ function CheckLink ([System.Uri]$linkUri)
162167
$headRequestSucceeded = $true
163168
try {
164169
# Attempt HEAD request first
165-
$response = Invoke-WebRequest -Uri $linkUri -Method HEAD
170+
$response = Invoke-WebRequest -Uri $linkUri -Method HEAD -UserAgent $userAgent
166171
}
167172
catch {
168173
$headRequestSucceeded = $false
169174
}
170175
if (!$headRequestSucceeded) {
171176
# Attempt a GET request if the HEAD request failed.
172-
$response = Invoke-WebRequest -Uri $linkUri -Method GET
177+
$response = Invoke-WebRequest -Uri $linkUri -Method GET -UserAgent $userAgent
173178
}
174179
$statusCode = $response.StatusCode
175180
if ($statusCode -ne 200) {
@@ -239,7 +244,7 @@ function GetLinks([System.Uri]$pageUri)
239244
{
240245
if ($pageUri.Scheme.StartsWith("http")) {
241246
try {
242-
$response = Invoke-WebRequest -Uri $pageUri
247+
$response = Invoke-WebRequest -Uri $pageUri -UserAgent $userAgent
243248
$content = $response.Content
244249
}
245250
catch {

0 commit comments

Comments
 (0)