Skip to content

Invoke-RestMethod and Invoke-WebRequest do not respect Retry-After header in 429 responses. #13188

@RobFaie

Description

@RobFaie

Calling Invoke-RestMethod will ignore the Retry-After header provided when hitting api rate limits retrying after 5 seconds even if the response specified wait time is longer than that.

Steps to reproduce

Invoke-RestMethod -Uri https://ins-httpstatus.azurewebsites.net/429 -MaximumRetryCount 2 -Verbose

Expected behavior

VERBOSE: GET https://ins-httpstatus.azurewebsites.net/429 with 0-byte payload
VERBOSE: Retrying after interval of 10 seconds. Status code for previous attempt: TooManyRequests
VERBOSE: Retrying after interval of 10 seconds. Status code for previous attempt: TooManyRequests
VERBOSE: received 0-byte response of content type
Invoke-RestMethod: Response status code does not indicate success: 429 (Too Many Requests).

Actual behavior

VERBOSE: GET https://ins-httpstatus.azurewebsites.net/429 with 0-byte payload
VERBOSE: Retrying after interval of 5 seconds. Status code for previous attempt: TooManyRequests
VERBOSE: Retrying after interval of 5 seconds. Status code for previous attempt: TooManyRequests
VERBOSE: received 0-byte response of content type
Invoke-RestMethod: Response status code does not indicate success: 429 (Too Many Requests).

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.0-preview.5
PSEdition                      Core
GitCommitId                    7.1.0-preview.5
OS                             Darwin 19.5.0 Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Name                           Value
----                           -----
PSVersion                      7.0.2
PSEdition                      Core
GitCommitId                    7.0.2
OS                             Darwin 19.5.0 Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

The uri that I am hitting above is just a simple Function App with the following proxy:

{
    "$schema": "http://json.schemastore.org/proxies",
    "proxies": {
        "429": {
            "matchCondition": {
                "route": "/429"
            },
            "responseOverrides": {
                "response.statusCode": "429",
                "response.headers.Retry-After": "10"
            }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Hacktoberfest-AcceptedAccepted to participate in HacktoberfestIssue-Enhancementthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions