模擬速率限制行為。
組態範例
{
"$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 物件或陣列,Dev Proxy 會將其序列化成 JSON。 如果你把它設成字串,Dev Proxy 會把字串寄 as-is,不會加上引號。 因為開發代理預設Content-Type標頭為 application/json,例如回傳非 JSON 內容text/plain時,標頭會與Content-Type你的內容相符。
自訂回應 Content-Type 標頭
當 whenLimitExceeded 設定為 且 Custom 自訂回應有 body 但未定義 Content-Type 標頭時,Dev Proxy 會回傳帶有 Content-Type: application/json 標頭的回應。 若要返回不同內容類型,請將標頭加入 Content-Type 自訂回應檔案。 Dev Proxy 使用你指定的值。