Skip to content

[Feature] Checkver - Add function to get redirect URLs that can be used in manifests #6526

@o-l-a-v

Description

@o-l-a-v

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.AbsoluteUri

There is some logic for this in download.ps1 already:

Scoop/lib/download.ps1

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..."

Describe alternatives you've considered

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions