Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use Last-Modified-If'ish behavior for wget, curl, and the powershell commandlet * Prefer curl to wget (seems significantly faster) This is the first step to speeding up auto-update. The next step will be to only run auto-update every X hours (PRs welcome), since the optimizations in this PR don't get around having to wait for the http connect / header-response.
- Loading branch information
Showing
4 changed files
with
28 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
param ( | ||
[string]$url = $(throw "-url is required."), | ||
[string]$out = $(throw "-out is required.") | ||
Param ( | ||
[Parameter(Mandatory=$True)] [System.Uri]$uri, | ||
[Parameter(Mandatory=$True )] [string]$FilePath | ||
) | ||
|
||
$progressPreference = 'silentlyContinue' # hide progress output | ||
$http_proxy = $env:http_proxy; | ||
|
||
if ( $http_proxy -ne $null ) { | ||
Invoke-WebRequest -Uri $url -OutFile $out -Proxy | ||
if ( -not (Test-Path $FilePath) ) { | ||
[void] (New-Object System.Net.WebClient).DownloadFile($uri.ToString(), $FilePath) | ||
} else { | ||
Invoke-WebRequest -Uri $url -OutFile $out | ||
try { | ||
$webRequest = [System.Net.HttpWebRequest]::Create($uri); | ||
$webRequest.IfModifiedSince = ([System.IO.FileInfo]$FilePath).LastWriteTime | ||
$webRequest.Method = "GET"; | ||
[System.Net.HttpWebResponse]$webResponse = $webRequest.GetResponse() | ||
|
||
$stream = New-Object System.IO.StreamReader($response.GetResponseStream()) | ||
$stream.ReadToEnd() | Set-Content -Path $FilePath -Force | ||
} catch [System.Net.WebException] { | ||
# If content isn't modified according to the output file timestamp then ignore the exception | ||
if ($_.Exception.Response.StatusCode -ne [System.Net.HttpStatusCode]::NotModified) { | ||
throw $_ | ||
} | ||
} | ||
} |