From bc983ace03867cf1d4003a6c14c682fb9585510a Mon Sep 17 00:00:00 2001 From: Dan Gough Date: Wed, 27 Jul 2022 08:55:14 +0100 Subject: [PATCH 1/2] Add passthru of Headers param to Invoke-WebRequest --- Nevergreen/Private/Get-Link.ps1 | 5 +++++ Nevergreen/Private/Resolve-Uri.ps1 | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Nevergreen/Private/Get-Link.ps1 b/Nevergreen/Private/Get-Link.ps1 index a07e4b4..e0b57f3 100644 --- a/Nevergreen/Private/Get-Link.ps1 +++ b/Nevergreen/Private/Get-Link.ps1 @@ -65,6 +65,7 @@ function Get-Link { [Parameter( Mandatory = $false)] [String] $UserAgent, + [System.Collections.Hashtable] $Headers, [Switch] $PrefixDomain, [Switch] $PrefixParent ) @@ -83,6 +84,10 @@ function Get-Link { $ParamHash.UserAgent = $UserAgent } + if ($Headers) { + $ParamHash.Headers = $Headers + } + try { $Response = Invoke-WebRequest @ParamHash diff --git a/Nevergreen/Private/Resolve-Uri.ps1 b/Nevergreen/Private/Resolve-Uri.ps1 index fd259c1..b22a262 100644 --- a/Nevergreen/Private/Resolve-Uri.ps1 +++ b/Nevergreen/Private/Resolve-Uri.ps1 @@ -42,7 +42,8 @@ function Resolve-Uri { [Parameter( Mandatory = $false, Position = 1)] - [String] $UserAgent + [String] $UserAgent, + [System.Collections.Hashtable] $Headers ) begin { @@ -67,6 +68,10 @@ function Resolve-Uri { $ParamHash.UserAgent = $UserAgent } + if ($Headers) { + $ParamHash.Headers = $Headers + } + $Response = Invoke-WebRequest @ParamHash if ($IsCoreCLR) { From 28578ab4fce8586989eb780443462410b21747f1 Mon Sep 17 00:00:00 2001 From: Dan Gough Date: Wed, 27 Jul 2022 08:56:15 +0100 Subject: [PATCH 2/2] Add headers to web requests --- Nevergreen/Apps/Get-AdobeAcrobat.ps1 | 4 ++-- Nevergreen/Apps/Get-AdobeAcrobatReader.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Nevergreen/Apps/Get-AdobeAcrobat.ps1 b/Nevergreen/Apps/Get-AdobeAcrobat.ps1 index 0a6c029..9879ea5 100644 --- a/Nevergreen/Apps/Get-AdobeAcrobat.ps1 +++ b/Nevergreen/Apps/Get-AdobeAcrobat.ps1 @@ -9,9 +9,9 @@ foreach ($Platform in $Platforms) { $SearchCount = 5 do { - $ReleaseURL = Get-Link -Uri $ReleaseURL -MatchProperty outerHTML -Pattern '>Next' -PrefixParent + $ReleaseURL = Get-Link -Uri $ReleaseURL -Headers @{"accept-language"="en-GB,en;q=0.9,en-US;q=0.8"} -MatchProperty outerHTML -Pattern '>Next' -PrefixParent - $URL = Get-Link -Uri $ReleaseURL -MatchProperty href -Pattern $Platform.Pattern + $URL = Get-Link -Uri $ReleaseURL -Headers @{"accept-language"="en-GB,en;q=0.9,en-US;q=0.8"} -MatchProperty href -Pattern $Platform.Pattern if ($URL) { $Version = ($URL | Get-Version -Pattern '(\d{8,12}).+msp') -replace '(\d{2})(\d{3})(\d+)','$1.$2.$3' New-NevergreenApp -Name 'Adobe Acrobat' -Version $Version -Uri $URL -Architecture $Platform.Architecture -Language $Platform.Language -Type 'Msp' diff --git a/Nevergreen/Apps/Get-AdobeAcrobatReader.ps1 b/Nevergreen/Apps/Get-AdobeAcrobatReader.ps1 index 942871c..34f14d4 100644 --- a/Nevergreen/Apps/Get-AdobeAcrobatReader.ps1 +++ b/Nevergreen/Apps/Get-AdobeAcrobatReader.ps1 @@ -10,9 +10,9 @@ foreach ($Platform in $Platforms) { $SearchCount = 5 do { - $ReleaseURL = Get-Link -Uri $ReleaseURL -MatchProperty outerHTML -Pattern '>Next' -PrefixParent + $ReleaseURL = Get-Link -Uri $ReleaseURL -Headers @{"accept-language"="en-GB,en;q=0.9,en-US;q=0.8"} -MatchProperty outerHTML -Pattern '>Next' -PrefixParent - $URL = Get-Link -Uri $ReleaseURL -MatchProperty href -Pattern $Platform.Pattern + $URL = Get-Link -Uri $ReleaseURL -Headers @{"accept-language"="en-GB,en;q=0.9,en-US;q=0.8"} -MatchProperty href -Pattern $Platform.Pattern if ($URL) { $Version = ($URL | Get-Version -Pattern '(\d{8,12}).+msp') -replace '(\d{2})(\d{3})(\d+)','$1.$2.$3' New-NevergreenApp -Name 'Adobe Acrobat Reader' -Version $Version -Uri $URL -Architecture $Platform.Architecture -Language $Platform.Language -Type 'Msp'