Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.Http;
- using System.Net.Http.Formatting;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Web.Http;
- namespace DiscordEmojiCollector.SelfHost.Controllers.Results
- {
- public class RateLimit<T> : IHttpActionResult
- {
- private readonly T _result;
- public RateLimit(T result)
- {
- _result = result;
- }
- public async Task<HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
- {
- var res = new HttpResponseMessage();
- res.GetType().GetProperty("StatusCode")?.SetValue(res, 429);
- res.Content = new ObjectContent(typeof(T), _result, new JsonMediaTypeFormatter());
- return res;
- }
- public static RateLimit<T> RateLimited(T response)
- {
- return new RateLimit<T>(response);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment