Issue
When installing the gitea runner from gitea.com the Invoke-FastWebRequest function errors with 403 (Forbidden).
Reference
Invoke-FastWebRequest fails with 403.
Invoke-WebRequest works
Invoke-FastWebRequest to non-gitea domain works.
Digging into the function seems to be around the $client.GetStreamAsync function.
Tested hosting the runner (v1.0.7 diff than past testing) with python3 -m http.server and file was grabbed successfully with Invoke-FastWebRequest
Workaround
I created a custom template and replaced calls to Invoke-FastWebRequest with Invoke-WebRequest
Template .ps1
function Invoke-FastWebRequest {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,ValueFromPipeline=$true,Position=0)]
[System.Uri]$Uri,
[Parameter(Position=1)]
[string]$OutFile,
[Hashtable]$Headers=@{},
[switch]$SkipIntegrityCheck=$false
)
PROCESS
{
if(!([System.Management.Automation.PSTypeName]'System.Net.Http.HttpClient').Type)
{
$assembly = [System.Reflection.Assembly]::LoadWithPartialName("System.Net.Http")
}
if(!$OutFile) {
$OutFile = $Uri.PathAndQuery.Substring($Uri.PathAndQuery.LastIndexOf("/") + 1)
if(!$OutFile) {
throw "The ""OutFile"" parameter needs to be specified"
}
}
$fragment = $Uri.Fragment.Trim('#')
if ($fragment) {
$details = $fragment.Split("=")
$algorithm = $details[0]
$hash = $details[1]
}
if (!$SkipIntegrityCheck -and $fragment -and (Test-Path $OutFile)) {
try {
return (Test-FileIntegrity -File $OutFile -Algorithm $algorithm -ExpectedHash $hash)
} catch {
Remove-Item $OutFile
}
}
$client = new-object System.Net.Http.HttpClient
foreach ($k in $Headers.Keys){
$client.DefaultRequestHeaders.Add($k, $Headers[$k])
}
$task = $client.GetStreamAsync($Uri)
$response = $task.Result
if($task.IsFaulted) {
$msg = "Request for URL '{0}' is faulted. Task status: {1}." -f @($Uri, $task.Status)
if($task.Exception) {
$msg += "Exception details: {0}" -f @($task.Exception)
}
Throw $msg
}
$outStream = New-Object IO.FileStream $OutFile, Create, Write, None
try {
$totRead = 0
$buffer = New-Object Byte[] 1MB
while (($read = $response.Read($buffer, 0, $buffer.Length)) -gt 0) {
$totRead += $read
$outStream.Write($buffer, 0, $read);
}
}
finally {
$outStream.Close()
}
if(!$SkipIntegrityCheck -and $fragment) {
Test-FileIntegrity -File $OutFile -Algorithm $algorithm -ExpectedHash $hash
}
}
}
Issue
When installing the gitea runner from
gitea.comtheInvoke-FastWebRequestfunction errors with403 (Forbidden).Reference
Invoke-FastWebRequestfails with 403.Invoke-WebRequestworksInvoke-FastWebRequestto non-gitea domain works.Digging into the function seems to be around the
$client.GetStreamAsyncfunction.Tested hosting the runner (v1.0.7 diff than past testing) with
python3 -m http.serverand file was grabbed successfully withInvoke-FastWebRequestWorkaround
I created a custom template and replaced calls to
Invoke-FastWebRequestwithInvoke-WebRequestTemplate .ps1