예제 #1
0
        private static void SetHeaders(HttpContext context, RateLimitResult result)
        {
            var headers = context.Response.Headers;

            headers.Add("X-RateLimit-Limit", result.RequestLimit.ToString());
            headers.Add("X-RateLimit-Remaining", result.RequestsRemaining.ToString());
            headers.Add("X-RateLimit-Reset", result.GetRateLimitResetAsUnixtime().ToString());
        }
예제 #2
0
        private async Task ReponseWithTooManyRequests(ResourceExecutingContext context, RateLimitResult result)
        {
            var serializer = context.GetService <IRateLimitResponseSerializer>();
            var json       = serializer.ToJson(result);
            var response   = context.HttpContext.Response;

            response.Headers["Retry-After"] = result.GetRateLimitResetAsUnixtime().ToString();
            response.StatusCode             = StatusCodes.Status429TooManyRequests;
            response.ContentType            = "application/json";
            await response.WriteAsync(json);
        }