-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
Description
Feature Request
Is your feature request related to a problem? Please describe.
In manifests for apps that don't have a straightforward way to get current version, "checkver":{"script":[]} is often used to get the metadata of some static URL pointing to latest release.
Describe the solution you'd like
Instead of having to handle the logic for getting a redirect URL, it'd be useful if Scoop added it as a function that can be referenced from checkver script.
Or maybe a new JSON property "checkver":{"redirectUrl" = "<url_that_redirects>"}, which regex later can get metadata out of?
Here is the easiest way I've found to get a redirect URL. Can be made a bit more robust if made into a Scoop function.
[System.Net.HttpWebRequest]::Create(
'<url>'
).GetResponse().ResponseUri.AbsoluteUriThere is some logic for this in download.ps1 already:
Lines 115 to 136 in b588a06
| } catch [System.Net.WebException] { | |
| $exc = $_.Exception | |
| $handledCodes = @( | |
| [System.Net.HttpStatusCode]::MovedPermanently, # HTTP 301 | |
| [System.Net.HttpStatusCode]::Found, # HTTP 302 | |
| [System.Net.HttpStatusCode]::SeeOther, # HTTP 303 | |
| [System.Net.HttpStatusCode]::TemporaryRedirect # HTTP 307 | |
| ) | |
| # Only handle redirection codes | |
| $redirectRes = $exc.Response | |
| if ($handledCodes -notcontains $redirectRes.StatusCode) { | |
| throw $exc | |
| } | |
| # Get the new location of the file | |
| if ((-not $redirectRes.Headers) -or ($redirectRes.Headers -notcontains 'Location')) { | |
| throw $exc | |
| } | |
| $newUrl = $redirectRes.Headers['Location'] | |
| info "Following redirect to $newUrl..." |