Skip to content

easyextensionsaspnetcore HttpRequestExtensions

BigMakCode edited this page Aug 5, 2024 · 1 revision

HttpRequestExtensions Public class

Description

HttpRequest extensions.

Diagram

  flowchart LR
  classDef interfaceStyle stroke-dasharray: 5 5;
  classDef abstractStyle stroke-width:4px
  subgraph EasyExtensions.AspNetCore
  EasyExtensions.AspNetCore.HttpRequestExtensions[[HttpRequestExtensions]]
  end
Loading

Members

Methods

Public Static methods

Returns Name
string GetRemoteAddress(HttpRequest request)
Get remote host IP address using proxy "X-Real-IP", "CF-Connecting-IP", "X-Forwarded-For" headers, or connection remote IP address.
bool TooManyRequests(...)
Check if there are too many requests from the same IP address, using in-memory cache.

Details

Summary

HttpRequest extensions.

Methods

GetRemoteAddress

public static string GetRemoteAddress(HttpRequest request)
Arguments
Type Name Description
HttpRequest request
Summary

Get remote host IP address using proxy "X-Real-IP", "CF-Connecting-IP", "X-Forwarded-For" headers, or connection remote IP address.

Returns

IP address, or "Unknown" by default.

TooManyRequests [1/3]

public static bool TooManyRequests(HttpRequest request, int atTimeSeconds, int maxRepeats)
Arguments
Type Name Description
HttpRequest request HTTP request.
int atTimeSeconds Time period to check, default is 60 seconds.
int maxRepeats Maximum number of requests for the specified time period, default is 1.
Summary

Check if there are too many requests from the same IP address, using in-memory cache.

Returns

True if there are too many requests, otherwise false.

TooManyRequests [2/3]

public static bool TooManyRequests(HttpRequest request, TimeSpan atTime, int maxRepeats)
Arguments
Type Name Description
HttpRequest request HTTP request.
TimeSpan atTime Time period to check, default is 60 seconds.
int maxRepeats Maximum number of requests for the specified time period, default is 1.
Summary

Check if there are too many requests from the same IP address, using in-memory cache.

Returns

True if there are too many requests, otherwise false.

TooManyRequests [3/3]

public static bool TooManyRequests(string ip, TimeSpan atTime, int maxRepeats)
Arguments
Type Name Description
string ip IP address.
TimeSpan atTime Time period to check.
int maxRepeats Maximum number of requests for the specified time period, default is 1.
Summary

Check if there are too many requests from the same IP address, using in-memory cache.

Returns

True if there are too many requests, otherwise false.

Generated with ModularDoc

Clone this wiki locally