-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1305 Populate RateLimiting headers in the original
HttpContext
res…
…ponse accessed via `IHttpContextAccessor` (#1307) * set rate limiting headers on the proper httpcontext * fix Retry-After header * merge fix * refactor of ClientRateLimitTests * merge fix * Fix build after rebasing * EOL: test/Ocelot.AcceptanceTests/Steps.cs * Add `RateLimitingSteps` * code review by @raman-m * Inject IHttpContextAccessor, not IServiceProvider * Ocelot's rate-limiting headers have become legacy * Headers definition life hack * A good StackOverflow link --------- Co-authored-by: Jolanta Łukawska <jolanta.lukawska@outlook.com> Co-authored-by: Raman Maksimchuk <dotnet044@gmail.com>
- Loading branch information
1 parent
d310508
commit da9d6fa
Showing
8 changed files
with
135 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Microsoft.Net.Http.Headers; | ||
|
||
namespace Ocelot.RateLimiting; | ||
|
||
/// <summary> | ||
/// TODO These Ocelot's RateLimiting headers don't follow industry standards, see links. | ||
/// </summary> | ||
/// <remarks>Links: | ||
/// <list type="bullet"> | ||
/// <item>GitHub: <see href="https://github.com/ioggstream/draft-polli-ratelimit-headers">draft-polli-ratelimit-headers</see></item> | ||
/// <item>GitHub: <see href="https://github.com/ietf-wg-httpapi/ratelimit-headers">ratelimit-headers</see></item> | ||
/// <item>GitHub Wiki: <see href="https://ietf-wg-httpapi.github.io/ratelimit-headers/draft-ietf-httpapi-ratelimit-headers.html">RateLimit header fields for HTTP</see></item> | ||
/// <item>StackOverflow: <see href="https://stackoverflow.com/questions/16022624/examples-of-http-api-rate-limiting-http-response-headers">Examples of HTTP API Rate Limiting HTTP Response headers</see></item> | ||
/// </list> | ||
/// </remarks> | ||
public static class RateLimitingHeaders | ||
{ | ||
public const char Dash = '-'; | ||
public const char Underscore = '_'; | ||
|
||
/// <summary>Gets the <c>Retry-After</c> HTTP header name.</summary> | ||
public static readonly string Retry_After = HeaderNames.RetryAfter; | ||
|
||
/// <summary>Gets the <c>X-Rate-Limit-Limit</c> Ocelot's header name.</summary> | ||
public static readonly string X_Rate_Limit_Limit = nameof(X_Rate_Limit_Limit).Replace(Underscore, Dash); | ||
|
||
/// <summary>Gets the <c>X-Rate-Limit-Remaining</c> Ocelot's header name.</summary> | ||
public static readonly string X_Rate_Limit_Remaining = nameof(X_Rate_Limit_Remaining).Replace(Underscore, Dash); | ||
|
||
/// <summary>Gets the <c>X-Rate-Limit-Reset</c> Ocelot's header name.</summary> | ||
public static readonly string X_Rate_Limit_Reset = nameof(X_Rate_Limit_Reset).Replace(Underscore, Dash); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
test/Ocelot.AcceptanceTests/RateLimiting/RateLimitingSteps.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Ocelot.AcceptanceTests.RateLimiting; | ||
|
||
public class RateLimitingSteps : Steps | ||
{ | ||
public async Task WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit(string url, int times) | ||
{ | ||
for (var i = 0; i < times; i++) | ||
{ | ||
const string clientId = "ocelotclient1"; | ||
var request = new HttpRequestMessage(new HttpMethod("GET"), url); | ||
request.Headers.Add("ClientId", clientId); | ||
_response = await _ocelotClient.SendAsync(request); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters