ThreeMammals / Ocelot

.NET API Gateway
https://www.nuget.org/packages/Ocelot
MIT License
8.38k stars 1.64k forks source link

`"DisableRateLimitHeaders": false` is not showing `X-Rate-Limit` and `Retry-After` headers in response #1305

Closed neetra closed 2 days ago

neetra commented 4 years ago

Expected Behavior / New Feature

configuration file:

{
"Routes" :  [  {
      "DownstreamPathTemplate": "/users",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "jsonplaceholder.typicode.com",
          "Port": 443
        }
      ],
      "UpstreamPathTemplate": "/users",
      "UpstreamHttpMethod": [ "Get" ],
      "RateLimitOptions": 
        {
          "ClientWhitelist": [],
          "EnableRateLimiting": true,
          "Period": "10s",
          "PeriodTimespan": 3,
          "Limit": 1
        }

    }],

  "GlobalConfiguration": {

    "RateLimitOptions": {
      "DisableRateLimitHeaders": true,
      "QuotaExceededMessage": "Exceed ",
      "HttpStatusCode": 602
    }

}

Response headers should contain X-Rate-Limit and Retry-After headers as mentioned in [document](https://ocelot.readthedocs.io/en/latest/features/ratelimiting.html)

Actual Behavior / Motivation for New Feature

image It does not contain response headers.

Specifications

jlukawska commented 4 years ago

Hello, as I see the problem is caused by the recent changes in the code. Now httpcontext is used in a different way than before, more: there is a new httpcontext created for each request... I have an idea how to fix it, so I'm going to create a PR soon.

neetra commented 4 years ago

Thanks @jlukawska

nls44 commented 3 years ago

+1, X-Rate-Limit and Retry-After headers are not set. Would be handy if this could get fixed since Polly supports automatic retries based on this header.

garybond commented 2 years ago

+1. Just updated my project from netcore3.1 to net5.0 Ocelot v17.0.0 and this breaks rate-limiting on a partner-facing api we host, as it no longer emits the required headers. I've also tried it on net6.0 Ocelot v18.0.0 and same issue.

raman-m commented 1 year ago
+ Accepted

...due to the open PR #1307 by @jlukawska