Skip to content

HttpContextExtensions Class ​

Definition ​

Extensions for the HttpContext class

  • Namespace: JASE.Extensions
  • Assembly: JASE.Web.dll

Methods ​

NameDescription
ValueTask<byte[]> GetRequestBytes(HttpContext context, CancellationToken cancellationToken = null)Returns the HttpContext.Request body as a byte[]
string GetRequestHeaders(HttpContext context)Returns the Request headers as a string
RouteInformation GetRouteInformation(HttpContext context)Returns a RouteInformation class from the provided HttpContext object
bool IsJson(HttpContext context)Returns if Request Content-Type header is application/json
bool IsLocalRequest(HttpContext context)Determines whether the current request originates from a local machine.
bool IsRedirect(HttpContext context)Returns true if the HttpContext response StatusCode is 301 or 302
bool IsSuccess(HttpContext context)Returns true if the HttpContext response StatusCode is between 200 and 299
Task<T> ReadCbor(HttpContext context, CancellationToken cancellationToken = null)Deserializes a CBOR-encoded HTTP request body into an object of type T.
Task<T> ReadJson(HttpContext context, JsonSerializerOptions options = null, CancellationToken cancellationToken = null)Async deserializaztion on HttpRequest body to an object type
string ReadRequestBody(HttpContext context, Encoding encoding = null)Returns the Request payload as a string
Task<string> ReadRequestBodyAsync(HttpContext context, Encoding encoding = null, CancellationToken cancellationToken = null)Returns the Request payload as a string
bool TryGetItem(HttpContext context, string key, out T result)Attempts to retrieve a value from Items and cast it to the requested type.
Task<bool> WriteText(HttpContext context, string text, int statusCode = null, string contentType = null, Encoding encoding = null)Write text to the HttpContext Response object