速率限制插件

模拟速率限制行为。

命令提示符的屏幕截图,其中开发人员代理模拟 GitHub API 上的速率限制。

配置示例

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v4.0.0/rc.schema.json",
  "plugins": [
    {
      "name": "RateLimitingPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
      "configSection": "rateLimiting"
    }
  ],
  "rateLimiting": {
    "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v4.0.0/ratelimitingplugin.schema.json",
    "costPerRequest": 2,
    "rateLimit": 120
  }
}

配置属性

财产 描述 违约
headerLimit 传达速率限制限制的响应标头的名称 RateLimit-Limit
headerRemaining 在重置之前传达剩余资源数的响应标头的名称 RateLimit-Remaining
headerReset 响应标头的名称,该标头传达重置前剩余时间 RateLimit-Reset
headerRetryAfter 传达重试后句点的响应标头的名称 Retry-After
costPerRequest 请求成本的资源数 2
resetTimeWindowSeconds 下一次重置的时长(以秒为单位) 六十
warningThresholdPercent 超出时间开始返回速率限制响应标头的使用量百分比 80
rateLimit 时间窗口的资源数 120
whenLimitExceeded 超出限制时插件应使用的行为。 使用 Throttle 或 Custom。 Throttle
resetFormat 用于确定速率限制何时重置的格式。 使用 SecondsLeft 或 UtcEpochSeconds。 SecondsLeft
customResponseFile 包含超出限制时使用的自定义错误响应的文件。 rate-limit-response.json

命令行选项

没有

备注

自定义响应正文

如果将自定义响应文件中的属性设置为 body JSON 对象或数组,则开发人员代理将其序列化为 JSON。 如果将字符串设置为字符串,则 Dev Proxy 将发送字符串 as-is,而不用周围引号。 由于开发代理将标头默认为 Content-Typeapplication/json,因此在返回非 JSON 内容时, Content-Type 请将标头设置为与内容匹配,例如 text/plain。

自定义响应 Content-Type 标头

当设置为 /> 且自定义响应具有但未定义标头时,开发代理将返回具有标头的响应。 若要返回其他内容类型,请将 Content-Type 标头添加到自定义响应文件。 开发代理使用指定的值。

后续步骤