jellyfin-server/MediaBrowser.Common/Extensions/HttpContextExtensions.cs

34 lines
1.2 KiB
C#
Raw Normal View History

2020-07-17 15:06:52 +00:00
using MediaBrowser.Model.Services;
using Microsoft.AspNetCore.Http;
2020-07-18 15:54:23 +00:00
namespace MediaBrowser.Common.Extensions
2020-07-17 15:06:52 +00:00
{
/// <summary>
2020-07-18 15:54:23 +00:00
/// Static class containing extension methods for <see cref="HttpContext"/>.
2020-07-17 15:06:52 +00:00
/// </summary>
2020-07-18 15:54:23 +00:00
public static class HttpContextExtensions
2020-07-17 15:06:52 +00:00
{
2020-07-19 21:19:17 +00:00
private const string ServiceStackRequest = "ServiceStackRequest";
2020-07-17 15:06:52 +00:00
/// <summary>
2020-07-18 15:54:23 +00:00
/// Set the ServiceStack request.
2020-07-17 15:06:52 +00:00
/// </summary>
/// <param name="httpContext">The HttpContext instance.</param>
2020-07-18 15:54:23 +00:00
/// <param name="request">The service stack request instance.</param>
2020-07-17 15:06:52 +00:00
public static void SetServiceStackRequest(this HttpContext httpContext, IRequest request)
{
2020-07-19 21:19:17 +00:00
httpContext.Items[ServiceStackRequest] = request;
2020-07-17 15:06:52 +00:00
}
/// <summary>
2020-07-18 15:54:23 +00:00
/// Get the ServiceStack request.
2020-07-17 15:06:52 +00:00
/// </summary>
/// <param name="httpContext">The HttpContext instance.</param>
/// <returns>The service stack request instance.</returns>
public static IRequest GetServiceStackRequest(this HttpContext httpContext)
2020-07-17 15:06:52 +00:00
{
2020-07-19 21:19:17 +00:00
return (IRequest)httpContext.Items[ServiceStackRequest];
2020-07-17 15:06:52 +00:00
}
}
}