Switch to request HEAD instead of Get (#1574)
* Switch to request HEAD instead of Get * Fallback to GET request if HEAD request fails
This commit is contained in:
Родитель
824fed4c95
Коммит
d0fd066656
|
@ -95,7 +95,19 @@ function CheckLink ([System.Uri]$linkUri)
|
|||
}
|
||||
else {
|
||||
try {
|
||||
$response = Invoke-WebRequest -Uri $linkUri
|
||||
$headRequestSucceeded = $true
|
||||
try {
|
||||
# Attempt HEAD request first
|
||||
$response = Invoke-WebRequest -Uri $linkUri -Method HEAD
|
||||
}
|
||||
catch {
|
||||
$headRequestSucceeded = $false
|
||||
}
|
||||
if (!$headRequestSucceeded) {
|
||||
# Attempt a GET request if the HEAD request failed.
|
||||
$response = Invoke-WebRequest -Uri $linkUri -Method GET
|
||||
}
|
||||
|
||||
$statusCode = $response.StatusCode
|
||||
if ($statusCode -ne 200) {
|
||||
Write-Host "[$statusCode] while requesting $linkUri"
|
||||
|
@ -234,4 +246,4 @@ while ($pageUrisToCheck.Count -ne 0)
|
|||
Write-Host "Found $($checkedLinks.Count) links with $($badLinks.Count) broken"
|
||||
$badLinks | ForEach-Object { Write-Host " $_" }
|
||||
|
||||
exit $badLinks.Count
|
||||
exit $badLinks.Count
|
||||
|
|
Загрузка…
Ссылка в новой задаче