_TruELecter_

Untitled

Jan 3rd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net.Http;
  5. using System.Net.Http.Formatting;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. using System.Web.Http;
  10.  
  11. namespace DiscordEmojiCollector.SelfHost.Controllers.Results
  12. {
  13.     public class RateLimit<T> : IHttpActionResult
  14.     {
  15.         private readonly T _result;
  16.  
  17.         public RateLimit(T result)
  18.         {
  19.             _result = result;
  20.         }
  21.  
  22.         public async Task<HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
  23.         {
  24.             var res = new HttpResponseMessage();
  25.  
  26.             res.GetType().GetProperty("StatusCode")?.SetValue(res, 429);
  27.             res.Content = new ObjectContent(typeof(T), _result, new JsonMediaTypeFormatter());
  28.  
  29.             return res;
  30.         }
  31.  
  32.         public static RateLimit<T> RateLimited(T response)
  33.         {
  34.             return new RateLimit<T>(response);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment